package testsuite import ( "context" "reflect" "testing" "forge.cadoles.com/Cadoles/emissary/internal/datastore" "github.com/pkg/errors" ) type specDefinitionRepositoryTestCase struct { Name string Skip bool Run func(ctx context.Context, repo datastore.SpecDefinitionRepository) error } var specDefinitionRepositoryTestCases = []specDefinitionRepositoryTestCase{ { Name: "Create a spec definition", Run: func(ctx context.Context, repo datastore.SpecDefinitionRepository) error { schema := []byte("{}") name := "net.example.foo" version := "0.0.0" specDef, err := repo.Upsert(ctx, name, version, schema) if err != nil { return errors.WithStack(err) } if specDef.CreatedAt.IsZero() { return errors.Errorf("specDef.CreatedAt should not be zero time") } if specDef.UpdatedAt.IsZero() { return errors.Errorf("specDef.UpdatedAt should not be zero time") } if e, g := name, specDef.Name; e != g { return errors.Errorf("specDef.Name: expected '%v', got '%v'", e, g) } if e, g := version, specDef.Version; e != g { return errors.Errorf("specDef.Name: expected '%v', got '%v'", e, g) } if e, g := schema, specDef.Schema; !reflect.DeepEqual(e, g) { return errors.Errorf("specDef.Schema: expected '%v', got '%v'", e, g) } return nil }, }, } func runSpecDefinitionRepositoryTests(t *testing.T, repo datastore.SpecDefinitionRepository) { for _, tc := range specDefinitionRepositoryTestCases { func(tc specDefinitionRepositoryTestCase) { t.Run(tc.Name, func(t *testing.T) { t.Parallel() if tc.Skip { t.SkipNow() return } ctx := context.Background() if err := tc.Run(ctx, repo); err != nil { t.Errorf("%+v", errors.WithStack(err)) } }) }(tc) } }