test: fix repo create test by using unique repo names

This commit is contained in:
Lunny Xiao 2025-04-03 22:36:56 -07:00
parent 8c66851fd9
commit 9a3119f87b

View File

@ -4,7 +4,9 @@
package repos
import (
"fmt"
"testing"
"time"
"code.gitea.io/sdk/gitea"
"github.com/stretchr/testify/assert"
@ -12,6 +14,7 @@ import (
)
func TestCreateRepoObjectFormat(t *testing.T) {
timestamp := time.Now().Unix()
tests := []struct {
name string
args []string
@ -21,25 +24,25 @@ func TestCreateRepoObjectFormat(t *testing.T) {
}{
{
name: "create repo with sha1 object format",
args: []string{"--name", "test-sha1", "--object-format", "sha1"},
args: []string{"--name", fmt.Sprintf("test-sha1-%d", timestamp), "--object-format", "sha1"},
wantOpts: gitea.CreateRepoOption{
Name: "test-sha1",
Name: fmt.Sprintf("test-sha1-%d", timestamp),
ObjectFormatName: "sha1",
},
wantErr: false,
},
{
name: "create repo with sha256 object format",
args: []string{"--name", "test-sha256", "--object-format", "sha256"},
args: []string{"--name", fmt.Sprintf("test-sha256-%d", timestamp), "--object-format", "sha256"},
wantOpts: gitea.CreateRepoOption{
Name: "test-sha256",
Name: fmt.Sprintf("test-sha256-%d", timestamp),
ObjectFormatName: "sha256",
},
wantErr: false,
},
{
name: "create repo with invalid object format",
args: []string{"--name", "test-invalid", "--object-format", "invalid"},
args: []string{"--name", fmt.Sprintf("test-invalid-%d", timestamp), "--object-format", "invalid"},
wantErr: true,
errContains: "invalid object format",
},
@ -48,8 +51,13 @@ func TestCreateRepoObjectFormat(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
app := cli.NewApp()
app.Commands = []*cli.Command{&CmdRepoCreate}
args := append([]string{"tea", "repo", "create"}, tt.args...)
reposCmd := &cli.Command{
Name: "repos",
Aliases: []string{"repo"},
Subcommands: []*cli.Command{&CmdRepoCreate},
}
app.Commands = []*cli.Command{reposCmd}
args := append([]string{"tea", "repos", "create"}, tt.args...)
err := app.Run(args)
if tt.wantErr {