Example #1
0
func TestPing(t *testing.T) {
	if testutil.RunningInCI() {
		t.Skip("Skipping volume client test because it looks like we're in the CI environment.")
	}
	runService(t)
	client := network.NewVolumeClient(volTestPort)
	require.NotNil(t, client)

	err := client.Ping(500)
	assert.Nil(t, err)
}
Example #2
0
func TestReport(t *testing.T) {
	if testutil.RunningInCI() {
		t.Skip("Skipping volume service test because it looks like we're in the CI environment.")
	}
	runService(t)

	// Reserve a chunk of space with 8000 bytes
	reserveUrl := fmt.Sprintf("%s/reserve/", serviceUrl)
	params := url.Values{
		"path":  {"/tmp/some_file"},
		"bytes": {"8000"},
	}
	resp, err := http.PostForm(reserveUrl, params)
	require.Nil(t, err)
	data, err := ioutil.ReadAll(resp.Body)
	assert.Nil(t, err)
	resp.Body.Close()
	assert.Equal(t, http.StatusOK, resp.StatusCode)

	// Reserve another chunk with 24000 bytes
	params = url.Values{
		"path":  {"/tmp/some_other_file"},
		"bytes": {"24000"},
	}
	resp, err = http.PostForm(reserveUrl, params)
	require.Nil(t, err)
	data, err = ioutil.ReadAll(resp.Body)
	assert.Nil(t, err)
	resp.Body.Close()
	assert.Equal(t, http.StatusOK, resp.StatusCode)

	reportUrl := fmt.Sprintf("%s/report/", serviceUrl)
	resp, err = http.Get(reportUrl)
	require.Nil(t, err)
	data, err = ioutil.ReadAll(resp.Body)
	assert.Nil(t, err)
	resp.Body.Close()

	expected := `{"Succeeded":false,"ErrorMessage":"Param 'path' is required.","Data":null}`
	assert.Equal(t, expected, string(data))
	assert.Equal(t, http.StatusBadRequest, resp.StatusCode)

	reportUrl = fmt.Sprintf("%s/report/?path=/", serviceUrl)
	resp, err = http.Get(reportUrl)
	require.Nil(t, err)
	data, err = ioutil.ReadAll(resp.Body)
	assert.Nil(t, err)
	resp.Body.Close()

	expected = `{"Succeeded":true,"ErrorMessage":"","Data":{"/tmp/some_file":8000,"/tmp/some_other_file":24000}}`
	assert.Equal(t, expected, string(data))
	assert.Equal(t, http.StatusOK, resp.StatusCode)
}
Example #3
0
func TestReserve(t *testing.T) {
	if testutil.RunningInCI() {
		t.Skip("Skipping volume service test because it looks like we're in the CI environment.")
	}
	runService(t)

	reserveUrl := fmt.Sprintf("%s/reserve/", serviceUrl)

	// Start with a good request
	params := url.Values{
		"path":  {"/tmp/some_file"},
		"bytes": {"8000"},
	}
	resp, err := http.PostForm(reserveUrl, params)
	require.Nil(t, err)
	data, err := ioutil.ReadAll(resp.Body)
	assert.Nil(t, err)
	resp.Body.Close()

	expected := `{"Succeeded":true,"ErrorMessage":"","Data":null}`
	assert.Equal(t, expected, string(data))
	assert.Equal(t, http.StatusOK, resp.StatusCode)

	// Bad request: no path
	params = url.Values{
		"bytes": {"8000"},
	}
	resp, err = http.PostForm(reserveUrl, params)
	require.Nil(t, err)
	data, err = ioutil.ReadAll(resp.Body)
	assert.Nil(t, err)
	resp.Body.Close()

	expected = `{"Succeeded":false,"ErrorMessage":"Param 'path' is required.","Data":null}`
	assert.Equal(t, expected, string(data))
	assert.Equal(t, http.StatusBadRequest, resp.StatusCode)

	// Bad request: no value for bytes
	params = url.Values{
		"path": {"/tmp/some_file"},
	}
	resp, err = http.PostForm(reserveUrl, params)
	require.Nil(t, err)
	data, err = ioutil.ReadAll(resp.Body)
	assert.Nil(t, err)
	resp.Body.Close()

	expected = `{"Succeeded":false,"ErrorMessage":"Param 'bytes' must be an integer greater than zero.","Data":null}`
	assert.Equal(t, expected, string(data))
	assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
}
Example #4
0
func TestVolumeRelease(t *testing.T) {
	if testutil.RunningInCI() {
		t.Skip("Skipping volume client test because it looks like we're in the CI environment.")
	}
	runService(t)
	client := network.NewVolumeClient(volTestPort)
	require.NotNil(t, client)

	err := client.Release("/tmp/some_file")
	assert.Nil(t, err)

	err = client.Release("")
	assert.NotNil(t, err) // path required
}
Example #5
0
func TestPing(t *testing.T) {
	if testutil.RunningInCI() {
		t.Skip("Skipping volume service test because it looks like we're in the CI environment.")
	}
	runService(t)

	pingUrl := fmt.Sprintf("%s/ping/", serviceUrl)
	resp, err := http.Get(pingUrl)
	require.Nil(t, err)
	data, err := ioutil.ReadAll(resp.Body)
	assert.Nil(t, err)
	resp.Body.Close()

	expected := `{"Succeeded":true,"ErrorMessage":"","Data":null}`
	assert.Equal(t, expected, string(data))
	assert.Equal(t, http.StatusOK, resp.StatusCode)
}
Example #6
0
func TestVolumeReserve(t *testing.T) {
	if testutil.RunningInCI() {
		t.Skip("Skipping volume client test because it looks like we're in the CI environment.")
	}
	runService(t)
	client := network.NewVolumeClient(volTestPort)
	require.NotNil(t, client)

	ok, err := client.Reserve("/tmp/some_file", uint64(800))
	assert.Nil(t, err)
	assert.True(t, ok)

	ok, err = client.Reserve("", uint64(800))
	assert.NotNil(t, err) // path required
	assert.False(t, ok)

	ok, err = client.Reserve("", uint64(0))
	assert.NotNil(t, err) // > 0 bytes required
	assert.False(t, ok)
}
Example #7
0
func TestNewVolumeService(t *testing.T) {
	if testutil.RunningInCI() {
		t.Skip("Skipping volume service test because it looks like we're in the CI environment.")
	}
	runService(t)
}