Beispiel #1
0
func (er ExecRun) Test(t *testing.T) {
	stdout, stderr, code, err := er.exec()

	assert.Nil(t, err, "should be nil")
	assert.Equal(t, er.Exit, code, "exit code should be equal")
	assert.Equal(t, er.Stdout, stdout, "stdout should be equal")
	assert.Equal(t, er.Stderr, stderr, "stderr should be equal")
}
Beispiel #2
0
func TestAppShow(t *testing.T) {
	aws := stubAws(test.DescribeAppStackCycle("bar"))
	defer aws.Close()

	body := HTTPBody("GET", "http://convox/apps/bar", nil)

	var resp map[string]string
	err := json.Unmarshal([]byte(body), &resp)

	if assert.Nil(t, err) {
		assert.Equal(t, "bar", resp["name"])
		assert.Equal(t, "running", resp["status"])
	}
}
Beispiel #3
0
func TestAppCreate(t *testing.T) {
	aws := stubAws(
		test.CreateAppStackCycle("application"),
		test.DescribeAppStackCycle("application"),
	)
	defer aws.Close()

	val := url.Values{"name": []string{"application"}}
	body := HTTPBody("POST", "http://convox/apps", val)

	if assert.NotEqual(t, "", body) {
		var resp map[string]string
		err := json.Unmarshal([]byte(body), &resp)

		if assert.Nil(t, err) {
			assert.Equal(t, "application", resp["name"])
			assert.Equal(t, "running", resp["status"])
		}
	}
}
Beispiel #4
0
func AssertStatus(t *testing.T, status int, method, url string, values url.Values) string {
	w := httptest.NewRecorder()
	req, err := buildRequest(method, url, values)

	if err != nil {
		t.Error(err)
		return ""
	}

	controllers.HandlerFunc(w, req)
	assert.Equal(t, status, w.Code)
	return w.Body.String()
}
Beispiel #5
0
func TestBasicAuth(t *testing.T) {
	assert := assert.New(t)
	aws := stubAws(test.DescribeConvoxStackCycle("convox-test"))
	defer aws.Close()
	defer os.Setenv("PASSWORD", os.Getenv("PASSWORD"))
	defer os.Setenv("RACK", os.Getenv("RACK"))

	os.Setenv("PASSWORD", "keymaster")
	os.Setenv("RACK", "convox-test")

	req, _ := http.NewRequest("GET", "http://convox/system", nil)
	w := httptest.NewRecorder()
	controllers.HandlerFunc(w, req)

	if !assert.Equal(401, w.Code) {
		return
	}

	w = httptest.NewRecorder()
	req.SetBasicAuth("", "keymaster")
	controllers.HandlerFunc(w, req)

	assert.Equal(200, w.Code)
}
Beispiel #6
0
/* NOTE: the S3 stuff f***s up b.c the client ries to prepend the
bucket name to the ephermeral host, so you get `app-XXX.127.0.0.1`
*/
func TestAppDelete(t *testing.T) {
	aws := stubAws(
		test.DescribeAppStackCycle("bar"),
		test.DeleteStackCycle("bar"),
	)
	defer aws.Close()

	body := HTTPBody("DELETE", "http://convox/apps/bar", nil)

	var resp map[string]bool
	err := json.Unmarshal([]byte(body), &resp)

	if assert.Nil(t, err) {
		assert.Equal(t, true, resp["success"])
	}
}
Beispiel #7
0
func Server(t *testing.T, stubs ...Http) *httptest.Server {
	ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		found := false

		for _, stub := range stubs {
			if stub.Method == r.Method && stub.Path == r.URL.Path {
				data, err := json.Marshal(stub.Response)

				if err != nil {
					w.WriteHeader(503)
					w.Write(serverError(err.Error()))
				}

				rb, err := ioutil.ReadAll(r.Body)

				if err != nil {
					w.WriteHeader(503)
					w.Write(serverError(err.Error()))
				}

				assert.Equal(t, string(rb), stub.Body)

				w.WriteHeader(stub.Code)
				w.Write(data)

				found = true
				break
			}
		}

		if !found {
			fmt.Fprintf(os.Stderr, "Missing HTTP stub:\n")
			fmt.Fprintf(os.Stderr, "  %s %s\n", r.Method, r.URL.Path)
			t.Fail()

			w.WriteHeader(404)
			w.Write(serverError("stub not found"))
		}
	}))

	return ts
}
Beispiel #8
0
// Equal asserts that two objects are equal.
//
//    require.Equal(t, 123, 123, "123 and 123 should be equal")
func Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) {
	if !assert.Equal(t, expected, actual, msgAndArgs...) {
		t.FailNow()
	}
}