MCPcopy Create free account
hub / github.com/daodst/chat / Test_migrations_Up

Function Test_migrations_Up

internal/sqlutil/migrate_test.go:58–112  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

56}
57
58func Test_migrations_Up(t *testing.T) {
59 withFail := append(dummyMigrations, failMigration)
60
61 tests := []struct {
62 name string
63 migrations []sqlutil.Migration
64 wantResult map[string]struct{}
65 wantErr bool
66 }{
67 {
68 name: "dummy migration",
69 migrations: dummyMigrations,
70 wantResult: map[string]struct{}{
71 "init": {},
72 "v2": {},
73 "multiple execs": {},
74 },
75 },
76 {
77 name: "with fail",
78 migrations: withFail,
79 wantErr: true,
80 },
81 }
82
83 ctx := context.Background()
84 for _, tt := range tests {
85 t.Run(tt.name, func(t *testing.T) {
86 test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
87 conStr, close := test.PrepareDBConnectionString(t, dbType)
88 defer close()
89 driverName := "sqlite3"
90 if dbType == test.DBTypePostgres {
91 driverName = "postgres"
92 }
93 db, err := sql.Open(driverName, conStr)
94 if err != nil {
95 t.Errorf("unable to open database: %v", err)
96 }
97 m := sqlutil.NewMigrator(db)
98 m.AddMigrations(tt.migrations...)
99 if err = m.Up(ctx); (err != nil) != tt.wantErr {
100 t.Errorf("Up() error = %v, wantErr %v", err, tt.wantErr)
101 }
102 result, err := m.ExecutedMigrations(ctx)
103 if err != nil {
104 t.Errorf("unable to get executed migrations: %v", err)
105 }
106 if !tt.wantErr && !reflect.DeepEqual(result, tt.wantResult) {
107 t.Errorf("expected: %+v, got %v", tt.wantResult, result)
108 }
109 })
110 })
111 }
112}

Callers

nothing calls this directly

Calls 5

AddMigrationsMethod · 0.95
UpMethod · 0.95
ExecutedMigrationsMethod · 0.95
RunMethod · 0.80
OpenMethod · 0.65

Tested by

no test coverage detected