|
| 1 | +package migration3 |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "io/ioutil" |
| 6 | + "os" |
| 7 | + "testing" |
| 8 | + "time" |
| 9 | + |
| 10 | + "github.com/stretchr/testify/require" |
| 11 | + |
| 12 | + afterbug "github.com/MichaelMure/git-bug-migration/migration3/after/bug" |
| 13 | + afterrepo "github.com/MichaelMure/git-bug-migration/migration3/after/repository" |
| 14 | + beforebug "github.com/MichaelMure/git-bug-migration/migration3/before/bug" |
| 15 | + beforeidentity "github.com/MichaelMure/git-bug-migration/migration3/before/identity" |
| 16 | + beforerepo "github.com/MichaelMure/git-bug-migration/migration3/before/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 TestMigrate23(t *testing.T) { |
| 29 | + cwd, err := os.Getwd() |
| 30 | + require.Nil(t, err, "got error when attempting to access the current working directory") |
| 31 | + |
| 32 | + var unix = time.Now().Unix() |
| 33 | + |
| 34 | + dir, err := createFolder() |
| 35 | + require.Nil(t, err, "got error when creating temporary repository dir with version 0") |
| 36 | + err = os.Chdir(dir) |
| 37 | + require.Nil(t, err, "got error when opening temporary repository folder") |
| 38 | + |
| 39 | + oldRepo, err := beforerepo.InitGitRepo(dir) |
| 40 | + require.Nil(t, err, "got error when initializing old repository") |
| 41 | + newRepo, err := afterrepo.InitGitRepo(dir) |
| 42 | + require.Nil(t, err, "got error when initializing new repository") |
| 43 | + |
| 44 | + oldVinc := beforeidentity.NewIdentityFull( |
| 45 | + "Vincent Tiu", |
| 46 | + "vincetiu8@gmail.com", |
| 47 | + "invincibot", |
| 48 | + "https://avatars2.githubusercontent.com/u/46623413?s=460&u=56824597898bc22464222f5c33e8eae6d72def5b&v=4", |
| 49 | + ) |
| 50 | + err = oldVinc.Commit(oldRepo) |
| 51 | + require.NoError(t, err) |
| 52 | + |
| 53 | + title := "bug0" |
| 54 | + message := "beep bop bug" |
| 55 | + bug0, _, err := beforebug.Create(oldVinc, unix, title, message) |
| 56 | + require.Nil(t, err, "got error when creating bug") |
| 57 | + |
| 58 | + err = bug0.Commit(oldRepo) |
| 59 | + require.Nil(t, err, "got error when committing bug") |
| 60 | + |
| 61 | + m := Migration3{} |
| 62 | + err = m.migrate(oldRepo, newRepo) |
| 63 | + require.Nil(t, err, "got error when migrating repository") |
| 64 | + |
| 65 | + bugs1 := afterbug.ReadAllLocal(newRepo) |
| 66 | + bug1 := (<-bugs1).Bug |
| 67 | + |
| 68 | + operations := afterbug.NewOperationIterator(bug1) |
| 69 | + require.Equal(t, true, operations.Next(), "unable to get first operation") |
| 70 | + |
| 71 | + operation := operations.Value() |
| 72 | + createOperation, ok := operation.(*afterbug.CreateOperation) |
| 73 | + require.True(t, ok) |
| 74 | + require.Equal(t, title, createOperation.Title) |
| 75 | + require.Equal(t, unix, createOperation.UnixTime) |
| 76 | + require.Equal(t, message, createOperation.Message) |
| 77 | + |
| 78 | + author := operation.GetAuthor() |
| 79 | + require.Equal(t, oldVinc.Name(), author.Name()) |
| 80 | + require.Equal(t, oldVinc.Login(), author.Login()) |
| 81 | + require.Equal(t, oldVinc.Email(), author.Email()) |
| 82 | + require.Equal(t, oldVinc.AvatarUrl(), author.AvatarUrl()) |
| 83 | + |
| 84 | + var bug afterbug.StreamedBug |
| 85 | + require.Equal(t, bug, <-bugs1, "got additional bug when getting bugs in repository") |
| 86 | + |
| 87 | + err = os.Chdir(cwd) |
| 88 | + err = removeFolder(dir) |
| 89 | + if err != nil { |
| 90 | + fmt.Printf("got error when removing temporary folder: %q", err) |
| 91 | + } |
| 92 | +} |
0 commit comments