当前位置: 首页>>代码示例>>Golang>>正文


Golang webhook.NewController函数代码示例

本文整理汇总了Golang中github.com/openshift/origin/pkg/build/webhook.NewController函数的典型用法代码示例。如果您正苦于以下问题:Golang NewController函数的具体用法?Golang NewController怎么用?Golang NewController使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewController函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestJsonPushEventError

func TestJsonPushEventError(t *testing.T) {
	server := httptest.NewServer(webhook.NewController(&okBuildConfigGetter{}, &okBuildConfigInstantiator{},
		map[string]webhook.Plugin{"github": New()}))
	defer server.Close()

	post("X-GitHub-Event", "push", []byte{}, server.URL+"/build100/secret101/github", http.StatusBadRequest, t)
}
开发者ID:asiainfoLDP,项目名称:datafactory,代码行数:7,代码来源:github_test.go

示例2: TestJsonPushEvent

func TestJsonPushEvent(t *testing.T) {
	server := httptest.NewServer(webhook.NewController(&osClient{}, map[string]webhook.Plugin{"github": New()}))
	defer server.Close()

	postFile("push", "pushevent.json", server.URL+"/build100/secret101/github",
		http.StatusOK, t)
}
开发者ID:rajdavies,项目名称:origin,代码行数:7,代码来源:github_test.go

示例3: TestJsonGogsPushEvent

func TestJsonGogsPushEvent(t *testing.T) {
	server := httptest.NewServer(webhook.NewController(&okBuildConfigGetter{}, &okBuildConfigInstantiator{},
		map[string]webhook.Plugin{"github": New()}))
	defer server.Close()

	postFile("X-Gogs-Event", "push", "pushevent.json", server.URL+"/build100/secret101/github",
		http.StatusOK, t)
}
开发者ID:asiainfoLDP,项目名称:datafactory,代码行数:8,代码来源:github_test.go

示例4: TestJsonGitHubPushEventWithCharset

func TestJsonGitHubPushEventWithCharset(t *testing.T) {
	server := httptest.NewServer(webhook.NewController(&okBuildConfigGetter{}, &okBuildConfigInstantiator{},
		map[string]webhook.Plugin{"github": New()}))
	defer server.Close()

	postFileWithCharset("X-GitHub-Event", "push", "pushevent.json", server.URL+"/build100/secret101/github",
		"application/json; charset=utf-8", http.StatusOK, t)
}
开发者ID:asiainfoLDP,项目名称:datafactory,代码行数:8,代码来源:github_test.go

示例5: TestWrongMethod

func TestWrongMethod(t *testing.T) {
	server := httptest.NewServer(webhook.NewController(&osClient{}, map[string]webhook.Plugin{"github": New()}))
	defer server.Close()

	resp, _ := http.Get(server.URL + "/build100/secret101/github")
	body, _ := ioutil.ReadAll(resp.Body)
	if resp.StatusCode != http.StatusBadRequest ||
		!strings.Contains(string(body), "method") {
		t.Errorf("Expected BadRequest , got %s: %s!", resp.Status, string(body))
	}
}
开发者ID:rajdavies,项目名称:origin,代码行数:11,代码来源:github_test.go

示例6: TestWrongSecret

func TestWrongSecret(t *testing.T) {
	server := httptest.NewServer(webhook.NewController(&okBuildConfigGetter{}, &okBuildConfigInstantiator{},
		map[string]webhook.Plugin{"github": New()}))
	defer server.Close()

	client := &http.Client{}
	req, _ := http.NewRequest("POST", server.URL+"/build100/wrongsecret/github", nil)
	resp, _ := client.Do(req)
	body, _ := ioutil.ReadAll(resp.Body)
	if resp.StatusCode != http.StatusBadRequest ||
		!strings.Contains(string(body), webhook.ErrSecretMismatch.Error()) {
		t.Errorf("Expected BadRequest, got %s: %s!", resp.Status, string(body))
	}
}
开发者ID:asiainfoLDP,项目名称:datafactory,代码行数:14,代码来源:github_test.go

示例7: TestMissingEvent

