github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/cbr/v3/policies/testing/fixtures.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 "github.com/opentelekomcloud/gophertelekomcloud/openstack/cbr/v3/policies" 9 th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" 10 fake "github.com/opentelekomcloud/gophertelekomcloud/testhelper/client" 11 ) 12 13 const ( 14 expectedRequest = ` 15 { 16 "policy" : { 17 "name" : "policy001", 18 "operation_definition" : { 19 "day_backups" : 0, 20 "month_backups" : 0, 21 "retention_duration_days" : 1, 22 "timezone" : "UTC+08:00", 23 "week_backups" : 0, 24 "year_backups" : 0 25 }, 26 "operation_type" : "backup", 27 "trigger" : { 28 "properties" : { 29 "pattern" : [ "FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYHOUR=14;BYMINUTE=00" ] 30 } 31 } 32 } 33 }` 34 expectedCreateResponse = ` 35 { 36 "policy" : { 37 "name" : "policy001", 38 "enabled" : true, 39 "trigger" : { 40 "properties" : { 41 "pattern" : [ "FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYHOUR=14;BYMINUTE=00" ], 42 "start_time" : "2019-05-08 06:57:05" 43 }, 44 "type" : "time", 45 "id" : "d67269a6-5369-42d7-8150-5254bd446328", 46 "name" : "default" 47 }, 48 "operation_definition" : { 49 "retention_duration_days" : 1, 50 "year_backups" : 0, 51 "day_backups" : 0, 52 "month_backups" : 0, 53 "week_backups" : 0, 54 "timezone" : "UTC+08:00" 55 }, 56 "operation_type" : "backup", 57 "id" : "cbb3ce6f-3332-4e7c-b98e-77290d8471ff" 58 } 59 }` 60 expectedUpdateResponse = ` 61 { 62 "policy" : { 63 "name" : "policy001", 64 "enabled" : true, 65 "trigger" : { 66 "properties" : { 67 "pattern" : [ "FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYHOUR=14;BYMINUTE=00" ], 68 "start_time" : "2019-05-08 06:57:05" 69 }, 70 "type" : "time", 71 "id" : "d67269a6-5369-42d7-8150-5254bd446328", 72 "name" : "default" 73 }, 74 "operation_definition" : { 75 "max_backups" : 0, 76 "year_backups" : 0, 77 "day_backups" : 0, 78 "month_backups" : 0, 79 "week_backups" : 0, 80 "timezone" : "UTC+08:00", 81 "retention_duration_days": 1 82 }, 83 "operation_type" : "backup", 84 "id" : "cbb3ce6f-3332-4e7c-b98e-77290d8471ff" 85 } 86 }` 87 ) 88 89 var ( 90 createOpts = policies.CreateOpts{ 91 Name: "policy001", 92 OperationDefinition: &policies.PolicyODCreate{ 93 DailyBackups: 0, 94 WeekBackups: 0, 95 YearBackups: 0, 96 MonthBackups: 0, 97 MaxBackups: 0, 98 RetentionDurationDays: 1, 99 Timezone: "UTC+08:00", 100 }, 101 OperationType: "backup", 102 Trigger: &policies.Trigger{ 103 Properties: policies.TriggerProperties{ 104 Pattern: []string{ 105 "FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYHOUR=14;BYMINUTE=00", 106 }, 107 }, 108 }, 109 } 110 111 expectedCreateResponseData = &policies.Policy{ 112 ID: "cbb3ce6f-3332-4e7c-b98e-77290d8471ff", 113 Name: "policy001", 114 Enabled: true, 115 OperationDefinition: &policies.PolicyODCreate{ 116 DailyBackups: 0, 117 WeekBackups: 0, 118 YearBackups: 0, 119 MonthBackups: 0, 120 MaxBackups: 0, 121 RetentionDurationDays: 1, 122 Timezone: "UTC+08:00", 123 }, 124 OperationType: "backup", 125 Trigger: &policies.PolicyTriggerResp{ 126 Properties: policies.PolicyTriggerPropertiesResp{ 127 Pattern: []string{"FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYHOUR=14;BYMINUTE=00"}, 128 StartTime: "2019-05-08 06:57:05", 129 }, 130 }, 131 } 132 updateEnabled = true 133 updateOpts = policies.UpdateOpts{ 134 Enabled: &updateEnabled, 135 Name: "policy001", 136 OperationDefinition: &policies.PolicyODCreate{ 137 DailyBackups: 0, 138 WeekBackups: 0, 139 YearBackups: 0, 140 MonthBackups: 0, 141 MaxBackups: 1, 142 RetentionDurationDays: 1, 143 Timezone: "UTC+08:00", 144 }, 145 Trigger: &policies.Trigger{ 146 Properties: policies.TriggerProperties{ 147 Pattern: []string{ 148 "FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYHOUR=14;BYMINUTE=00", 149 }, 150 }, 151 }, 152 } 153 ) 154 155 func handlePolicyCreation(t *testing.T) { 156 th.Mux.HandleFunc("/policies", func(w http.ResponseWriter, r *http.Request) { 157 th.TestMethod(t, r, "POST") 158 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 159 w.Header().Add("Content-Type", "application/json") 160 w.WriteHeader(http.StatusOK) 161 _, _ = fmt.Fprint(w, expectedCreateResponse) 162 }) 163 } 164 165 func handlePolicyDeletion(t *testing.T) { 166 th.Mux.HandleFunc("/policies/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) { 167 th.TestMethod(t, r, "DELETE") 168 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 169 w.Header().Add("Content-Type", "application/json") 170 w.WriteHeader(http.StatusNoContent) 171 }) 172 } 173 174 func handlePolicyUpdate(t *testing.T) { 175 th.Mux.HandleFunc("/policies/cbb3ce6f-3332-4e7c-b98e-77290d8471ff", func(w http.ResponseWriter, r *http.Request) { 176 th.TestMethod(t, r, "PUT") 177 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 178 w.Header().Add("Content-Type", "application/json") 179 w.WriteHeader(http.StatusOK) 180 _, _ = fmt.Fprint(w, expectedUpdateResponse) 181 }) 182 }