github.com/sap/cf-mta-plugin@v2.6.3+incompatible/clients/restclient/http_rest_client_test.go (about) 1 package restclient 2 3 // Add test case about the configuration entries 4 // import ( 5 // "context" 6 // "encoding/xml" 7 // "net/http" 8 // "net/http/httptest" 9 // "net/url" 10 // "testing" 11 // 12 // "github.com/cloudfoundry-incubator/multiapps-cli-plugin/clients/models" 13 // "github.com/cloudfoundry-incubator/multiapps-cli-plugin/clients/restclient/operations" 14 // "github.com/cloudfoundry-incubator/multiapps-cli-plugin/clients/testutil" 15 // "github.com/go-openapi/runtime/client" 16 // "github.com/go-openapi/strfmt" 17 // "github.com/stretchr/testify/assert" 18 // ) 19 // 20 // const xmlHeader = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>` 21 // 22 // const operationsPayload = xmlHeader + ` 23 // <ongoing-operations>` + 24 // operationElement + ` 25 // </ongoing-operations>` 26 // 27 // const activeOperationsPayload = xmlHeader + ` 28 // <ongoing-operations>` + 29 // operationElement + 30 // activeElement + ` 31 // </ongoing-operations>` 32 // 33 // const operationPayload = xmlHeader + operationElement 34 // 35 // const operationElement = ` 36 // <ongoing-operation> 37 // <process-id>1</process-id> 38 // <process-type>deploy</process-type> 39 // <started-at>2016-03-04T14:23:24.521Z[Etc/UTC]</started-at> 40 // <space-id>5bea6497-6d70-4a31-9ad2-1ac64a520f8f</space-id> 41 // <user>admin</user> 42 // <state>SLP_TASK_STATE_ERROR</state> 43 // <acquired-lock>false</acquired-lock> 44 // </ongoing-operation>` 45 // 46 // const activeElement = ` 47 // <ongoing-operation> 48 // <process-id>2</process-id> 49 // <process-type>deploy</process-type> 50 // <started-at>2016-03-04T14:23:24.521Z[Etc/UTC]</started-at> 51 // <space-id>5bea6497-6d70-4a31-9ad2-1ac64a520f8f</space-id> 52 // <user>admin</user> 53 // <state>SLP_TASK_STATE_RUNNING</state> 54 // <acquired-lock>false</acquired-lock> 55 // </ongoing-operation>` 56 // 57 // var operationsResult = models.Operations{ 58 // XMLName: xml.Name{Local: "ongoing-operations"}, 59 // Operations: []*models.Operation{&operationResult}, 60 // } 61 // 62 // var mixedOperationsResult = models.Operations{ 63 // XMLName: xml.Name{Local: "ongoing-operations"}, 64 // Operations: []*models.Operation{&operationResult, &activeOperationResult}, 65 // } 66 // 67 // var operationResult = models.Operation{ 68 // XMLName: xml.Name{Local: "ongoing-operation"}, 69 // ProcessID: strptr("1"), 70 // ProcessType: models.ProcessType("deploy"), 71 // StartedAt: strptr("2016-03-04T14:23:24.521Z[Etc/UTC]"), 72 // SpaceID: strptr("5bea6497-6d70-4a31-9ad2-1ac64a520f8f"), 73 // User: strptr("admin"), 74 // State: models.SlpTaskStateEnum("SLP_TASK_STATE_ERROR"), 75 // AcquiredLock: boolptr(false), 76 // } 77 // 78 // var activeOperationResult = models.Operation{ 79 // XMLName: xml.Name{Local: "ongoing-operation"}, 80 // ProcessID: strptr("2"), 81 // ProcessType: models.ProcessType("deploy"), 82 // StartedAt: strptr("2016-03-04T14:23:24.521Z[Etc/UTC]"), 83 // SpaceID: strptr("5bea6497-6d70-4a31-9ad2-1ac64a520f8f"), 84 // User: strptr("admin"), 85 // State: models.SlpTaskStateEnum("SLP_TASK_STATE_RUNNING"), 86 // AcquiredLock: boolptr(false), 87 // } 88 // 89 // const componentsPayload = xmlHeader + ` 90 // <components> 91 // <mtas>` + 92 // mtaElement + ` 93 // </mtas> 94 // <standaloneApps> 95 // <standaloneApp>deploy-service</standaloneApp> 96 // </standaloneApps> 97 // </components>` 98 // 99 // const mtaPayload = xmlHeader + mtaElement 100 // 101 // const mtaElement = ` 102 // <mta> 103 // <metadata> 104 // <id>org.cloudfoundry.samples.music</id> 105 // <version>1.0</version> 106 // </metadata> 107 // <modules> 108 // <module> 109 // <moduleName>spring-music</moduleName> 110 // <appName>spring-music</appName> 111 // <services> 112 // <service>postgresql</service> 113 // </services> 114 // <providedDependencies> 115 // <providedDependency>spring-music</providedDependency> 116 // </providedDependencies> 117 // </module> 118 // </modules> 119 // <services> 120 // <service>postgresql</service> 121 // </services> 122 // </mta>` 123 // 124 // var componentsResult = models.Components{ 125 // XMLName: xml.Name{Local: "components"}, 126 // Mtas: models.ComponentsMtas{ 127 // Mtas: []*models.Mta{&mtaResult}, 128 // }, 129 // StandaloneApps: models.ComponentsStandaloneApps{ 130 // StandaloneApps: []string{"deploy-service"}, 131 // }, 132 // } 133 // 134 // var mtaResult = models.Mta{ 135 // XMLName: xml.Name{Local: "mta"}, 136 // Metadata: &models.MtaMetadata{ 137 // ID: strptr("org.cloudfoundry.samples.music"), 138 // Version: strptr("1.0"), 139 // }, 140 // Modules: models.MtaModules{ 141 // Modules: []*models.MtaModulesItems0{ 142 // &models.MtaModulesItems0{ 143 // ModuleName: strptr("spring-music"), 144 // AppName: strptr("spring-music"), 145 // Services: models.MtaModulesItems0Services{ 146 // Services: []string{"postgresql"}, 147 // }, 148 // ProvidedDependencies: models.MtaModulesItems0ProvidedDependencies{ 149 // ProvidedDependencies: []string{"spring-music"}, 150 // }, 151 // }, 152 // }, 153 // }, 154 // Services: models.MtaServices{ 155 // Services: []string{"postgresql"}, 156 // }, 157 // } 158 // 159 // func TestGetOperations(t *testing.T) { 160 // server := testutil.NewGetXMLOKServer("/operations", []byte(operationsPayload)) 161 // defer server.Close() 162 // client := newClient(server, nil) 163 // params := &operations.GetOperationsParams{ 164 // Context: context.TODO(), 165 // } 166 // res, err := client.Operations.GetOperations(params, nil) 167 // if assert.NoError(t, err) { 168 // testutil.CheckSuccess(t, operationsResult, res.Payload) 169 // } 170 // } 171 // 172 // func TestGetOperationsWithLastOperationCount(t *testing.T) { 173 // server := testutil.NewGetXMLOKServer("/operations", []byte(operationsPayload)) 174 // defer server.Close() 175 // client := newClient(server, nil) 176 // params := &operations.GetOperationsParams{ 177 // Context: context.TODO(), 178 // Last: strptr("1"), 179 // } 180 // res, err := client.Operations.GetOperations(params, nil) 181 // if assert.NoError(t, err) { 182 // testutil.CheckSuccess(t, operationsResult, res.Payload) 183 // } 184 // } 185 // 186 // func TestGetOperationsWithMixedOperationsRequested(t *testing.T) { 187 // server := testutil.NewGetXMLOKServer("/operations", []byte(activeOperationsPayload)) 188 // defer server.Close() 189 // client := newClient(server, nil) 190 // params := &operations.GetOperationsParams{ 191 // Context: context.TODO(), 192 // Status: []string{"SLP_TASK_STATE_RUNNING", "SLP_TASK_STATE_ERROR"}, 193 // } 194 // res, err := client.Operations.GetOperations(params, nil) 195 // if assert.NoError(t, err) { 196 // testutil.CheckSuccess(t, mixedOperationsResult, res.Payload) 197 // } 198 // } 199 // 200 // func TestGetOperation(t *testing.T) { 201 // server := testutil.NewGetXMLOKServer("/operations/1", []byte(operationPayload)) 202 // defer server.Close() 203 // client := newClient(server, nil) 204 // params := &operations.GetOperationParams{ 205 // Context: context.TODO(), 206 // ProcessID: "1", 207 // } 208 // res, err := client.Operations.GetOperation(params, nil) 209 // if assert.NoError(t, err) { 210 // testutil.CheckSuccess(t, operationResult, *res.Payload) 211 // } 212 // } 213 // 214 // func TestGetComponents(t *testing.T) { 215 // server := testutil.NewGetXMLOKServer("/components", []byte(componentsPayload)) 216 // defer server.Close() 217 // client := newClient(server, nil) 218 // params := &operations.GetComponentsParams{ 219 // Context: context.TODO(), 220 // } 221 // res, err := client.Operations.GetComponents(params, nil) 222 // if assert.NoError(t, err) { 223 // testutil.CheckSuccess(t, &componentsResult, res.Payload) 224 // } 225 // } 226 // 227 // func TestGetMta(t *testing.T) { 228 // server := testutil.NewGetXMLOKServer("/components/org.cloudfoundry.samples.music", []byte(mtaPayload)) 229 // defer server.Close() 230 // client := newClient(server, nil) 231 // params := &operations.GetMtaParams{ 232 // Context: context.TODO(), 233 // MtaID: "org.cloudfoundry.samples.music", 234 // } 235 // res, err := client.Operations.GetMta(params, nil) 236 // if assert.NoError(t, err) { 237 // testutil.CheckSuccess(t, &mtaResult, res.Payload) 238 // } 239 // } 240 // 241 // func newClient(server *httptest.Server, rt http.RoundTripper) *Rest { 242 // hu, _ := url.Parse(server.URL) 243 // runtime := client.New(hu.Host, "/", "/", []string{"http"}) 244 // if rt != nil { 245 // runtime.Transport = rt 246 // } 247 // return New(runtime, strfmt.Default) 248 // } 249 // 250 // func strptr(s string) *string { 251 // return &s 252 // } 253 // 254 // func boolptr(b bool) *bool { 255 // return &b 256 // }