github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/notification/fake_client.go (about) 1 package notification 2 3 import "fmt" 4 5 const ( 6 FakeOrchestrationID = "ASKHGK-SAKJHTJ-ALKJSHT-HUZIUOP" 7 FakeInstanceID = "WEAJKG-INSTANCE-1" 8 ) 9 10 type Tenants struct { 11 InstanceID string 12 StartDate string 13 EndDate string 14 State string 15 } 16 17 type MaintenanceEvent struct { 18 OrchestrationID string 19 EventType string 20 Tenants []Tenants 21 } 22 23 type FakeClient struct { 24 maintenanceEvent []*MaintenanceEvent 25 } 26 27 func NewFakeClient() *FakeClient { 28 return &FakeClient{ 29 maintenanceEvent: []*MaintenanceEvent{ 30 { 31 OrchestrationID: FakeOrchestrationID, 32 EventType: "test", 33 Tenants: []Tenants{ 34 { 35 InstanceID: "test", 36 StartDate: "test", 37 EndDate: "test", 38 State: "test", 39 }, 40 }, 41 }, 42 }, 43 } 44 } 45 46 func (f *FakeClient) CreateEvent(request CreateEventRequest) error { 47 f.maintenanceEvent = append(f.maintenanceEvent, &MaintenanceEvent{ 48 OrchestrationID: request.OrchestrationID, 49 EventType: request.EventType, 50 Tenants: []Tenants{ 51 { 52 InstanceID: request.Tenants[0].InstanceID, 53 StartDate: request.Tenants[0].StartDate, 54 }, 55 }, 56 }) 57 58 return nil 59 } 60 61 func (f *FakeClient) UpdateEvent(request UpdateEventRequest) error { 62 maintenanceEvent, err := f.GetMaintenanceEvent(request.OrchestrationID) 63 if err != nil { 64 return err 65 } 66 67 maintenanceEvent.Tenants[0].StartDate = request.Tenants[0].StartDate 68 maintenanceEvent.Tenants[0].State = request.Tenants[0].State 69 70 return nil 71 } 72 73 func (f *FakeClient) CancelEvent(request CancelEventRequest) error { 74 maintenanceEvent, err := f.GetMaintenanceEvent(request.OrchestrationID) 75 if err != nil { 76 return err 77 } 78 79 maintenanceEvent.Tenants[0].State = CancelledMaintenanceState 80 return nil 81 } 82 83 func (f *FakeClient) GetMaintenanceEvent(id string) (*MaintenanceEvent, error) { 84 for _, event := range f.maintenanceEvent { 85 if event.OrchestrationID == id { 86 return event, nil 87 } 88 } 89 90 return nil, fmt.Errorf("cannot find MaintenanceEvent with OrchestrationID: %s", id) 91 }