-
Notifications
You must be signed in to change notification settings - Fork 18
/
migration_test.go
48 lines (43 loc) · 990 Bytes
/
migration_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
package main
import (
"encoding/json"
"reflect"
"testing"
)
func TestRetrieveMigrations(t *testing.T) {
got := retrieveMigrations([]string{
"AppEnv=prod test/migration.go -arg1 val1 -arg2 val2",
"AppEnv='pr od' AppEnv='pr od' test/migration.go -arg1 val1 -arg2 val2",
"AppEnv='pr od' test/migration.go",
})
expect := []Migration{
{
File: "test/migration.go",
Base: "migration.go",
Envs: "AppEnv=prod",
Args: "-arg1 val1 -arg2 val2",
},
{
File: "test/migration.go",
Base: "migration.go",
Envs: "AppEnv='pr od' AppEnv='pr od'",
Args: "-arg1 val1 -arg2 val2",
},
{
File: "test/migration.go",
Base: "migration.go",
Envs: "AppEnv='pr od'",
Args: "",
},
}
if !reflect.DeepEqual(expect, got) {
t.Errorf("expect %s got %s", pretty(expect), pretty(got))
}
}
func pretty(v interface{}) string {
r, err := json.MarshalIndent(v, "", " ")
if err != nil {
panic("failed to marshal indent: " + err.Error())
}
return string(r)
}