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


Golang testdataclient.New函数代码示例

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


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

示例1: TestMergesMultipleSources

func TestMergesMultipleSources(t *testing.T) {
	if testing.Short() {
		t.Skip()
	}

	dc1 := testdataclient.New([]*eskip.Route{{Id: "route1", Path: "/some-path", Backend: "https://www.example.org"}})
	dc2 := testdataclient.New([]*eskip.Route{{Id: "route2", Path: "/some-other", Backend: "https://other.example.org"}})
	dc3 := testdataclient.New([]*eskip.Route{{Id: "route3", Path: "/another", Backend: "https://another.example.org"}})
	rt := routing.New(routing.Options{
		UpdateBuffer: 0,
		DataClients:  []routing.DataClient{dc1, dc2, dc3},
		PollTimeout:  pollTimeout})

	req1, err := http.NewRequest("GET", "https://www.example.com/some-path", nil)
	if err != nil {
		t.Error(err)
	}

	req2, err := http.NewRequest("GET", "https://www.example.com/some-other", nil)
	if err != nil {
		t.Error(err)
	}

	req3, err := http.NewRequest("GET", "https://www.example.com/another", nil)
	if err != nil {
		t.Error(err)
	}

	if !waitDone(6*pollTimeout,
		waitRoute(rt, req1),
		waitRoute(rt, req2),
		waitRoute(rt, req3)) {
		t.Error("test timeout")
	}
}
开发者ID:nishanthvasudevan,项目名称:skipper,代码行数:35,代码来源:routing_test.go

示例2: TestMergesUpdatesFromMultipleSources

func TestMergesUpdatesFromMultipleSources(t *testing.T) {
	dc1 := testdataclient.New([]*eskip.Route{{Id: "route1", Path: "/some-path", Backend: "https://www.example.org"}})
	dc2 := testdataclient.New([]*eskip.Route{{Id: "route2", Path: "/some-other", Backend: "https://other.example.org"}})
	dc3 := testdataclient.New([]*eskip.Route{{Id: "route3", Path: "/another", Backend: "https://another.example.org"}})
	rt := routing.New(routing.Options{
		UpdateBuffer: 0,
		DataClients:  []routing.DataClient{dc1, dc2, dc3},
		PollTimeout:  pollTimeout})

	req1, err := http.NewRequest("GET", "https://www.example.com/some-path", nil)
	if err != nil {
		t.Error(err)
	}

	req2, err := http.NewRequest("GET", "https://www.example.com/some-other", nil)
	if err != nil {
		t.Error(err)
	}

	req3, err := http.NewRequest("GET", "https://www.example.com/another", nil)
	if err != nil {
		t.Error(err)
	}

	waitRoute(rt, req1)
	waitRoute(rt, req2)
	waitRoute(rt, req3)

	<-waitUpdate(dc1, []*eskip.Route{{Id: "route1", Path: "/some-changed-path", Backend: "https://www.example.org"}}, nil, false)
	<-waitUpdate(dc2, []*eskip.Route{{Id: "route2", Path: "/some-other-changed", Backend: "https://www.example.org"}}, nil, false)
	<-waitUpdate(dc3, nil, []string{"route3"}, false)

	req1, err = http.NewRequest("GET", "https://www.example.com/some-changed-path", nil)
	if err != nil {
		t.Error(err)
	}

	req2, err = http.NewRequest("GET", "https://www.example.com/some-other-changed", nil)
	if err != nil {
		t.Error(err)
	}

	req3, err = http.NewRequest("GET", "https://www.example.com/another", nil)
	if err != nil {
		t.Error(err)
	}

	if !waitDone(6*pollTimeout,
		waitRoute(rt, req1),
		waitRoute(rt, req2)) {
		t.Error("test timeout")
	}

	time.Sleep(3 * pollTimeout)

	if waitDone(0, waitRoute(rt, req3)) {
		t.Error("should not have found route")
	}
}
开发者ID:nishanthvasudevan,项目名称:skipper,代码行数:59,代码来源:routing_test.go

示例3: TestReceivesDelete

