github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/storage/driver/postsql/orchestration_test.go (about) 1 package postsql_test 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/kyma-project/kyma-environment-broker/common/orchestration" 8 "github.com/kyma-project/kyma-environment-broker/internal/events" 9 "github.com/kyma-project/kyma-environment-broker/internal/fixture" 10 "github.com/kyma-project/kyma-environment-broker/internal/storage" 11 "github.com/kyma-project/kyma-environment-broker/internal/storage/dberr" 12 "github.com/kyma-project/kyma-environment-broker/internal/storage/dbmodel" 13 "github.com/sirupsen/logrus" 14 "github.com/stretchr/testify/assert" 15 "github.com/stretchr/testify/require" 16 ) 17 18 func TestOrchestration(t *testing.T) { 19 20 ctx := context.Background() 21 22 t.Run("Orchestrations", func(t *testing.T) { 23 containerCleanupFunc, cfg, err := storage.InitTestDBContainer(t.Logf, ctx, "test_DB_1") 24 require.NoError(t, err) 25 defer containerCleanupFunc() 26 27 tablesCleanupFunc, err := storage.InitTestDBTables(t, cfg.ConnectionURL()) 28 require.NoError(t, err) 29 defer tablesCleanupFunc() 30 31 cipher := storage.NewEncrypter(cfg.SecretKey) 32 brokerStorage, _, err := storage.NewFromConfig(cfg, events.Config{}, cipher, logrus.StandardLogger()) 33 require.NoError(t, err) 34 require.NotNil(t, brokerStorage) 35 36 givenOrchestration := fixture.FixOrchestration("test") 37 givenOrchestration.Type = orchestration.UpgradeKymaOrchestration 38 givenOrchestration.State = "test" 39 givenOrchestration.Description = "test" 40 givenOrchestration.Parameters.DryRun = true 41 42 svc := brokerStorage.Orchestrations() 43 44 err = svc.Insert(givenOrchestration) 45 require.NoError(t, err) 46 47 // when 48 gotOrchestration, err := svc.GetByID("test") 49 require.NoError(t, err) 50 assert.Equal(t, givenOrchestration.Parameters, gotOrchestration.Parameters) 51 assert.Equal(t, orchestration.UpgradeKymaOrchestration, gotOrchestration.Type) 52 53 gotOrchestration.Description = "new modified description 1" 54 err = svc.Update(givenOrchestration) 55 require.NoError(t, err) 56 57 err = svc.Insert(givenOrchestration) 58 assertError(t, dberr.CodeAlreadyExists, err) 59 60 l, count, totalCount, err := svc.List(dbmodel.OrchestrationFilter{PageSize: 10, Page: 1}) 61 require.NoError(t, err) 62 assert.Len(t, l, 1) 63 assert.Equal(t, 1, count) 64 assert.Equal(t, 1, totalCount) 65 66 l, c, tc, err := svc.List(dbmodel.OrchestrationFilter{States: []string{"test"}, Types: []string{string(orchestration.UpgradeKymaOrchestration)}}) 67 require.NoError(t, err) 68 assert.Len(t, l, 1) 69 assert.Equal(t, 1, c) 70 assert.Equal(t, 1, tc) 71 }) 72 }