mirror of
https://github.com/kubernetes-sigs/prometheus-adapter.git
synced 2026-04-07 10:17:51 +00:00
Add vendor folder to git
This commit is contained in:
parent
66cf5eaafb
commit
183585f56f
6916 changed files with 2629581 additions and 1 deletions
56
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/errors_test.go
generated
vendored
Normal file
56
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/errors_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
package runtime_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
)
|
||||
|
||||
func TestDefaultHTTPError(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
for _, spec := range []struct {
|
||||
err error
|
||||
status int
|
||||
msg string
|
||||
}{
|
||||
{
|
||||
err: fmt.Errorf("example error"),
|
||||
status: http.StatusInternalServerError,
|
||||
msg: "example error",
|
||||
},
|
||||
{
|
||||
err: grpc.Errorf(codes.NotFound, "no such resource"),
|
||||
status: http.StatusNotFound,
|
||||
msg: "no such resource",
|
||||
},
|
||||
} {
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("", "", nil) // Pass in an empty request to match the signature
|
||||
runtime.DefaultHTTPError(ctx, &runtime.JSONBuiltin{}, w, req, spec.err)
|
||||
|
||||
if got, want := w.Header().Get("Content-Type"), "application/json"; got != want {
|
||||
t.Errorf(`w.Header().Get("Content-Type") = %q; want %q; on spec.err=%v`, got, want, spec.err)
|
||||
}
|
||||
if got, want := w.Code, spec.status; got != want {
|
||||
t.Errorf("w.Code = %d; want %d", got, want)
|
||||
}
|
||||
|
||||
body := make(map[string]interface{})
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &body); err != nil {
|
||||
t.Errorf("json.Unmarshal(%q, &body) failed with %v; want success", w.Body.Bytes(), err)
|
||||
continue
|
||||
}
|
||||
if got, want := body["error"].(string), spec.msg; !strings.Contains(got, want) {
|
||||
t.Errorf(`body["error"] = %q; want %q; on spec.err=%v`, got, want, spec.err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue