package testsuite import ( "context" "testing" "forge.cadoles.com/cadoles/bouncer/internal/store" "github.com/pkg/errors" ) type layerRepositoryTestCase struct { Name string Do func(repo store.LayerRepository) error } const layerType store.LayerType = "test" var layerRepositoryTestCases = []layerRepositoryTestCase{ { Name: "Create layer", Do: func(repo store.LayerRepository) error { ctx := context.Background() options := map[string]any{} layer, err := repo.CreateLayer(ctx, "create_layer_proxy", "create_layer", layerType, options) if err != nil { return errors.WithStack(err) } if layer == nil { return errors.Errorf("layer should not be nil") } if layer.Name == "" { return errors.Errorf("layer.Name should not be empty") } if layer.Proxy == "" { return errors.Errorf("layer.Proxy should not be empty") } if layer.CreatedAt.IsZero() { return errors.Errorf("layer.CreatedAt should not be zero value") } if layer.UpdatedAt.IsZero() { return errors.Errorf("layer.UpdatedAt should not be zero value") } return nil }, }, } func TestLayerRepository(t *testing.T, repo store.LayerRepository) { for _, tc := range layerRepositoryTestCases { func(tc layerRepositoryTestCase) { t.Run(tc.Name, func(t *testing.T) { if err := tc.Do(repo); err != nil { t.Fatalf("%+v", errors.WithStack(err)) } }) }(tc) } }