gotelem/migration_test.go
saji 4e6f8db7ed
All checks were successful
Go / build (1.21) (push) Successful in 1m16s
Go / build (1.22) (push) Successful in 1m15s
combine separate packages
2024-03-02 21:49:18 -06:00

85 lines
1.7 KiB
Go

package gotelem
import (
"embed"
"reflect"
"testing"
)
// import just the first and second migrations to ensure stability.
//
//go:embed migrations/1_*.sql
//go:embed migrations/2_*.sql
var testFs embed.FS
func Test_getMigrations(t *testing.T) {
tests := []struct {
name string
want map[int]map[string]Migration
}{
{
name: "main test",
want: map[int]map[string]Migration{
1: {
"up": Migration{
Name: "initial",
Version: 1,
FileName: "1_initial_up.sql",
},
"down": Migration{
Name: "initial",
Version: 1,
FileName: "1_initial_down.sql",
},
},
2: {
"up": Migration{
Name: "addl_tables",
Version: 2,
FileName: "2_addl_tables_up.sql",
},
"down": Migration{
Name: "addl_tables",
Version: 2,
FileName: "2_addl_tables_down.sql",
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := getMigrations(testFs); !reflect.DeepEqual(got, tt.want) {
t.Errorf("getMigrations() = %v, want %v", got, tt.want)
}
})
}
}
func TestRunMigrations(t *testing.T) {
type args struct {
tdb *TelemDb
}
tests := []struct {
name string
args args
wantFinalVer int
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotFinalVer, err := RunMigrations(tt.args.tdb)
if (err != nil) != tt.wantErr {
t.Errorf("RunMigrations() error = %v, wantErr %v", err, tt.wantErr)
return
}
if gotFinalVer != tt.wantFinalVer {
t.Errorf("RunMigrations() = %v, want %v", gotFinalVer, tt.wantFinalVer)
}
})
}
}