github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/notification/bundle_test.go (about) 1 package notification 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestServiceProviderBundle_CreateNotificationEvent(t *testing.T) { 10 // given 11 tenants := []NotificationTenant{ 12 { 13 InstanceID: "WEAJKG-INSTANCE-1", 14 StartDate: "2022-01-01T20:00:02Z", 15 }, 16 } 17 paras := NotificationParams{ 18 OrchestrationID: "test-create", 19 EventType: KymaMaintenanceNumber, 20 Tenants: tenants, 21 } 22 23 client := NewFakeClient() 24 bundle := NewNotificationBundle("ochstA", paras, client, Config{Url: ""}) 25 26 // when 27 err := bundle.CreateNotificationEvent() 28 29 // then 30 assert.NoError(t, err) 31 32 event, err := client.GetMaintenanceEvent("test-create") 33 assert.NoError(t, err) 34 assert.Equal(t, "test-create", event.OrchestrationID) 35 assert.Equal(t, "WEAJKG-INSTANCE-1", event.Tenants[0].InstanceID) 36 assert.Equal(t, "2022-01-01T20:00:02Z", event.Tenants[0].StartDate) 37 assert.Equal(t, "1", event.EventType) 38 } 39 40 func TestServiceProviderBundle_UpdateNotificationEvent(t *testing.T) { 41 // given 42 tenants := []NotificationTenant{ 43 { 44 InstanceID: "WEAJKG-INSTANCE-1", 45 StartDate: "2022-01-01T20:00:02Z", 46 State: UnderMaintenanceEventState, 47 }, 48 } 49 paras := NotificationParams{ 50 OrchestrationID: FakeOrchestrationID, 51 Tenants: tenants, 52 } 53 54 client := NewFakeClient() 55 bundle := NewNotificationBundle("ochstA", paras, client, Config{Url: ""}) 56 57 // when 58 err := bundle.UpdateNotificationEvent() 59 60 // then 61 assert.NoError(t, err) 62 63 event, err := client.GetMaintenanceEvent(FakeOrchestrationID) 64 assert.NoError(t, err) 65 assert.Equal(t, "1", event.Tenants[0].State) 66 assert.Equal(t, "2022-01-01T20:00:02Z", event.Tenants[0].StartDate) 67 } 68 69 func TestServiceProviderBundle_CancelNotificationEvent(t *testing.T) { 70 // given 71 paras := NotificationParams{ 72 OrchestrationID: FakeOrchestrationID, 73 } 74 75 client := NewFakeClient() 76 bundle := NewNotificationBundle("ochstA", paras, client, Config{Url: ""}) 77 78 // when 79 err := bundle.CancelNotificationEvent() 80 81 // then 82 assert.NoError(t, err) 83 84 event, err := client.GetMaintenanceEvent(FakeOrchestrationID) 85 assert.NoError(t, err) 86 assert.Equal(t, "3", event.Tenants[0].State) 87 }