@@ -5,15 +5,15 @@ import (
55)
66
77func TestActionMigrateUp (t * testing.T ) {
8- cli , teardown := NewTestCLI (t )
9- defer teardown ()
8+ cli , teardown := NewTestCLI (t )
9+ defer teardown ()
1010
11- dbTeardown := cli .RandomDatabase ()
12- defer dbTeardown ()
11+ dbTeardown := cli .RandomDatabase ()
12+ defer dbTeardown ()
1313
14- cli .Files (
15- "set.fyml" ,
16- `
14+ cli .Files (
15+ "set.fyml" ,
16+ `
1717apiVersion: migrations/v1
1818kind: MigrationSet
1919metadata:
2424 migrations:
2525 - create_animals
2626 ` ,
27- "01_create_animals.fyml" ,
28- `
27+ "01_create_animals.fyml" ,
28+ `
2929apiVersion: migrations/v1
3030kind: Migration
3131metadata:
@@ -38,43 +38,63 @@ spec:
3838 down:
3939 sql: DROP TABLE animals;
4040` ,
41- )
41+ )
4242
43- cli .AssertRun ("migrate" , "status" , "--set" , "public" , "--driver" , "test" )
44- cli .AssertOutputContains (t , "pending v1 create_animals" )
45- cli .ResetAllOutputs ()
43+ cli .AssertRun ("migrate" , "status" , "--set" , "public" , "--driver" , "test" )
44+ cli .AssertOutputContains (t , "pending v1 create_animals" )
45+ cli .ResetAllOutputs ()
4646
47- cli .AssertRun ("migrate" , "up" , "--set" , "public" , "--driver" , "test" )
47+ cli .AssertRun ("migrate" , "up" , "--set" , "public" , "--driver" , "test" )
4848 cli .AssertOutputNotContains (t , "No pending migrations" )
49- cli .AssertOutputContains (t , "Applied successfully" )
50- cli .ResetAllOutputs ()
49+ cli .AssertOutputContains (t , "Applied successfully" )
50+ cli .ResetAllOutputs ()
5151
52- cli .AssertRun ("migrate" , "up" , "--set" , "public" , "--driver" , "test" )
52+ cli .AssertRun ("migrate" , "up" , "--set" , "public" , "--driver" , "test" )
5353 cli .AssertOutputContains (t , "No pending migrations" )
54- cli .ResetAllOutputs ()
54+ cli .ResetAllOutputs ()
5555
56- cli .AssertRun ("migrate" , "status" , "--set" , "public" , "--driver" , "test" )
57- cli .AssertOutputContains (t , "completed v1 create_animals" )
58- cli .ResetAllOutputs ()
59- // cli.AssertSchemaMigrationTable(t, "public", "v1")
60- // TODO:
61- // - count records in schema migration table
62- // - read records in schema migration table
63- // - check if table exists
64- // - check if table does not exists
65- // - fix english with asserts Contains? NotContain? be consistent
56+ cli .AssertRun ("migrate" , "status" , "--set" , "public" , "--driver" , "test" )
57+ cli .AssertOutputContains (t , "completed v1 create_animals" )
58+ cli .ResetAllOutputs ()
6659
67- // cli.AssertRecordsCount("test", "public", 0)
68- // ...
69- // cli.AssertRecordsCount("test", "public", 1)
60+ audit := cli .Audit ("test" , "public" )
61+ audit .AssertCount (2 )
62+ audit .Assert (0 , auditLog {
63+ ID : 1 ,
64+ Event : "migration.up.started" ,
65+ Data : map [string ]any {
66+ "migration" : "create_animals" ,
67+ "set" : "public" ,
68+ "version" : "v1" ,
69+ },
70+ Metadata : map [string ]any {},
71+ })
72+ audit .Assert (1 , auditLog {
73+ ID : 2 ,
74+ Event : "migration.up.completed" ,
75+ Data : map [string ]any {
76+ "migration" : "create_animals" ,
77+ "set" : "public" ,
78+ "version" : "v1" ,
79+ },
80+ Metadata : map [string ]any {},
81+ })
82+ // TODO:
83+ // - check if table exists
84+ // - check if table does not exists
85+ // - fix english with asserts Contains? NotContain? be consistent
7086
71- // audit := cli.UseAudit ("test", "public")
72- // ...
73- // audit.AssertEvent(1 , "pending" )
87+ // cli.AssertRecordsCount ("test", "public", 0 )
88+ // ...
89+ // cli.AssertRecordsCount("test" , "public", 1 )
7490
75- // query := cli.UseQuery("test", "public")
76- // query.AssertTableExists("animals")
77- // query.AssertCount("table", 1)
91+ // audit := cli.UseAudit("test", "public")
92+ // ...
93+ // audit.AssertEvent(1, "pending")
94+
95+ // query := cli.UseQuery("test", "public")
96+ // query.AssertTableExists("animals")
97+ // query.AssertCount("table", 1)
7898}
7999
80100// func TestActionMigrateUpWithError(t *testing.T) {
0 commit comments