Skip to content
This repository was archived by the owner on Aug 24, 2024. It is now read-only.

Commit 6d016ab

Browse files
committed
Add unit test for migration
This commit adds a unit test for the migration function.
1 parent b46c794 commit 6d016ab

38 files changed

+3985
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ Sections:
1616
- Identity
1717
- OperationPack
1818
- Config
19+
20+
Note: All imports follow the format mg{migration folder number}{first letter of package}
21+
For example, to import the bug from the migration 1 folder, its name should be mg1b.
22+
To import sub-packages, put the first letter of each parent package.
23+
For example, to import the lamport clock from the migration 1 folder, its name should be mg1ul.
1924

2025
Todo for migration tool:
2126
- Remove legacy author and create new identity out of it -- forwards compatible

main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ const rootCommandName = "git-bug-migration"
1414
var repo mg1r.ClockedRepo
1515

1616
func main() {
17+
Migrate01()
18+
}
19+
20+
func Migrate01() {
1721
cwd, err := os.Getwd()
1822
if err != nil {
1923
panic(fmt.Errorf("unable to get the current working directory: %q", err))

main_test.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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

Comments
 (0)