forked from JonasFranzDEV/gitea-github-migrator
Add tests (#5 )
parent
4e61d1ca09
commit
9a306fb468
@ -0,0 +1,23 @@ |
||||
package cmd |
||||
|
||||
import ( |
||||
"context" |
||||
"testing" |
||||
|
||||
"git.jonasfranz.software/JonasFranzDEV/gitea-github-migrator/migrations" |
||||
"github.com/google/go-github/github" |
||||
"github.com/stretchr/testify/assert" |
||||
) |
||||
|
||||
// Test_migrate is an integration tests for migrate command
|
||||
// using repo JonasFranzDEV/test
|
||||
func Test_migrate(t *testing.T) { |
||||
assert.NoError(t, migrate( |
||||
context.Background(), |
||||
github.NewClient(nil), |
||||
migrations.DemoMigratory, |
||||
"JonasFranzDEV", |
||||
"test", |
||||
false, |
||||
)) |
||||
} |
@ -0,0 +1,49 @@ |
||||
package migrations |
||||
|
||||
import ( |
||||
"testing" |
||||
|
||||
"code.gitea.io/sdk/gitea" |
||||
"github.com/google/go-github/github" |
||||
"github.com/stretchr/testify/assert" |
||||
) |
||||
|
||||
func Test_githubStateToGiteaState(t *testing.T) { |
||||
open := "open" |
||||
all := "all" |
||||
closed := "closed" |
||||
tests := map[*string]string{&all: "open", &open: "open", &closed: "closed"} |
||||
for input, exceptedResult := range tests { |
||||
actualResult := githubStateToGiteaState(input) |
||||
assert.NotNil(t, actualResult) |
||||
assert.NotEmpty(t, *actualResult) |
||||
assert.Equal(t, exceptedResult, *actualResult) |
||||
} |
||||
nilInput := "teoafweogwoe" |
||||
assert.Nil(t, githubStateToGiteaState(&nilInput)) |
||||
} |
||||
|
||||
func TestMigratory_Label(t *testing.T) { |
||||
res, err := DemoMigratory.Label(&github.Label{ |
||||
Name: github.String("testlabel"), |
||||
Color: github.String("123456"), |
||||
}) |
||||
assert.NoError(t, err) |
||||
assert.Equal(t, "123456", res.Color) |
||||
assert.Equal(t, "testlabel", res.Name) |
||||
} |
||||
|
||||
func TestMigratory_Milestone(t *testing.T) { |
||||
res, err := DemoMigratory.Milestone(&github.Milestone{ |
||||
ID: github.Int64(1), |
||||
State: github.String("open"), |
||||
Description: github.String("test milestone"), |
||||
Title: github.String("TEST"), |
||||
DueOn: &demoTime, |
||||
}) |
||||
assert.NoError(t, err) |
||||
assert.Equal(t, "TEST", res.Title) |
||||
assert.Equal(t, "test milestone", res.Description) |
||||
assert.Equal(t, demoTime.Unix(), res.Deadline.Unix()) |
||||
assert.Equal(t, gitea.StateOpen, res.State) |
||||
} |
@ -0,0 +1,24 @@ |
||||
package migrations |
||||
|
||||
import ( |
||||
"time" |
||||
|
||||
"code.gitea.io/sdk/gitea" |
||||
) |
||||
|
||||
var DemoMigratory = &Migratory{ |
||||
AuthUsername: "demo", |
||||
AuthPassword: "demo", |
||||
Client: gitea.NewClient("http://gitea:3000", "8bffa364d5a4b2f18421426da0baf6ccddd16d6b"), |
||||
repository: &gitea.Repository{ |
||||
Name: "demo", |
||||
Owner: &gitea.User{ |
||||
UserName: "demo", |
||||
}, |
||||
}, |
||||
NewOwnerID: 1, |
||||
migratedMilestones: make(map[int64]int64), |
||||
migratedLabels: make(map[int64]int64), |
||||
} |
||||
|
||||
var demoTime = time.Date(2018, 01, 01, 01, 01, 01, 01, time.UTC) |
Loading…
Reference in new issue