mirror of
https://gitea.com/gitea/tea.git
synced 2025-09-02 18:08:30 +02:00
test: fix repo create test by using unique repo names
This commit is contained in:
@ -4,7 +4,9 @@
|
|||||||
package repos
|
package repos
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/sdk/gitea"
|
"code.gitea.io/sdk/gitea"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -12,6 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestCreateRepoObjectFormat(t *testing.T) {
|
func TestCreateRepoObjectFormat(t *testing.T) {
|
||||||
|
timestamp := time.Now().Unix()
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
args []string
|
args []string
|
||||||
@ -21,25 +24,25 @@ func TestCreateRepoObjectFormat(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "create repo with sha1 object format",
|
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{
|
wantOpts: gitea.CreateRepoOption{
|
||||||
Name: "test-sha1",
|
Name: fmt.Sprintf("test-sha1-%d", timestamp),
|
||||||
ObjectFormatName: "sha1",
|
ObjectFormatName: "sha1",
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "create repo with sha256 object format",
|
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{
|
wantOpts: gitea.CreateRepoOption{
|
||||||
Name: "test-sha256",
|
Name: fmt.Sprintf("test-sha256-%d", timestamp),
|
||||||
ObjectFormatName: "sha256",
|
ObjectFormatName: "sha256",
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "create repo with invalid object format",
|
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,
|
wantErr: true,
|
||||||
errContains: "invalid object format",
|
errContains: "invalid object format",
|
||||||
},
|
},
|
||||||
@ -48,8 +51,13 @@ func TestCreateRepoObjectFormat(t *testing.T) {
|
|||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
app.Commands = []*cli.Command{&CmdRepoCreate}
|
reposCmd := &cli.Command{
|
||||||
args := append([]string{"tea", "repo", "create"}, tt.args...)
|
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)
|
err := app.Run(args)
|
||||||
if tt.wantErr {
|
if tt.wantErr {
|
||||||
|
Reference in New Issue
Block a user