Add test fixture

This commit is contained in:
Lunny Xiao
2025-08-11 19:37:09 -07:00
parent 93033237dd
commit 24053ce2d2
2 changed files with 50 additions and 2 deletions

View File

@ -6,15 +6,22 @@ package repos
import (
"context"
"fmt"
"os"
"testing"
"time"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/cmd/login"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli/v3"
)
func TestCreateRepoObjectFormat(t *testing.T) {
giteaURL := os.Getenv("GITEA_TEA_TEST_URL")
if giteaURL == "" {
t.Skip("GITEA_TEA_TEST_URL is not set, skipping test")
}
timestamp := time.Now().Unix()
tests := []struct {
name string
@ -49,13 +56,26 @@ func TestCreateRepoObjectFormat(t *testing.T) {
},
}
loginAddCmd := &cli.Command{
Name: "add",
Commands: []*cli.Command{
&login.CmdLoginAdd,
},
}
giteaUserName := os.Getenv("GITEA_TEA_TEST_USERNAME")
giteaUserPasword := os.Getenv("GITEA_TEA_TEST_PASSWORD")
args := []string{"add", "--name", "test-login", "--url", giteaURL, "--user", giteaUserName, "--password", giteaUserPasword}
err := loginAddCmd.Run(context.Background(), args)
assert.NoError(t, err)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
reposCmd := &cli.Command{
Name: "repos",
Aliases: []string{"repo"},
Name: "repos",
Commands: []*cli.Command{&CmdRepoCreate},
}
tt.args = append(tt.args, "--login", "test-login")
args := append([]string{"repos", "create"}, tt.args...)
err := reposCmd.Run(context.Background(), args)