func TestReceivesDelete(t *testing.T) {
	dc := testdataclient.New([]*eskip.Route{
		{Id: "route1", Path: "/some-path", Backend: "https://www.example.org"},
		{Id: "route2", Path: "/some-other", Backend: "https://other.example.org"}})
	rt := routing.New(routing.Options{
		UpdateBuffer: 0,
		DataClients:  []routing.DataClient{dc},
		PollTimeout:  pollTimeout})

	req, err := http.NewRequest("GET", "https://www.example.com/some-path", nil)
	if err != nil {
		t.Error(err)
	}

	<-waitRoute(rt, req)
	<-waitUpdate(dc, nil, []string{"route1"}, false)
	time.Sleep(6 * pollTimeout)

	req, err = http.NewRequest("GET", "https://www.example.com/some-path", nil)
	if err != nil {
		t.Error(err)
	}

	if waitDone(0, waitRoute(rt, req)) {
		t.Error("should not have found route")
	}
}
开发者ID:nishanthvasudevan,项目名称:skipper,代码行数:27,代码来源:routing_test.go

示例4: TestProcessesFilterDefinitions

func TestProcessesFilterDefinitions(t *testing.T) {
	fr := make(filters.Registry)
	fs := &filtertest.Filter{FilterName: "filter1"}
	fr.Register(fs)

	dc := testdataclient.New([]*eskip.Route{{
		Id:      "route1",
		Path:    "/some-path",
		Filters: []*eskip.Filter{{Name: "filter1", Args: []interface{}{3.14, "Hello, world!"}}},
		Backend: "https://www.example.org"}})

	tr, err := newTestRoutingWithFilters(fr, dc)
	if err != nil {
		t.Error(err)
		return
	}

	defer tr.close()

	if r, err := tr.checkGetRequest("https://www.example.com/some-path"); r == nil || err != nil {
		t.Error(err)
	} else {
		if len(r.Filters) != 1 {
			t.Error("failed to process filters")
			return
		}

		if f, ok := r.Filters[0].Filter.(*filtertest.Filter); !ok ||
			f.FilterName != fs.Name() || len(f.Args) != 2 ||
			f.Args[0] != float64(3.14) || f.Args[1] != "Hello, world!" {
			t.Error("failed to process filters")
		}
	}
}
开发者ID:zalando,项目名称:skipper,代码行数:34,代码来源:routing_test.go

示例5: Example

func Example() {
	// create a data client:
	dataClient := testdataclient.New([]*eskip.Route{
		{Path: "/some/path", Backend: "https://www.example.org"}})

	// (only in tests)
	tl := loggingtest.New()
	defer tl.Close()

	// create a router:
	r := routing.New(routing.Options{
		DataClients: []routing.DataClient{dataClient},
		Log:         tl})
	defer r.Close()

	// wait for the route data being propagated:
	tl.WaitFor("route settigns applied", time.Second)

	// test the router:
	route, _ := r.Route(&http.Request{URL: &url.URL{Path: "/some/path"}})
	if route == nil {
		log.Fatal("failed to route request")
	}

	fmt.Println(route.Backend)

	// Output:
	// https://www.example.org
}
开发者ID:zalando,项目名称:skipper,代码行数:29,代码来源:example_test.go

示例6: TestMergesUpdatesFromMultipleSources

func TestMergesUpdatesFromMultipleSources(t *testing.T) {
	dc1 := testdataclient.New([]*eskip.Route{{Id: "route1", Path: "/some-path", Backend: "https://www.example.org"}})
	dc2 := testdataclient.New([]*eskip.Route{{Id: "route2", Path: "/some-other", Backend: "https://other.example.org"}})
	dc3 := testdataclient.New([]*eskip.Route{{Id: "route3", Path: "/another", Backend: "https://another.example.org"}})
	tr, err := newTestRouting(dc1, dc2, dc3)
	if err != nil {
		t.Error(err)
		return
	}

	defer tr.close()

	if _, err := tr.checkGetRequest("https://www.example.com/some-path"); err != nil {
		t.Error(err)
	}

	if _, err := tr.checkGetRequest("https://www.example.com/some-other"); err != nil {
		t.Error(err)
	}

	if _, err := tr.checkGetRequest("https://www.example.com/another"); err != nil {
		t.Error(err)
	}

	tr.log.Reset()

	dc1.Update([]*eskip.Route{{Id: "route1", Path: "/some-changed-path", Backend: "https://www.example.org"}}, nil)
	dc2.Update([]*eskip.Route{{Id: "route2", Path: "/some-other-changed", Backend: "https://www.example.org"}}, nil)
	dc3.Update(nil, []string{"route3"})

	if err := tr.waitForNRouteSettings(3); err != nil {
		t.Error(err)
		return
	}

	if _, err := tr.checkGetRequest("https://www.example.com/some-changed-path"); err != nil {
		t.Error(err)
	}

	if _, err := tr.checkGetRequest("https://www.example.com/some-other-changed"); err != nil {
		t.Error(err)
	}

	if _, err := tr.checkGetRequest("https://www.example.com/another"); err == nil {
		t.Error(err)
	}
}
开发者ID:zalando,项目名称:skipper,代码行数:47,代码来源:routing_test.go

