This repository has been archived by the owner on Jun 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 324
/
parse_test.go
106 lines (101 loc) · 2.1 KB
/
parse_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package source
import (
"testing"
)
func TestParse(t *testing.T) {
tt := []struct {
name string
expectErr error
expectMigration *Migration
}{
{
name: "1_foobar.up.sql",
expectErr: nil,
expectMigration: &Migration{
Version: 1,
Identifier: "foobar",
Direction: Up,
Raw: "1_foobar.up.sql",
},
},
{
name: "1_foobar.down.sql",
expectErr: nil,
expectMigration: &Migration{
Version: 1,
Identifier: "foobar",
Direction: Down,
Raw: "1_foobar.down.sql",
},
},
{
name: "1_f-o_ob+ar.up.sql",
expectErr: nil,
expectMigration: &Migration{
Version: 1,
Identifier: "f-o_ob+ar",
Direction: Up,
Raw: "1_f-o_ob+ar.up.sql",
},
},
{
name: "1485385885_foobar.up.sql",
expectErr: nil,
expectMigration: &Migration{
Version: 1485385885,
Identifier: "foobar",
Direction: Up,
Raw: "1485385885_foobar.up.sql",
},
},
{
name: "20170412214116_date_foobar.up.sql",
expectErr: nil,
expectMigration: &Migration{
Version: 20170412214116,
Identifier: "date_foobar",
Direction: Up,
Raw: "20170412214116_date_foobar.up.sql",
},
},
{
name: "-1_foobar.up.sql",
expectErr: ErrParse,
expectMigration: nil,
},
{
name: "foobar.up.sql",
expectErr: ErrParse,
expectMigration: nil,
},
{
name: "1.up.sql",
expectErr: ErrParse,
expectMigration: nil,
},
{
name: "1_foobar.sql",
expectErr: ErrParse,
expectMigration: nil,
},
{
name: "1_foobar.up",
expectErr: ErrParse,
expectMigration: nil,
},
{
name: "1_foobar.down",
expectErr: ErrParse,
expectMigration: nil,
},
}
for i, v := range tt {
f, err := Parse(v.name)
if err != v.expectErr {
t.Errorf("expected %v, got %v, in %v", v.expectErr, err, i)
}
if v.expectMigration != nil && *f != *v.expectMigration {
t.Errorf("expected %+v, got %+v, in %v", *v.expectMigration, *f, i)
}
}
}