Esempio n. 1
0
// docker run golang go version
func TestRunContainer(t *testing.T) {
	var payload = []byte(`{"AttachStdin": "false",
		"AttachStout": "true",
		"AttachStderr": "true",
		"Tty": "false",
		"OpenStdin": "false",
		"StdinOnce": "false",
		"Cmd":["/bin/bash", "-c", "go", "version"],
		"Image": "golang",
		"DisableNetwork": "false"
	}`)

	mockReq, _ := http.NewRequest("POST", "/containers/create?name=golang", bytes.NewBuffer(payload))

	ctx := context.Empty()
	ctx.SetHttpRequest(mockReq)

	modDocker := NewDocker(defaultParams())
	resp, err := modDocker.ProcessRequest(ctx)
	assert.Nil(t, err)

	assert.Equal(t, resp.StatusCode, 200)
	body, _ := ioutil.ReadAll(resp.Body)
	fmt.Printf("Docker Run output\n============\n %s\n", body)
}
Esempio n. 2
0
func TestHappyProcessChain(t *testing.T) {
	OnRequest1Fn := func(ctx context.ContextSpec) (*http.Response, error) {
		return nil, nil
	}
	OnResponse1Fn := func(ctx context.ContextSpec) (*http.Response, error) {
		return nil, nil
	}

	OnRequest2Fn := func(ctx context.ContextSpec) (*http.Response, error) {
		return httputils.NewTextResponse(nil, 200, "happy life"), nil
	}
	OnResponse2Fn := func(ctx context.ContextSpec) (*http.Response, error) {
		return nil, nil
	}

	modMock1 := modules.NewWithParams("mod_mock_1", OnRequest1Fn, OnResponse1Fn)
	modMock2 := modules.NewWithParams("mod_mock_2", OnRequest2Fn, OnResponse2Fn)

	chain := New()
	chain.AppendModule(modMock1)
	chain.AppendModule(modMock2)

	assert.Equal(t, len(chain.GetModules()), 2)

	resp, err := chain.Process(context.Empty())

	assert.Nil(t, err)
	assert.Equal(t, resp.StatusCode, 200)
}
Esempio n. 3
0
func TestGetImages(t *testing.T) {
	// Prepare the context
	mockReq, _ := http.NewRequest("GET", "/images/json", nil)
	ctx := context.Empty()
	ctx.SetHttpRequest(mockReq)

	modDocker := NewDocker(defaultParams())
	resp, err := modDocker.ProcessRequest(ctx)

	assert.Nil(t, err)
	assert.Equal(t, resp.StatusCode, 200)
	body, _ := ioutil.ReadAll(resp.Body)
	fmt.Printf("Docker Images\n============\n %s\n", body)
}
Esempio n. 4
0
func TestChangePath(t *testing.T) {

	mockReq, _ := http.NewRequest("GET", "/docker/images/json?query=example", nil)
	ctx := context.Empty()
	ctx.SetHttpRequest(mockReq)

	modRewrite := NewRewrite(defaultParams())
	_, err := modRewrite.ProcessRequest(ctx)

	assert.Nil(t, err)
	//assert.Equal(t, resp.StatusCode, 200)
	//body, _ := ioutil.ReadAll(resp.Body)
	//fmt.Printf("Body\n============\n %s\n", body)
}
Esempio n. 5
0
func TestHappyProxy(t *testing.T) {
	proxy := New("testProxy", "GET", "/ping", true, getMockChain())
	resp, err := proxy.RoundTrip(context.Empty())
	assert.Nil(t, err)
	assert.Equal(t, resp.StatusCode, 200)
}