1package auroradns 2 3import ( 4 "fmt" 5 "net/http" 6 "net/http/httptest" 7) 8 9func setupTest() (*Client, *http.ServeMux, func()) { 10 apiHandler := http.NewServeMux() 11 server := httptest.NewServer(apiHandler) 12 13 client, err := NewClient(nil, WithBaseURL(server.URL)) 14 if err != nil { 15 panic(err) 16 } 17 18 return client, apiHandler, server.Close 19} 20 21func handleAPI(mux *http.ServeMux, pattern string, method string, next func(w http.ResponseWriter, r *http.Request)) { 22 mux.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) { 23 if r.Method != method { 24 http.Error(w, fmt.Sprintf("invalid method %s", r.Method), http.StatusMethodNotAllowed) 25 return 26 } 27 28 contentType := r.Header.Get(contentTypeHeader) 29 if contentType != contentTypeJSON { 30 http.Error(w, fmt.Sprintf("invalid Content-Type %s", contentType), http.StatusBadRequest) 31 return 32 } 33 34 if next != nil { 35 next(w, r) 36 } 37 }) 38} 39