in testutils/fakekubeapi/fakekubeapi.go [188:223]
func (f *Server) processGet(url string, w http.ResponseWriter) {
glog.Infof("Processing Get request %s", url)
// TODO(alextc) Check URL - is it actually a get/list request for a Secret?
var response interface{}
switch {
case url == "/api/v1/namespaces":
response = f.namespaces
// Expect url to be of the following format: /api/v1/namespaces/default/secrets.
case strings.HasSuffix(url, "/secrets"):
urlParts := strings.Split(url, "/")
if len(urlParts) != 6 {
http.Error(w, fmt.Sprintf("unexpected format of url: %q, wanted len of 4, got %d, parts: %#v", url, len(urlParts), urlParts), http.StatusBadRequest)
return
}
s, ok := f.secrets[urlParts[4]]
if !ok {
http.Error(w, fmt.Sprintf("invalid test data, request for %q, but namespace %s was not provided", url, urlParts[4]), http.StatusNotFound)
return
}
response = corev1.SecretList{
Items: s,
}
f.recordSecretList(s)
default:
http.Error(w, fmt.Sprintf("Was not expecting call to %q", url), http.StatusNotFound)
return
}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(response); err != nil {
http.Error(w, fmt.Sprintf("failed to write response for request:%s, err: %v", url, err), http.StatusInternalServerError)
}
}