forked from NYANDEV/forgejo
(cherry picked from commit 481d813539762af6670b2cb4d3e893ab27dfe544) address oliverpool comments (cherry picked from commit d8f313f9e21ceea7b113fc04938fa4ffea577d9e) s/Printf/Print/ (cherry picked from commit 6621b04458b9fbaf8b6664efd86886b2ebbec01d) do not run initDB within integration tests (cherry picked from commit 5a0428ede3e8f242860d121ab3ee8712a1fe2f14) (cherry picked from commit e8287b753d70d51e9bec23e732d797fe900a4911)
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
// SPDX-License-Identifier: MIT
|
|
|
|
package integration
|
|
|
|
import (
|
|
"bytes"
|
|
"flag"
|
|
"io"
|
|
"net/url"
|
|
"os"
|
|
"testing"
|
|
|
|
"code.gitea.io/gitea/cmd"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
func Test_CmdActions(t *testing.T) {
|
|
onGiteaRun(t, func(*testing.T, *url.URL) {
|
|
tests := []struct {
|
|
name string
|
|
args []string
|
|
wantErr bool
|
|
expectedOutput func(string)
|
|
}{
|
|
{"test_registration-token-admin", []string{"actions", "--registration-token-admin"}, false, func(output string) { assert.EqualValues(t, 40, len(output), output) }},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
realStdout := os.Stdout
|
|
r, w, _ := os.Pipe()
|
|
os.Stdout = w
|
|
|
|
set := flag.NewFlagSet("actions", 0)
|
|
_ = set.Parse(tt.args)
|
|
context := cli.NewContext(&cli.App{Writer: os.Stdout}, set, nil)
|
|
err := cmd.CmdActions.Run(context)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("CmdActions.Run() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
w.Close()
|
|
var buf bytes.Buffer
|
|
io.Copy(&buf, r)
|
|
tt.expectedOutput(buf.String())
|
|
os.Stdout = realStdout
|
|
})
|
|
}
|
|
})
|
|
}
|