github.com/gophercloud/gophercloud@v1.11.0/openstack/sharedfilesystems/v2/securityservices/testing/fixtures_test.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 th "github.com/gophercloud/gophercloud/testhelper" 9 fake "github.com/gophercloud/gophercloud/testhelper/client" 10 ) 11 12 func MockCreateResponse(t *testing.T) { 13 th.Mux.HandleFunc("/security-services", func(w http.ResponseWriter, r *http.Request) { 14 th.TestMethod(t, r, "POST") 15 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 16 th.TestHeader(t, r, "Content-Type", "application/json") 17 th.TestHeader(t, r, "Accept", "application/json") 18 th.TestJSONRequest(t, r, ` 19 { 20 "security_service": { 21 "description": "Creating my first Security Service", 22 "dns_ip": "10.0.0.0/24", 23 "user": "demo", 24 "password": "***", 25 "type": "kerberos", 26 "name": "SecServ1" 27 } 28 }`) 29 30 w.Header().Add("Content-Type", "application/json") 31 w.WriteHeader(http.StatusOK) 32 33 fmt.Fprintf(w, ` 34 { 35 "security_service": { 36 "status": "new", 37 "domain": null, 38 "project_id": "16e1ab15c35a457e9c2b2aa189f544e1", 39 "name": "SecServ1", 40 "created_at": "2015-09-07T12:19:10.695211", 41 "updated_at": null, 42 "server": null, 43 "dns_ip": "10.0.0.0/24", 44 "user": "demo", 45 "password": "supersecret", 46 "type": "kerberos", 47 "id": "3c829734-0679-4c17-9637-801da48c0d5f", 48 "description": "Creating my first Security Service" 49 } 50 }`) 51 }) 52 } 53 54 func MockDeleteResponse(t *testing.T) { 55 th.Mux.HandleFunc("/security-services/securityServiceID", func(w http.ResponseWriter, r *http.Request) { 56 th.TestMethod(t, r, "DELETE") 57 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 58 w.WriteHeader(http.StatusAccepted) 59 }) 60 } 61 62 func MockListResponse(t *testing.T) { 63 th.Mux.HandleFunc("/security-services/detail", func(w http.ResponseWriter, r *http.Request) { 64 th.TestMethod(t, r, "GET") 65 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 66 67 w.Header().Add("Content-Type", "application/json") 68 w.WriteHeader(http.StatusOK) 69 70 fmt.Fprintf(w, ` 71 { 72 "security_services": [ 73 { 74 "status": "new", 75 "domain": null, 76 "project_id": "16e1ab15c35a457e9c2b2aa189f544e1", 77 "name": "SecServ1", 78 "created_at": "2015-09-07T12:19:10.000000", 79 "description": "Creating my first Security Service", 80 "updated_at": null, 81 "server": null, 82 "dns_ip": "10.0.0.0/24", 83 "user": "demo", 84 "password": "supersecret", 85 "type": "kerberos", 86 "id": "3c829734-0679-4c17-9637-801da48c0d5f" 87 }, 88 { 89 "status": "new", 90 "domain": null, 91 "project_id": "16e1ab15c35a457e9c2b2aa189f544e1", 92 "name": "SecServ2", 93 "created_at": "2015-09-07T12:25:03.000000", 94 "description": "Creating my second Security Service", 95 "updated_at": null, 96 "server": null, 97 "dns_ip": "10.0.0.0/24", 98 "user": null, 99 "password": null, 100 "type": "ldap", 101 "id": "5a1d3a12-34a7-4087-8983-50e9ed03509a" 102 } 103 ] 104 }`) 105 }) 106 } 107 108 func MockFilteredListResponse(t *testing.T) { 109 th.Mux.HandleFunc("/security-services/detail", func(w http.ResponseWriter, r *http.Request) { 110 th.TestMethod(t, r, "GET") 111 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 112 113 w.Header().Add("Content-Type", "application/json") 114 w.WriteHeader(http.StatusOK) 115 116 fmt.Fprintf(w, ` 117 { 118 "security_services": [ 119 { 120 "status": "new", 121 "domain": null, 122 "project_id": "16e1ab15c35a457e9c2b2aa189f544e1", 123 "name": "SecServ1", 124 "created_at": "2015-09-07T12:19:10.000000", 125 "description": "Creating my first Security Service", 126 "updated_at": null, 127 "server": null, 128 "dns_ip": "10.0.0.0/24", 129 "user": "demo", 130 "password": "supersecret", 131 "type": "kerberos", 132 "id": "3c829734-0679-4c17-9637-801da48c0d5f" 133 } 134 ] 135 }`) 136 }) 137 } 138 139 func MockGetResponse(t *testing.T) { 140 th.Mux.HandleFunc("/security-services/3c829734-0679-4c17-9637-801da48c0d5f", func(w http.ResponseWriter, r *http.Request) { 141 th.TestMethod(t, r, "GET") 142 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 143 144 w.Header().Add("Content-Type", "application/json") 145 w.WriteHeader(http.StatusOK) 146 fmt.Fprintf(w, ` 147 { 148 "security_service": { 149 "status": "new", 150 "domain": null, 151 "project_id": "16e1ab15c35a457e9c2b2aa189f544e1", 152 "name": "SecServ1", 153 "created_at": "2015-09-07T12:19:10.000000", 154 "updated_at": null, 155 "server": null, 156 "dns_ip": "10.0.0.0/24", 157 "user": "demo", 158 "password": "supersecret", 159 "type": "kerberos", 160 "id": "3c829734-0679-4c17-9637-801da48c0d5f", 161 "description": "Creating my first Security Service" 162 } 163 }`) 164 }) 165 } 166 167 func MockUpdateResponse(t *testing.T) { 168 th.Mux.HandleFunc("/security-services/securityServiceID", func(w http.ResponseWriter, r *http.Request) { 169 th.TestMethod(t, r, "PUT") 170 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 171 w.WriteHeader(http.StatusOK) 172 fmt.Fprintf(w, ` 173 { 174 "security_service": { 175 "status": "new", 176 "domain": null, 177 "project_id": "16e1ab15c35a457e9c2b2aa189f544e1", 178 "name": "SecServ2", 179 "created_at": "2015-09-07T12:19:10.000000", 180 "updated_at": "2015-09-07T12:20:10.000000", 181 "server": null, 182 "dns_ip": "10.0.0.0/24", 183 "user": "demo", 184 "password": "supersecret", 185 "type": "kerberos", 186 "id": "securityServiceID", 187 "description": "Updating my first Security Service" 188 } 189 } 190 `) 191 }) 192 }