func TestMissingEvent(t *testing.T) {
	server := httptest.NewServer(webhook.NewController(&okBuildConfigGetter{}, &okBuildConfigInstantiator{},
		map[string]webhook.Plugin{"github": New()}))
	defer server.Close()

	client := &http.Client{}
	req, _ := http.NewRequest("POST", server.URL+"/build100/secret101/github", nil)
	req.Header.Add("Content-Type", "application/json")
	resp, _ := client.Do(req)
	body, _ := ioutil.ReadAll(resp.Body)
	if resp.StatusCode != http.StatusBadRequest ||
		!strings.Contains(string(body), "missing X-GitHub-Event or X-Gogs-Event") {
		t.Errorf("Expected BadRequest, got %s: %s!", resp.Status, string(body))
	}
}
开发者ID:asiainfoLDP,项目名称:datafactory,代码行数:15,代码来源:github_test.go

示例8: TestWrongGithubEvent

func TestWrongGithubEvent(t *testing.T) {
	server := httptest.NewServer(webhook.NewController(&osClient{}, map[string]webhook.Plugin{"github": New()}))
	defer server.Close()

	client := &http.Client{}
	req, _ := http.NewRequest("POST", server.URL+"/build100/secret101/github", nil)
	req.Header.Add("Content-Type", "application/json")
	req.Header.Add("User-Agent", "GitHub-Hookshot/github")
	req.Header.Add("X-GitHub-Event", "wrong")
	resp, _ := client.Do(req)
	body, _ := ioutil.ReadAll(resp.Body)
	if resp.StatusCode != http.StatusBadRequest ||
		!strings.Contains(string(body), "Unknown") {
		t.Errorf("Excepcted BadRequest, got %s: %s!", resp.Status, string(body))
	}
}
开发者ID:rajdavies,项目名称:origin,代码行数:16,代码来源:github_test.go

示例9: TestJsonPushEventError

func TestJsonPushEventError(t *testing.T) {
	server := httptest.NewServer(webhook.NewController(&osClient{}, map[string]webhook.Plugin{"github": New()}))
	defer server.Close()

	post("push", []byte{}, server.URL+"/build100/secret101/github", http.StatusBadRequest, t)
}
开发者ID:rajdavies,项目名称:origin,代码行数:6,代码来源:github_test.go

示例10: TestWebhookGithubPush

func TestWebhookGithubPush(t *testing.T) {
	etcdClient := newEtcdClient()
	m := master.New(&master.Config{
		EtcdServers: etcdClient.GetCluster(),
	})
	osMux := http.NewServeMux()
	storage := map[string]apiserver.RESTStorage{
		"builds":       buildregistry.NewStorage(build.NewEtcdRegistry(etcdClient)),
		"buildConfigs": buildconfigregistry.NewStorage(build.NewEtcdRegistry(etcdClient)),
	}
	apiserver.NewAPIGroup(m.API_v1beta1()).InstallREST(osMux, "/api/v1beta1")
	osPrefix := "/osapi/v1beta1"
	apiserver.NewAPIGroup(storage, runtime.Codec).InstallREST(osMux, osPrefix)
	apiserver.InstallSupport(osMux)

	s := httptest.NewServer(osMux)

	kubeclient := client.NewOrDie(s.URL, nil)
	osClient, _ := osclient.New(s.URL, nil)

	whPrefix := osPrefix + "/buildConfigHooks/"
	osMux.Handle(whPrefix, http.StripPrefix(whPrefix,
		webhook.NewController(osClient, map[string]webhook.Plugin{
			"github": github.New(),
		})))

	info, err := kubeclient.ServerVersion()
	if err != nil {
		t.Fatalf("Unexpected error: %v", err)
	}
	if e, a := version.Get(), *info; !reflect.DeepEqual(e, a) {
		t.Errorf("Expected %#v, got %#v", e, a)
	}

	// create buildconfig
	buildConfig := &buildapi.BuildConfig{
		JSONBase: kubeapi.JSONBase{
			ID: "build100",
		},
		DesiredInput: buildapi.BuildInput{
			Type:      buildapi.DockerBuildType,
			SourceURI: "http://my.docker/build",
			ImageTag:  "namespace/builtimage",
		},
		Secret: "secret101",
	}
	if _, err := osClient.CreateBuildConfig(buildConfig); err != nil {
		t.Fatalf("Unexpected error: %v", err)
	}

	// trigger build event sending push notification
	client := &http.Client{}
	data, err := ioutil.ReadFile("../../pkg/build/webhook/github/fixtures/pushevent.json")
	if err != nil {
		t.Fatalf("Failed to open pushevent.json: %v", err)
	}
	req, err := http.NewRequest("POST", s.URL+whPrefix+"build100/secret101/github", bytes.NewReader(data))
	if err != nil {
		t.Fatalf("Error creating POST request: %v", err)
	}
	req.Header.Add("Content-Type", "application/json")
	req.Header.Add("User-Agent", "GitHub-Hookshot/github")
	req.Header.Add("X-Github-Event", "push")
	resp, err := client.Do(req)
	if err != nil {
		t.Fatalf("Failed posting webhook: %v", err)
	}
	body, _ := ioutil.ReadAll(resp.Body)
	if resp.StatusCode != http.StatusOK {
		t.Errorf("Wrong response code, expecting 200, got %s: %s!",
			resp.Status, string(body))
	}

	// get a list of builds
	builds, err := osClient.ListBuilds(labels.Everything())
	if err != nil {
		t.Fatalf("Unexpected error: %v", err)
	}
	if len(builds.Items) != 1 {
		t.Fatalf("Expected one build, got %#v", builds)
	}
	actual := builds.Items[0]
	if actual.Status != buildapi.BuildNew {
		t.Errorf("Expected %s, got %s", buildapi.BuildNew, actual.Status)
	}
	if !reflect.DeepEqual(actual.Input, buildConfig.DesiredInput) {
		t.Errorf("Expected %#v, got %#v", buildConfig.DesiredInput, actual.Input)
	}

}
开发者ID:rajdavies,项目名称:origin,代码行数:90,代码来源:webhookgithub_test.go

