2 Star 0 Fork 0

mirrors_airbnb/k8s-webhook-handler

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
handler_test.go 1.44 KB
一键复制 编辑 原始数据 按行查看 历史
Johannes 'fish' Ziemke 提交于 2019-12-30 12:00 . Remove unused variables
package handler
import (
"context"
"fmt"
"io/ioutil"
"net/http/httptest"
"os"
"testing"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/metrics/statsd"
"k8s.io/apimachinery/pkg/runtime"
)
type mockKubernetesClient struct {
obj runtime.Object
namespace string
}
func (k *mockKubernetesClient) Apply(obj runtime.Object, namespace string) error {
k.obj = obj
k.namespace = namespace
return nil
}
type mockLoader struct {
obj runtime.Object
}
func (l *mockLoader) Load(ctx context.Context, repo, path, ref string) (runtime.Object, error) {
return l.obj, nil
}
func TestHandle(t *testing.T) {
var (
config = &Config{Namespace: "namespace", ResourcePath: "foo/bar.yaml", Secret: []byte("foobar")}
)
logger := log.With(log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)), "caller", log.Caller(5))
handler := NewGithubHookHandler(
logger,
config,
&mockKubernetesClient{},
&mockLoader{},
statsd.New("k8s-ci-purger.", logger),
)
req := httptest.NewRequest("POST", "http://example.com/", nil)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-GitHub-Event", "DeleteEvent")
req.Header.Set("X-GitHub-Delivery", "4636fc67-b693-4a27-87a4-18d4021ae789")
req.Header.Set("X-Hub-Signature", "sha1=1234")
w := httptest.NewRecorder()
handler.ServeHTTP(w, req)
resp := w.Result()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(resp.StatusCode)
fmt.Println(resp.Header.Get("Content-Type"))
fmt.Println(string(body))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_airbnb/k8s-webhook-handler.git
git@gitee.com:mirrors_airbnb/k8s-webhook-handler.git
mirrors_airbnb
k8s-webhook-handler
k8s-webhook-handler
master

搜索帮助