Skip to content

Commit 4728e74

Browse files
committed
add test for multitoken clones
1 parent fb90bdd commit 4728e74

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

services/migrations/github_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
base "code.gitea.io/gitea/modules/migration"
1313

1414
"github.com/stretchr/testify/assert"
15+
"github.com/stretchr/testify/require"
1516
)
1617

1718
func TestGitHubDownloadRepo(t *testing.T) {
@@ -429,3 +430,36 @@ func TestGitHubDownloadRepo(t *testing.T) {
429430
},
430431
}, reviews)
431432
}
433+
434+
func TestGithubMultiToken(t *testing.T) {
435+
testCases := []struct {
436+
desc string
437+
token string
438+
expectedCloneURL string
439+
}{
440+
{
441+
desc: "Single Token",
442+
token: "single_token",
443+
expectedCloneURL: "https://oauth2:[email protected]",
444+
},
445+
{
446+
desc: "Multi Token",
447+
token: "token1,token2",
448+
expectedCloneURL: "https://oauth2:[email protected]",
449+
},
450+
}
451+
factory := GithubDownloaderV3Factory{}
452+
453+
for _, tC := range testCases {
454+
t.Run(tC.desc, func(t *testing.T) {
455+
opts := base.MigrateOptions{CloneAddr: "https://github.com/go-gitea/gitea", AuthToken: tC.token}
456+
client, err := factory.New(t.Context(), opts)
457+
require.NoError(t, err)
458+
459+
cloneURL, err := client.FormatCloneURL(opts, "https://github.com")
460+
require.NoError(t, err)
461+
462+
assert.Equal(t, tC.expectedCloneURL, cloneURL)
463+
})
464+
}
465+
}

0 commit comments

Comments
 (0)