All checks were successful
Go CI/CD / go-ci (push) Successful in 19m9s
Reviewed-on: #2 Reviewed-by: Cloud Administrator <cloud-admin@noreply.gitstormr.dev> Co-authored-by: Rene Nochebuena <code-raider@noreply.gitstormr.dev> Co-committed-by: Rene Nochebuena <code-raider@noreply.gitstormr.dev>
44 lines
896 B
Go
44 lines
896 B
Go
package stonesql
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"gitstormr.dev/stone-utils/stonesql/test"
|
|
)
|
|
|
|
type migratorSuccessMock struct{}
|
|
|
|
func (m *migratorSuccessMock) ExecuteMigration(
|
|
ctx context.Context, name string, sqlContent string,
|
|
) error {
|
|
fmt.Println(name, sqlContent)
|
|
return nil
|
|
}
|
|
|
|
type migratorFailureMock struct{}
|
|
|
|
func (m *migratorFailureMock) ExecuteMigration(
|
|
ctx context.Context, name string, sqlContent string,
|
|
) error {
|
|
return fmt.Errorf("failed to execute migration %s", name)
|
|
}
|
|
|
|
func Test_MigrationSuccess(t *testing.T) {
|
|
migrator := &migratorSuccessMock{}
|
|
err := RunMigrations(context.Background(), migrator, test.TestFS, ".")
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
func Test_MigrationFailure(t *testing.T) {
|
|
migrator := &migratorFailureMock{}
|
|
err := RunMigrations(context.Background(), migrator, test.TestFS, ".")
|
|
|
|
if err == nil {
|
|
t.Error("expected error")
|
|
}
|
|
}
|