示例11: runApiserver

func (c *config) runApiserver() {
	minionPort := 10250
	osAddr := c.ListenAddr

	kubePrefix := "/api/v1beta1"
	osPrefix := "/osapi/v1beta1"

	kubeClient := c.getKubeClient()
	osClient := c.getOsClient()
	etcdClient, etcdServers := c.getEtcdClient()

	imageRegistry := imageetcd.NewEtcd(etcdClient)

	// initialize OpenShift API
	storage := map[string]apiserver.RESTStorage{
		"builds":                  buildregistry.NewStorage(build.NewEtcdRegistry(etcdClient)),
		"buildConfigs":            buildconfigregistry.NewStorage(build.NewEtcdRegistry(etcdClient)),
		"images":                  image.NewREST(imageRegistry),
		"imageRepositories":       imagerepository.NewREST(imageRegistry),
		"imageRepositoryMappings": imagerepositorymapping.NewREST(imageRegistry, imageRegistry),
		"templateConfigs":         template.NewStorage(),
	}

	osMux := http.NewServeMux()

	// initialize webhooks
	whPrefix := osPrefix + "/buildConfigHooks/"
	osMux.Handle(whPrefix, http.StripPrefix(whPrefix,
		webhook.NewController(osClient, map[string]webhook.Plugin{
			"github": github.New(),
		})))

	// initialize Kubernetes API
	podInfoGetter := &kubeclient.HTTPPodInfoGetter{
		Client: http.DefaultClient,
		Port:   uint(minionPort),
	}
	masterConfig := &master.Config{
		Client:             kubeClient,
		EtcdServers:        etcdServers,
		HealthCheckMinions: true,
		Minions:            c.nodeHosts,
		PodInfoGetter:      podInfoGetter,
	}
	m := master.New(masterConfig)

	apiserver.NewAPIGroup(m.API_v1beta1()).InstallREST(osMux, kubePrefix)
	apiserver.NewAPIGroup(storage, runtime.Codec).InstallREST(osMux, osPrefix)
	apiserver.InstallSupport(osMux)

	osApi := &http.Server{
		Addr:           osAddr,
		Handler:        apiserver.RecoverPanics(osMux),
		ReadTimeout:    5 * time.Minute,
		WriteTimeout:   5 * time.Minute,
		MaxHeaderBytes: 1 << 20,
	}

	go util.Forever(func() {
		glog.Infof("Started Kubernetes API at http://%s%s", osAddr, kubePrefix)
		glog.Infof("Started OpenShift API at http://%s%s", osAddr, osPrefix)
		glog.Fatal(osApi.ListenAndServe())
	}, 0)
}
开发者ID:rajdavies,项目名称:origin,代码行数:64,代码来源:master.go


注:本文中的github.com/openshift/origin/pkg/build/webhook.NewController函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。