@@ -19,7 +19,6 @@ import (
1919 "io"
2020 "net/http"
2121 "net/http/httptest"
22- "regexp"
2322 "testing"
2423
2524 apiv1 "github.com/google/cloud-android-orchestration/api/v1"
@@ -28,19 +27,17 @@ import (
2827)
2928
3029func TestDeleteHosts (t * testing.T ) {
31- existingNames := map [string ]struct {}{"bar" : {}, "baz" : {}}
3230 ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
33- if r .Method != "DELETE" {
34- panic ("unexpected method: " + r .Method )
35- }
36- re := regexp .MustCompile (`^/hosts/(.*)$` )
37- matches := re .FindStringSubmatch (r .URL .Path )
38- if len (matches ) != 2 {
39- panic ("unexpected path: " + r .URL .Path )
40- }
41- if _ , ok := existingNames [matches [1 ]]; ok {
42- writeOK (w , "" )
43- } else {
31+ switch ep := r .Method + " " + r .URL .Path ; ep {
32+ case "DELETE /hosts/bar" :
33+ writeOK (w , apiv1.Operation {Name : "deletingbar" })
34+ case "DELETE /hosts/baz" :
35+ writeOK (w , apiv1.Operation {Name : "deletingbaz" })
36+ case "POST /operations/deletingbar/:wait" :
37+ writeOK (w , apiv1.HostInstance {Name : "bar" })
38+ case "POST /operations/deletingbaz/:wait" :
39+ writeOK (w , apiv1.HostInstance {Name : "baz" })
40+ default :
4441 writeErr (w , 404 )
4542 }
4643 }))
0 commit comments