add notification apis (#2066)

add alerting apis

add generic proxy
This commit is contained in:
zryfish
2020-05-13 21:50:26 +08:00
committed by GitHub
parent 1464ca197d
commit d358d9ab1a
6 changed files with 198 additions and 1 deletions

View File

@@ -0,0 +1,60 @@
package generic
import (
"github.com/emicklei/go-restful"
"github.com/google/go-cmp/cmp"
"net/http/httptest"
"net/url"
"testing"
)
var group = "test.kubesphere.io"
var version = "v1"
var scheme = "http"
func TestNewGenericProxy(t *testing.T) {
var testCases = []struct {
description string
endpoint string
query string
expected *url.URL
}{
{
description: "Endpoint with path",
endpoint: "http://awesome.kubesphere-system.svc:8080/api",
query: "/kapis/test.kubesphere.io/v1/foo/bar?id=1&time=whatever",
expected: &url.URL{
Scheme: scheme,
Host: "awesome.kubesphere-system.svc:8080",
Path: "/api/v1/foo/bar",
RawQuery: "id=1&time=whatever",
},
},
{
description: "Endpoint without path",
endpoint: "http://awesome.kubesphere-system.svc:8080",
query: "/kapis/test.kubesphere.io/v1/foo/bar?id=1&time=whatever",
expected: &url.URL{
Scheme: scheme,
Host: "awesome.kubesphere-system.svc:8080",
Path: "/v1/foo/bar",
RawQuery: "id=1&time=whatever",
},
},
}
for _, testCase := range testCases {
proxy, err := NewGenericProxy(testCase.endpoint, group, version)
if err != nil {
t.Error(err)
}
t.Run(testCase.description, func(t *testing.T) {
request := httptest.NewRequest("GET", testCase.query, nil)
u := proxy.makeURL(restful.NewRequest(request))
if diff := cmp.Diff(u, testCase.expected); len(diff) != 0 {
t.Errorf("%T differ (-got, +want): %s", testCase.expected, diff)
}
})
}
}