代码拉取完成,页面将自动刷新
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))
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。