mirror of
https://github.com/kubernetes-sigs/prometheus-adapter.git
synced 2026-04-07 02:07:58 +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
13
vendor/github.com/coreos/pkg/httputil/README.md
generated
vendored
Normal file
13
vendor/github.com/coreos/pkg/httputil/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
httputil
|
||||
====
|
||||
|
||||
Common code for dealing with HTTP.
|
||||
|
||||
Includes:
|
||||
|
||||
* Code for returning JSON responses.
|
||||
|
||||
### Documentation
|
||||
|
||||
Visit the docs on [gopkgdoc](http://godoc.org/github.com/coreos/pkg/httputil)
|
||||
|
||||
21
vendor/github.com/coreos/pkg/httputil/cookie.go
generated
vendored
Normal file
21
vendor/github.com/coreos/pkg/httputil/cookie.go
generated
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package httputil
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
// DeleteCookies effectively deletes all named cookies
|
||||
// by wiping all data and setting to expire immediately.
|
||||
func DeleteCookies(w http.ResponseWriter, cookieNames ...string) {
|
||||
for _, n := range cookieNames {
|
||||
c := &http.Cookie{
|
||||
Name: n,
|
||||
Value: "",
|
||||
Path: "/",
|
||||
MaxAge: -1,
|
||||
Expires: time.Time{},
|
||||
}
|
||||
http.SetCookie(w, c)
|
||||
}
|
||||
}
|
||||
51
vendor/github.com/coreos/pkg/httputil/cookie_test.go
generated
vendored
Normal file
51
vendor/github.com/coreos/pkg/httputil/cookie_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
package httputil
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestDeleteCookies(t *testing.T) {
|
||||
tests := []struct {
|
||||
// cookie names to delete
|
||||
n []string
|
||||
}{
|
||||
// single
|
||||
{
|
||||
n: []string{"foo"},
|
||||
},
|
||||
// multiple
|
||||
{
|
||||
n: []string{"foo", "bar"},
|
||||
},
|
||||
}
|
||||
|
||||
for i, tt := range tests {
|
||||
w := httptest.NewRecorder()
|
||||
DeleteCookies(w, tt.n...)
|
||||
resp := &http.Response{}
|
||||
resp.Header = w.Header()
|
||||
cks := resp.Cookies()
|
||||
|
||||
if len(cks) != len(tt.n) {
|
||||
t.Errorf("case %d: unexpected number of cookies, want: %d, got: %d", i, len(tt.n), len(cks))
|
||||
}
|
||||
|
||||
for _, c := range cks {
|
||||
if c.Value != "" {
|
||||
t.Errorf("case %d: unexpected cookie value, want: %q, got: %q", i, "", c.Value)
|
||||
}
|
||||
if c.Path != "/" {
|
||||
t.Errorf("case %d: unexpected cookie path, want: %q, got: %q", i, "/", c.Path)
|
||||
}
|
||||
if c.MaxAge != -1 {
|
||||
t.Errorf("case %d: unexpected cookie max-age, want: %q, got: %q", i, -1, c.MaxAge)
|
||||
}
|
||||
if !c.Expires.IsZero() {
|
||||
t.Errorf("case %d: unexpected cookie expires, want: %q, got: %q", i, time.Time{}, c.MaxAge)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
27
vendor/github.com/coreos/pkg/httputil/json.go
generated
vendored
Normal file
27
vendor/github.com/coreos/pkg/httputil/json.go
generated
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package httputil
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
JSONContentType = "application/json"
|
||||
)
|
||||
|
||||
func WriteJSONResponse(w http.ResponseWriter, code int, resp interface{}) error {
|
||||
enc, err := json.Marshal(resp)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return err
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", JSONContentType)
|
||||
w.WriteHeader(code)
|
||||
|
||||
_, err = w.Write(enc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
56
vendor/github.com/coreos/pkg/httputil/json_test.go
generated
vendored
Normal file
56
vendor/github.com/coreos/pkg/httputil/json_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
package httputil
|
||||
|
||||
import (
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestWriteJSONResponse(t *testing.T) {
|
||||
for i, test := range []struct {
|
||||
code int
|
||||
resp interface{}
|
||||
expectedJSON string
|
||||
expectErr bool
|
||||
}{
|
||||
{
|
||||
200,
|
||||
struct {
|
||||
A string
|
||||
B string
|
||||
}{A: "foo", B: "bar"},
|
||||
`{"A":"foo","B":"bar"}`,
|
||||
false,
|
||||
},
|
||||
{
|
||||
500,
|
||||
// Something that json.Marshal cannot serialize.
|
||||
make(chan int),
|
||||
"",
|
||||
true,
|
||||
},
|
||||
} {
|
||||
w := httptest.NewRecorder()
|
||||
err := WriteJSONResponse(w, test.code, test.resp)
|
||||
|
||||
if w.Code != test.code {
|
||||
t.Errorf("case %d: w.code == %v, want %v", i, w.Code, test.code)
|
||||
}
|
||||
|
||||
if (err != nil) != test.expectErr {
|
||||
t.Errorf("case %d: (err != nil) == %v, want %v. err: %v", i, err != nil, test.expectErr, err)
|
||||
}
|
||||
|
||||
if string(w.Body.Bytes()) != test.expectedJSON {
|
||||
t.Errorf("case %d: w.Body.Bytes()) == %q, want %q", i,
|
||||
string(w.Body.Bytes()), test.expectedJSON)
|
||||
}
|
||||
|
||||
if !test.expectErr {
|
||||
contentType := w.Header()["Content-Type"][0]
|
||||
if contentType != JSONContentType {
|
||||
t.Errorf("case %d: contentType == %v, want %v", i, contentType, JSONContentType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue