-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathTestMigrations.fs
119 lines (109 loc) · 3.16 KB
/
TestMigrations.fs
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
107
108
109
110
111
112
113
114
115
116
117
118
119
module Rezoom.SQL.Test.TestMigrations
open System
open System.IO
open NUnit.Framework
open FsUnit
open Rezoom.SQL.Compiler
open Rezoom.SQL.Mapping
open Rezoom.SQL.Migrations
type Tree =
{ MigrationName : string
Children : Tree list
}
let private branch migrationName children =
{ MigrationName = migrationName
Children = children
}
let private leaf migrationName = branch migrationName []
let rec toTree (migraton : string MigrationTree) =
{ MigrationName = migraton.Node.MigrationName
Children = toTrees migraton.Children
}
and toTrees migrations = migrations |> Seq.map toTree |> Seq.toList
[<Test>]
let ``model 2 migration tree`` () =
let model = userModel2()
let migrations = model.Migrations
let expected =
[ branch "V1, initial"
[ leaf "V1, employer"
leaf "V1, groups"
]
leaf "V2, companygroups"
]
printfn "%A" migrations
let trees = toTrees migrations
printfn "%A" trees
Assert.AreEqual(expected, trees)
[<Test>]
let ``model 3 fails`` () =
try
ignore <| userModelByName "user-model-3"
failwith "should've failed"
with
| :? SQLCompilerException as c when c.Message = Error.minorMigrationContainsDestruction "V1, drop" ->
()
| other ->
printfn "wrong exn %O" other
reraise()
[<Test>]
let ``model 4 fails`` () =
try
ignore <| userModelByName "user-model-4"
failwith "should've failed"
with
| :? SQLCompilerException as c when c.Message = Error.migrationContainsParameter "V2, bad" ->
()
| other ->
printfn "wrong exn %O" other
reraise()
[<Test>]
let ``model 5 migration tree`` () =
let model = userModelByName "user-model-5"
let migrations = model.Migrations
let expected =
[ branch "V1, model"
[ branch "V1, comments"
[ leaf "V1, time"
]
branch "V1, groups"
[ branch "V1, foos"
[ leaf "V1, bars"
]
]
]
branch "V2, next"
[ leaf "V2, baz"
leaf "V2, qux"
]
]
printfn "%A" migrations
let trees = toTrees migrations
printfn "%A" trees
Assert.AreEqual(expected, trees)
[<Test>]
let ``model 6 fails`` () =
try
ignore <| userModelByName "user-model-6"
failwith "should've failed"
with
| :? SQLCompilerException as c when c.Message = Error.noSuchTable "Foos" ->
()
| other ->
printfn "wrong exn %O" other
reraise()
[<Test>]
let ``model 6-good migration tree`` () =
let model = userModelByName "user-model-6-good"
let migrations = model.Migrations
let expected =
[ branch "V1, model"
[ branch "V1, a"
[ leaf "V1, b"
]
]
]
printfn "%A" migrations
let trees = toTrees migrations
printfn "%A" trees
Assert.AreEqual(expected, trees)