github.com/gophercloud/gophercloud@v1.11.0/openstack/identity/v3/extensions/ec2credentials/testing/fixtures_test.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 "github.com/gophercloud/gophercloud/openstack/identity/v3/extensions/ec2credentials" 9 th "github.com/gophercloud/gophercloud/testhelper" 10 "github.com/gophercloud/gophercloud/testhelper/client" 11 ) 12 13 const userID = "2844b2a08be147a08ef58317d6471f1f" 14 const credentialID = "f741662395b249c9b8acdebf1722c5ae" 15 16 // ListOutput provides a single page of EC2Credential results. 17 const ListOutput = ` 18 { 19 "credentials": [ 20 { 21 "user_id": "2844b2a08be147a08ef58317d6471f1f", 22 "links": { 23 "self": "http://identity:5000/v3/users/2844b2a08be147a08ef58317d6471f1f/credentials/OS-EC2/f741662395b249c9b8acdebf1722c5ae" 24 }, 25 "tenant_id": "6238dee2fec940a6bf31e49e9faf995a", 26 "access": "f741662395b249c9b8acdebf1722c5ae", 27 "secret": "6a61eb0296034c89b49cc51dde9b40aa", 28 "trust_id": null 29 }, 30 { 31 "user_id": "2844b2a08be147a08ef58317d6471f1f", 32 "links": { 33 "self": "http://identity:5000/v3/users/2844b2a08be147a08ef58317d6471f1f/credentials/OS-EC2/ad6fc85fc2df49e6b5c23d5b5bdff980" 34 }, 35 "tenant_id": "6238dee2fec940a6bf31e49e9faf995a", 36 "access": "ad6fc85fc2df49e6b5c23d5b5bdff980", 37 "secret": "eb233f680a204097ac329ebe8dba6d32", 38 "trust_id": null 39 } 40 ], 41 "links": { 42 "self": "http://identity:5000/v3/users/2844b2a08be147a08ef58317d6471f1f/credentials/OS-EC2", 43 "previous": null, 44 "next": null 45 } 46 } 47 ` 48 49 // GetOutput provides a Get result. 50 const GetOutput = ` 51 { 52 "credential": { 53 "user_id": "2844b2a08be147a08ef58317d6471f1f", 54 "links": { 55 "self": "http://identity:5000/v3/users/2844b2a08be147a08ef58317d6471f1f/credentials/OS-EC2/f741662395b249c9b8acdebf1722c5ae" 56 }, 57 "tenant_id": "6238dee2fec940a6bf31e49e9faf995a", 58 "access": "f741662395b249c9b8acdebf1722c5ae", 59 "secret": "6a61eb0296034c89b49cc51dde9b40aa", 60 "trust_id": null 61 } 62 } 63 ` 64 65 // CreateRequest provides the input to a Create request. 66 const CreateRequest = ` 67 { 68 "tenant_id": "6238dee2fec940a6bf31e49e9faf995a" 69 } 70 ` 71 72 const CreateResponse = ` 73 { 74 "credential": { 75 "user_id": "2844b2a08be147a08ef58317d6471f1f", 76 "links": { 77 "self": "http://identity:5000/v3/users/2844b2a08be147a08ef58317d6471f1f/credentials/OS-EC2/f741662395b249c9b8acdebf1722c5ae" 78 }, 79 "tenant_id": "6238dee2fec940a6bf31e49e9faf995a", 80 "access": "f741662395b249c9b8acdebf1722c5ae", 81 "secret": "6a61eb0296034c89b49cc51dde9b40aa", 82 "trust_id": null 83 } 84 } 85 ` 86 87 var EC2Credential = ec2credentials.Credential{ 88 UserID: "2844b2a08be147a08ef58317d6471f1f", 89 TenantID: "6238dee2fec940a6bf31e49e9faf995a", 90 Access: "f741662395b249c9b8acdebf1722c5ae", 91 Secret: "6a61eb0296034c89b49cc51dde9b40aa", 92 TrustID: "", 93 Links: map[string]interface{}{ 94 "self": "http://identity:5000/v3/users/2844b2a08be147a08ef58317d6471f1f/credentials/OS-EC2/f741662395b249c9b8acdebf1722c5ae", 95 }, 96 } 97 98 var SecondEC2Credential = ec2credentials.Credential{ 99 UserID: "2844b2a08be147a08ef58317d6471f1f", 100 TenantID: "6238dee2fec940a6bf31e49e9faf995a", 101 Access: "ad6fc85fc2df49e6b5c23d5b5bdff980", 102 Secret: "eb233f680a204097ac329ebe8dba6d32", 103 TrustID: "", 104 Links: map[string]interface{}{ 105 "self": "http://identity:5000/v3/users/2844b2a08be147a08ef58317d6471f1f/credentials/OS-EC2/ad6fc85fc2df49e6b5c23d5b5bdff980", 106 }, 107 } 108 109 // ExpectedEC2CredentialsSlice is the slice of application credentials expected to be returned from ListOutput. 110 var ExpectedEC2CredentialsSlice = []ec2credentials.Credential{EC2Credential, SecondEC2Credential} 111 112 // HandleListEC2CredentialsSuccessfully creates an HTTP handler at `/users` on the 113 // test handler mux that responds with a list of two applicationcredentials. 114 func HandleListEC2CredentialsSuccessfully(t *testing.T) { 115 th.Mux.HandleFunc("/users/2844b2a08be147a08ef58317d6471f1f/credentials/OS-EC2", func(w http.ResponseWriter, r *http.Request) { 116 th.TestMethod(t, r, "GET") 117 th.TestHeader(t, r, "Accept", "application/json") 118 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 119 120 w.Header().Set("Content-Type", "application/json") 121 w.WriteHeader(http.StatusOK) 122 fmt.Fprintf(w, ListOutput) 123 }) 124 } 125 126 // HandleGetEC2CredentialSuccessfully creates an HTTP handler at `/users` on the 127 // test handler mux that responds with a single application credential. 128 func HandleGetEC2CredentialSuccessfully(t *testing.T) { 129 th.Mux.HandleFunc("/users/2844b2a08be147a08ef58317d6471f1f/credentials/OS-EC2/f741662395b249c9b8acdebf1722c5ae", func(w http.ResponseWriter, r *http.Request) { 130 th.TestMethod(t, r, "GET") 131 th.TestHeader(t, r, "Accept", "application/json") 132 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 133 134 w.Header().Set("Content-Type", "application/json") 135 w.WriteHeader(http.StatusOK) 136 fmt.Fprintf(w, GetOutput) 137 }) 138 } 139 140 // HandleCreateEC2CredentialSuccessfully creates an HTTP handler at `/users` on the 141 // test handler mux that tests application credential creation. 142 func HandleCreateEC2CredentialSuccessfully(t *testing.T) { 143 th.Mux.HandleFunc("/users/2844b2a08be147a08ef58317d6471f1f/credentials/OS-EC2", func(w http.ResponseWriter, r *http.Request) { 144 th.TestMethod(t, r, "POST") 145 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 146 th.TestJSONRequest(t, r, CreateRequest) 147 148 w.WriteHeader(http.StatusCreated) 149 fmt.Fprintf(w, CreateResponse) 150 }) 151 } 152 153 // HandleDeleteEC2CredentialSuccessfully creates an HTTP handler at `/users` on the 154 // test handler mux that tests application credential deletion. 155 func HandleDeleteEC2CredentialSuccessfully(t *testing.T) { 156 th.Mux.HandleFunc("/users/2844b2a08be147a08ef58317d6471f1f/credentials/OS-EC2/f741662395b249c9b8acdebf1722c5ae", func(w http.ResponseWriter, r *http.Request) { 157 th.TestMethod(t, r, "DELETE") 158 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 159 160 w.WriteHeader(http.StatusNoContent) 161 }) 162 }