示例7: TestReceivesInitial

func TestReceivesInitial(t *testing.T) {
	dc := testdataclient.New([]*eskip.Route{{Id: "route1", Path: "/some-path", Backend: "https://www.example.org"}})
	tr, err := newTestRouting(dc)
	if err != nil {
		t.Error(err)
	}

	defer tr.close()

	if _, err := tr.checkGetRequest("https://www.example.com/some-path"); err != nil {
		t.Error(err)
	}
}
开发者ID:zalando,项目名称:skipper,代码行数:13,代码来源:routing_test.go

示例8: TestIgnoresInvalidBackend

func TestIgnoresInvalidBackend(t *testing.T) {
	dc := testdataclient.New([]*eskip.Route{{Id: "route1", Path: "/some-path", Backend: "invalid backend"}})
	tr, err := newTestRouting(dc)
	if err != nil {
		t.Error(err)
	}

	defer tr.close()

	if err = tr.log.WaitFor("invalid backend", time.Second); err != nil {
		t.Error(err)
	}
}
开发者ID:zalando,项目名称:skipper,代码行数:13,代码来源:routing_test.go

示例9: TestMergesMultipleSources

func TestMergesMultipleSources(t *testing.T) {
	dc1 := testdataclient.New([]*eskip.Route{{Id: "route1", Path: "/some-path", Backend: "https://www.example.org"}})
	dc2 := testdataclient.New([]*eskip.Route{{Id: "route2", Path: "/some-other", Backend: "https://other.example.org"}})
	dc3 := testdataclient.New([]*eskip.Route{{Id: "route3", Path: "/another", Backend: "https://another.example.org"}})
	tr, err := newTestRouting(dc1, dc2, dc3)
	if err != nil {
		t.Error(err)
		return
	}

	defer tr.close()

	if _, err := tr.checkGetRequest("https://www.example.com/some-path"); err != nil {
		t.Error(err)
	}

	if _, err := tr.checkGetRequest("https://www.example.com/some-other"); err != nil {
		t.Error(err)
	}

	if _, err := tr.checkGetRequest("https://www.example.com/another"); err != nil {
		t.Error(err)
	}
}
开发者ID:zalando,项目名称:skipper,代码行数:24,代码来源:routing_test.go

示例10: TestIgnoresInvalidBackend

func TestIgnoresInvalidBackend(t *testing.T) {
	dc := testdataclient.New([]*eskip.Route{{Id: "route1", Path: "/some-path", Backend: "invalid backend"}})
	rt := routing.New(routing.Options{
		UpdateBuffer: 0,
		DataClients:  []routing.DataClient{dc},
		PollTimeout:  pollTimeout})

	req, err := http.NewRequest("GET", "https://www.example.com/some-path", nil)
	if err != nil {
		t.Error(err)
	}

	if waitDone(6*pollTimeout, waitRoute(rt, req)) {
		t.Error("should not have found route")
	}
}
开发者ID:nishanthvasudevan,项目名称:skipper,代码行数:16,代码来源:routing_test.go

示例11: TestReceivesInitial

func TestReceivesInitial(t *testing.T) {
	dc := testdataclient.New([]*eskip.Route{{Id: "route1", Path: "/some-path", Backend: "https://www.example.org"}})
	rt := routing.New(routing.Options{
		UpdateBuffer: 0,
		DataClients:  []routing.DataClient{dc},
		PollTimeout:  pollTimeout})

	req, err := http.NewRequest("GET", "https://www.example.com/some-path", nil)
	if err != nil {
		t.Error(err)
	}

	if !waitDone(6*pollTimeout, waitRoute(rt, req)) {
		t.Error("test timeout")
	}
}
开发者ID:nishanthvasudevan,项目名称:skipper,代码行数:16,代码来源:routing_test.go

