Exemple #1
0
func TestClientWithBehavior(t *testing.T) {
	r := struct {
		calledA bool
		calledB bool
	}{}
	c := &Client{
		ClientHostPort: "127.0.0.1:0",
		Behaviors: crossdock.Behaviors{
			"hello": func(t crossdock.T) {
				if t.Param("param") == "a" {
					t.Successf("good")
					r.calledA = true
				}
				if t.Param("param") == "b" {
					t.Skipf("not so good")
					r.calledB = true
				}
			},
		},
	}
	require.NoError(t, c.Start())
	defer c.Close()
	crossdock.Wait(t, c.URL(), 10)

	axes := map[string][]string{
		"param": {"a", "b"},
	}
	for _, entry := range crossdock.Combinations(axes) {
		entryArgs := url.Values{}
		for k, v := range entry {
			entryArgs.Set(k, v)
		}
		// test via real HTTP call
		crossdock.Call(t, c.URL(), "hello", entryArgs)
	}
	assert.True(t, r.calledA)
	assert.True(t, r.calledB)
}