aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/github/export_test.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-12-08 21:15:06 +0100
committerMichael Muré <batolettre@gmail.com>2019-12-08 21:28:27 +0100
commitb92adfcb5f79f2b32c3dafb0fc3e7f1b753b6197 (patch)
tree69202c4021b10f3ab7b7f5ebf229d501e95c4786 /bridge/github/export_test.go
parent981a4a848b1329da1a73270e27633911f9298bb1 (diff)
downloadgit-bug-b92adfcb5f79f2b32c3dafb0fc3e7f1b753b6197.tar.gz
bridge: huge refactor to accept multiple kind of credentials
Diffstat (limited to 'bridge/github/export_test.go')
-rw-r--r--bridge/github/export_test.go43
1 files changed, 23 insertions, 20 deletions
diff --git a/bridge/github/export_test.go b/bridge/github/export_test.go
index dba72f3f..5a0bc653 100644
--- a/bridge/github/export_test.go
+++ b/bridge/github/export_test.go
@@ -14,6 +14,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/MichaelMure/git-bug/bridge/core"
+ "github.com/MichaelMure/git-bug/bridge/core/auth"
"github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/repository"
@@ -30,7 +31,7 @@ type testCase struct {
numOrOp int // number of original operations
}
-func testCases(t *testing.T, repo *cache.RepoCache, identity *cache.IdentityCache) []*testCase {
+func testCases(t *testing.T, repo *cache.RepoCache) []*testCase {
// simple bug
simpleBug, _, err := repo.NewBug("simple bug", "new bug")
require.NoError(t, err)
@@ -92,32 +93,32 @@ func testCases(t *testing.T, repo *cache.RepoCache, identity *cache.IdentityCach
require.NoError(t, err)
return []*testCase{
- &testCase{
+ {
name: "simple bug",
bug: simpleBug,
numOrOp: 1,
},
- &testCase{
+ {
name: "bug with comments",
bug: bugWithComments,
numOrOp: 2,
},
- &testCase{
+ {
name: "bug label change",
bug: bugLabelChange,
numOrOp: 6,
},
- &testCase{
+ {
name: "bug with comment editions",
bug: bugWithCommentEditions,
numOrOp: 4,
},
- &testCase{
+ {
name: "bug changed status",
bug: bugStatusChanged,
numOrOp: 3,
},
- &testCase{
+ {
name: "bug title edited",
bug: bugTitleEdited,
numOrOp: 2,
@@ -127,11 +128,11 @@ func testCases(t *testing.T, repo *cache.RepoCache, identity *cache.IdentityCach
func TestPushPull(t *testing.T) {
// repo owner
- user := os.Getenv("GITHUB_TEST_USER")
+ envUser := os.Getenv("GITHUB_TEST_USER")
// token must have 'repo' and 'delete_repo' scopes
- token := os.Getenv("GITHUB_TOKEN_ADMIN")
- if token == "" {
+ envToken := os.Getenv("GITHUB_TOKEN_ADMIN")
+ if envToken == "" {
t.Skip("Env var GITHUB_TOKEN_ADMIN missing")
}
@@ -152,35 +153,38 @@ func TestPushPull(t *testing.T) {
defer backend.Close()
interrupt.RegisterCleaner(backend.Close)
- tests := testCases(t, backend, author)
+ tests := testCases(t, backend)
// generate project name
projectName := generateRepoName()
// create target Github repository
- err = createRepository(projectName, token)
+ err = createRepository(projectName, envToken)
require.NoError(t, err)
fmt.Println("created repository", projectName)
// Make sure to remove the Github repository when the test end
defer func(t *testing.T) {
- if err := deleteRepository(projectName, user, token); err != nil {
+ if err := deleteRepository(projectName, envUser, envToken); err != nil {
t.Fatal(err)
}
fmt.Println("deleted repository:", projectName)
}(t)
interrupt.RegisterCleaner(func() error {
- return deleteRepository(projectName, user, token)
+ return deleteRepository(projectName, envUser, envToken)
})
+ token := auth.NewToken(author.Id(), envToken, target)
+ err = auth.Store(repo, token)
+ require.NoError(t, err)
+
// initialize exporter
exporter := &githubExporter{}
- err = exporter.Init(core.Configuration{
- keyOwner: user,
+ err = exporter.Init(backend, core.Configuration{
+ keyOwner: envUser,
keyProject: projectName,
- keyToken: token,
})
require.NoError(t, err)
@@ -206,10 +210,9 @@ func TestPushPull(t *testing.T) {
require.NoError(t, err)
importer := &githubImporter{}
- err = importer.Init(core.Configuration{
- keyOwner: user,
+ err = importer.Init(backend, core.Configuration{
+ keyOwner: envUser,
keyProject: projectName,
- keyToken: token,
})
require.NoError(t, err)