示例12: TestKeepsReceivingInitialRouteDataUntilSucceeds

func TestKeepsReceivingInitialRouteDataUntilSucceeds(t *testing.T) {
	dc := testdataclient.New([]*eskip.Route{{Id: "route1", Path: "/some-path", Backend: "https://www.example.org"}})
	dc.FailNext()
	dc.FailNext()
	dc.FailNext()

	tr, err := newTestRouting(dc)
	if err != nil {
		t.Error(err)
		return
	}

	defer tr.close()

	if _, err := tr.checkGetRequest("https://www.example.com/some-path"); err != nil {
		t.Error(err)
	}
}
开发者ID:zalando,项目名称:skipper,代码行数:18,代码来源:routing_test.go

示例13: WithParams

func WithParams(fr filters.Registry, o proxy.Params, routes ...*eskip.Route) *TestProxy {
	dc := testdataclient.New(routes)
	tl := loggingtest.New()
	rt := routing.New(routing.Options{FilterRegistry: fr, DataClients: []routing.DataClient{dc}, Log: tl})
	o.Routing = rt
	pr := proxy.WithParams(o)
	tsp := httptest.NewServer(pr)

	if err := tl.WaitFor("route settings applied", 3*time.Second); err != nil {
		panic(err)
	}

	return &TestProxy{
		URL:     tsp.URL,
		log:     tl,
		routing: rt,
		proxy:   pr,
		server:  tsp}
}
开发者ID:zalando,项目名称:skipper,代码行数:19,代码来源:proxytest.go

示例14: TestProcessesFilterDefinitions

func TestProcessesFilterDefinitions(t *testing.T) {
	if testing.Short() {
		t.Skip()
	}

	fr := make(filters.Registry)
	fs := &filtertest.Filter{FilterName: "filter1"}
	fr.Register(fs)

	dc := testdataclient.New([]*eskip.Route{{
		Id:      "route1",
		Path:    "/some-path",
		Filters: []*eskip.Filter{{Name: "filter1", Args: []interface{}{3.14, "Hello, world!"}}},
		Backend: "https://www.example.org"}})
	rt := routing.New(routing.Options{
		UpdateBuffer:   0,
		DataClients:    []routing.DataClient{dc},
		PollTimeout:    pollTimeout,
		FilterRegistry: fr})

	req, err := http.NewRequest("GET", "https://www.example.com/some-path", nil)
	if err != nil {
		t.Error(err)
	}

	select {
	case r := <-waitRoute(rt, req):
		if len(r.Filters) != 1 {
			t.Error("failed to process filters")
			return
		}

		if f, ok := r.Filters[0].Filter.(*filtertest.Filter); !ok ||
			f.FilterName != fs.Name() || len(f.Args) != 2 ||
			f.Args[0] != float64(3.14) || f.Args[1] != "Hello, world!" {
			t.Error("failed to process filters")
		}
	case <-time.After(3 * pollTimeout):
		t.Error("test timeout")
	}
}
开发者ID:nishanthvasudevan,项目名称:skipper,代码行数:41,代码来源:routing_test.go

示例15: TestReceivesUpdate

func TestReceivesUpdate(t *testing.T) {
	dc := testdataclient.New([]*eskip.Route{{Id: "route1", Path: "/some-path", Backend: "https://www.example.org"}})
	tr, err := newTestRouting(dc)
	if err != nil {
		t.Error(err)
		return
	}

	defer tr.close()

	tr.log.Reset()
	dc.Update([]*eskip.Route{{Id: "route2", Path: "/some-other", Backend: "https://other.example.org"}}, nil)

	if err := tr.waitForRouteSetting(); err != nil {
		t.Error(err)
		return
	}

	if _, err := tr.checkGetRequest("https://www.example.com/some-other"); err != nil {
		t.Error(err)
	}
}
开发者ID:zalando,项目名称:skipper,代码行数:22,代码来源:routing_test.go


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