-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfwish_test.go
74 lines (65 loc) · 1.54 KB
/
fwish_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
package fwish_test
import (
"errors"
"strings"
"testing"
"github.com/rez-go/fwish"
sqlsource "github.com/rez-go/fwish/sources/sql"
)
type sourceConflict struct {
}
func (s *sourceConflict) SchemaID() string { return "" }
func (s *sourceConflict) SchemaName() string { return "" }
func (s *sourceConflict) Migrations() ([]fwish.MigrationInfo, error) {
return []fwish.MigrationInfo{
{Name: "V1__test"},
{Name: "V1__test2"},
}, nil
}
func (s *sourceConflict) ExecuteMigration(db fwish.DB, migration fwish.MigrationInfo) error {
return errors.New("not implemented")
}
func TestVersionConflict(t *testing.T) {
mg, err := fwish.NewMigrator("")
if err != nil {
t.Fatal(err)
}
err = mg.AddSource(&sourceConflict{})
if err == nil {
t.Fatal("unexpected nil error")
}
if !strings.Contains(err.Error(), `version "1" conflict`) {
t.Fatal("wrong error message")
}
}
func TestSchemaIDMatchSourceProgram(t *testing.T) {
mg, err := fwish.NewMigrator("372ce18d-02a2-4cb1-828a-bb470f02fe6e")
if err != nil {
t.Fatal(err)
}
src, err := sqlsource.LoadDir("./test-data/basic")
if err != nil {
t.Fatal(err)
}
err = mg.AddSource(src)
if err != nil {
t.Fatal(err)
}
}
func TestSchemaIDMismatchSourceProgram(t *testing.T) {
mg, err := fwish.NewMigrator("myapp.example.com")
if err != nil {
t.Fatal(err)
}
src, err := sqlsource.LoadDir("./test-data/basic")
if err != nil {
t.Fatal(err)
}
err = mg.AddSource(src)
if err == nil {
t.Fatal("unexpected nil error")
}
if !strings.Contains(err.Error(), "schema ID mismatch") {
t.Error(err)
}
}