|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "io/ioutil" |
| 5 | + "os" |
| 6 | + "testing" |
| 7 | + "time" |
| 8 | + |
| 9 | + "github.com/stretchr/testify/assert" |
| 10 | + |
| 11 | + mg0b "github.com/MichaelMure/git-bug-migration/migration0/bug" |
| 12 | + mg0r "github.com/MichaelMure/git-bug-migration/migration0/repository" |
| 13 | + mg1b "github.com/MichaelMure/git-bug-migration/migration1/bug" |
| 14 | + mg1i "github.com/MichaelMure/git-bug-migration/migration1/identity" |
| 15 | + |
| 16 | + mg1r "github.com/MichaelMure/git-bug-migration/migration1/repository" |
| 17 | +) |
| 18 | + |
| 19 | +func createFolder() (string, error) { |
| 20 | + dir, err := ioutil.TempDir("", "") |
| 21 | + return dir, err |
| 22 | +} |
| 23 | + |
| 24 | +func removeFolder(path string) error { |
| 25 | + return os.RemoveAll(path) |
| 26 | +} |
| 27 | + |
| 28 | +func TestMigrate01(t *testing.T) { |
| 29 | + cwd, err := os.Getwd() |
| 30 | + assert.Nil(t, err, "got error when attempting to access the current working directory") |
| 31 | + |
| 32 | + oldVinc := mg0b.Person{ |
| 33 | + Name: "Vincent Tiu", |
| 34 | + Email: "vincetiu8@gmail.com", |
| 35 | + Login: "invincibot", |
| 36 | + AvatarUrl: "https://avatars2.githubusercontent.com/u/46623413?s=460&u=56824597898bc22464222f5c33e8eae6d72def5b&v=4", |
| 37 | + } |
| 38 | + |
| 39 | + newVinc := mg1i.NewIdentityFull( |
| 40 | + oldVinc.Name, |
| 41 | + oldVinc.Email, |
| 42 | + oldVinc.Login, |
| 43 | + oldVinc.AvatarUrl, |
| 44 | + ) |
| 45 | + |
| 46 | + var unix = time.Now().Unix() |
| 47 | + |
| 48 | + dir, err := createFolder() |
| 49 | + os.Chdir(dir) |
| 50 | + assert.Nil(t, err, "got error when creating temporary repository dir with version 0") |
| 51 | + repo0, err := mg0r.InitGitRepo(dir) |
| 52 | + |
| 53 | + bug0, _, err := mg0b.Create(oldVinc, unix, "bug1", "beep bop bug") |
| 54 | + assert.Nil(t, err, "got error when creating bug") |
| 55 | + |
| 56 | + err = bug0.Commit(repo0) |
| 57 | + assert.Nil(t, err, "got error when committing bug") |
| 58 | + |
| 59 | + Migrate01() |
| 60 | + |
| 61 | + repo1, err := mg1r.NewGitRepo(dir, []mg1r.ClockLoader{mg1b.ClockLoader}) |
| 62 | + assert.Nil(t, err, "got error when loading repository with version 1") |
| 63 | + |
| 64 | + bugs1 := mg1b.ReadAllLocalBugs(repo1) |
| 65 | + bug1 := (<-bugs1).Bug |
| 66 | + operations := mg1b.NewOperationIterator(bug1) |
| 67 | + assert.Equal(t, true, operations.Next(), "unable to get first operation") |
| 68 | + |
| 69 | + operation := operations.Value() |
| 70 | + |
| 71 | + author := operation.GetAuthor() |
| 72 | + assert.IsType(t, newVinc, author, "author type mismatch") |
| 73 | + assert.Equal(t, newVinc.Name(), author.Name(), "author name mismatch") |
| 74 | + assert.Equal(t, newVinc.Email(), author.Email(), "author email mismatch") |
| 75 | + assert.Equal(t, newVinc.Login(), author.Login(), "author login mismatch") |
| 76 | + assert.Equal(t, newVinc.AvatarUrl(), author.AvatarUrl(), "author avatarUrl mismatch") |
| 77 | + |
| 78 | + var bug mg1b.StreamedBug |
| 79 | + assert.Equal(t, bug, <-bugs1, "got additional bug when getting bugs in repository") |
| 80 | + |
| 81 | + os.Chdir(cwd) |
| 82 | + removeFolder(dir) |
| 83 | +} |
0 commit comments