本文整理汇总了Golang中github.com/convox/rack/test.HTTPBody函数的典型用法代码示例。如果您正苦于以下问题:Golang HTTPBody函数的具体用法?Golang HTTPBody怎么用?Golang HTTPBody使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HTTPBody函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestInstanceTerminate
func TestInstanceTerminate(t *testing.T) {
// set current provider
testProvider := &provider.TestProviderRunner{}
provider.CurrentProvider = testProvider
defer func() {
//TODO: remove: as we arent updating all tests we need tos et current provider back to a
//clean default one (I miss rspec before)
provider.CurrentProvider = new(provider.TestProviderRunner)
}()
// setup expectations on current provider
testProvider.On("SystemGet").Return(nil, nil)
os.Setenv("RACK", "convox-test")
aws := test.StubAws(
test.DeleteInstanceCycle("i-4a5513f4"),
)
defer aws.Close()
body := test.HTTPBody("DELETE", "http://convox/instances/i-4a5513f4", nil)
var resp map[string]bool
err := json.Unmarshal([]byte(body), &resp)
if assert.Nil(t, err) {
assert.Equal(t, true, resp["success"])
}
}
示例2: TestInstanceList
func TestInstanceList(t *testing.T) {
// set current provider
testProvider := &provider.TestProviderRunner{
Instances: []structs.Instance{
structs.Instance{},
structs.Instance{},
structs.Instance{},
},
}
provider.CurrentProvider = testProvider
defer func() {
//TODO: remove: as we arent updating all tests we need tos et current provider back to a
//clean default one (I miss rspec before)
provider.CurrentProvider = new(provider.TestProviderRunner)
}()
// setup expectations on current provider
testProvider.On("InstanceList").Return(testProvider.Instances, nil)
os.Setenv("RACK", "convox-test")
os.Setenv("CLUSTER", "convox-test-cluster")
body := test.HTTPBody("GET", "http://convox/instances", nil)
var resp []client.Instance
err := json.Unmarshal([]byte(body), &resp)
if assert.Nil(t, err) {
assert.Equal(t, 3, len(resp))
}
}
示例3: TestAppCreate
// Test the primary path: creating an app on a `convox` rack
// Return to testing against a `convox-test` rack afterwards
func TestAppCreate(t *testing.T) {
r := os.Getenv("RACK")
os.Setenv("RACK", "convox")
defer os.Setenv("RACK", r)
aws := test.StubAws(
test.DescribeStackNotFound("application"),
test.CreateAppStackCycle("convox-application"),
test.DescribeAppStackCycle("convox-application"),
)
defer aws.Close()
val := url.Values{"name": []string{"application"}}
body := test.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"])
}
}
}
示例4: TestFormationScaleMemory2048
// post memory=2048 should error
func TestFormationScaleMemory2048(t *testing.T) {
// set current provider
testProvider := &provider.TestProviderRunner{
Capacity: structs.Capacity{
InstanceMemory: 1024,
},
}
provider.CurrentProvider = testProvider
defer func() {
//TODO: remove: as we arent updating all tests we need tos et current provider back to a
//clean default one (I miss rspec before)
provider.CurrentProvider = new(provider.TestProviderRunner)
}()
testProvider.On("CapacityGet").Return(testProvider.Capacity, nil)
aws := test.StubAws(
test.DescribeAppStackCycle("convox-test-application"),
test.DescribeAppStackCycle("convox-test-application"),
test.GetItemAppReleaseCycle("convox-test-application"),
test.UpdateAppStackCycle("convox-test-application", "1", "512"),
)
defer aws.Close()
provider.TestProvider.Capacity = structs.Capacity{
InstanceMemory: 1024,
}
val := url.Values{"count": []string{""}, "memory": []string{"2048"}}
body := test.HTTPBody("POST", "http://convox/apps/application/formation/main", val)
assert.Equal(t, `{"error":"requested memory 2048 greater than instance size 1024"}`, body)
}
示例5: TestFormationScaleCount0
// post count=0 should set MainDesiredCount=0 in the stack update
func TestFormationScaleCount0(t *testing.T) {
// set current provider
testProvider := &provider.TestProviderRunner{
Capacity: structs.Capacity{},
}
provider.CurrentProvider = testProvider
defer func() {
//TODO: remove: as we arent updating all tests we need tos et current provider back to a
//clean default one (I miss rspec before)
provider.CurrentProvider = new(provider.TestProviderRunner)
}()
// setup expectations on current provider
testProvider.On("CapacityGet").Return(testProvider.Capacity, nil)
aws := test.StubAws(
test.DescribeAppStackCycle("convox-test-application"),
test.DescribeAppStackCycle("convox-test-application"),
test.GetItemAppReleaseCycle("convox-test-application"),
test.UpdateAppStackCycle("convox-test-application", "0", "256"),
)
defer aws.Close()
val := url.Values{"count": []string{"0"}, "memory": []string{""}}
body := test.HTTPBody("POST", "http://convox/apps/application/formation/main", val)
assert.Equal(t, `{"success":true}`, body)
}
示例6: TestBuildDelete
func TestBuildDelete(t *testing.T) {
models.TestProvider = &provider.TestProvider{
App: structs.App{
Name: "app-name",
Release: "release-id",
},
Build: structs.Build{
Id: "build-id",
},
Release: structs.Release{
Id: "release-id",
Build: "not-build-id",
},
}
// setup expectations on current provider
models.TestProvider.On("AppGet", "app-name").Return(&models.TestProvider.App, nil)
models.TestProvider.On("BuildGet", "app-name", "build-id").Return(&models.TestProvider.Build, nil)
models.TestProvider.On("ReleaseGet", "app-name", "release-id").Return(&models.TestProvider.Release, nil)
models.TestProvider.On("BuildDelete", "app-name", "build-id").Return(&models.TestProvider.Build, nil)
models.TestProvider.On("ReleaseDelete", "app-name", "build-id").Return(nil)
// make request
body := test.HTTPBody("DELETE", "http://convox/apps/app-name/builds/build-id", nil)
// assert on expectations
models.TestProvider.AssertExpectations(t)
// assert on response
resp := new(structs.Build)
err := json.Unmarshal([]byte(body), resp)
if assert.Nil(t, err) {
assert.Equal(t, "build-id", resp.Id)
}
}
示例7: TestBuildDelete
func TestBuildDelete(t *testing.T) {
// set current provider
testProvider := &provider.TestProviderRunner{
Build: structs.Build{
Id: "build-id",
},
}
provider.CurrentProvider = testProvider
defer func() {
//TODO: remove: as we arent updating all tests we need tos et current provider back to a
//clean default one (I miss rspec before)
provider.CurrentProvider = new(provider.TestProviderRunner)
}()
// setup expectations on current provider
testProvider.On("BuildDelete", "app-name", "build-id").Return(&testProvider.Build, nil)
// make request
body := test.HTTPBody("DELETE", "http://convox/apps/app-name/builds/build-id", nil)
// assert on expectations
testProvider.AssertExpectations(t)
// assert on response
resp := new(structs.Build)
err := json.Unmarshal([]byte(body), resp)
if assert.Nil(t, err) {
assert.Equal(t, "build-id", resp.Id)
}
}
示例8: TestInstanceList
func TestInstanceList(t *testing.T) {
models.TestProvider = &provider.TestProvider{
Instances: []structs.Instance{
structs.Instance{},
structs.Instance{},
structs.Instance{},
},
}
// setup expectations on current provider
models.TestProvider.On("InstanceList").Return(models.TestProvider.Instances, nil)
os.Setenv("RACK", "convox-test")
os.Setenv("CLUSTER", "convox-test-cluster")
body := test.HTTPBody("GET", "http://convox/instances", nil)
var resp []client.Instance
err := json.Unmarshal([]byte(body), &resp)
if assert.Nil(t, err) {
assert.Equal(t, 3, len(resp))
}
}
示例9: TestBuildDeleteActive
func TestBuildDeleteActive(t *testing.T) {
models.TestProvider = &provider.TestProvider{
App: structs.App{
Name: "httpd",
Release: "release-id",
},
Build: structs.Build{
Id: "BHINCLZYYVN",
},
Release: structs.Release{
Id: "release-id",
Build: "BHINCLZYYVN",
},
}
models.TestProvider.On("AppGet", "httpd").Return(&models.TestProvider.App, nil)
models.TestProvider.On("BuildGet", "httpd", "BHINCLZYYVN").Return(&models.TestProvider.Build, nil)
models.TestProvider.On("ReleaseGet", "httpd", "release-id").Return(&models.TestProvider.Release, nil)
body := test.HTTPBody("DELETE", "http://convox/apps/httpd/builds/BHINCLZYYVN", nil)
// assert on expectations
models.TestProvider.AssertExpectations(t)
// assert on response
resp := make(map[string]string)
err := json.Unmarshal([]byte(body), &resp)
if assert.Nil(t, err) {
fmt.Fprintf(os.Stderr, "%s\n", resp)
assert.Equal(t, "cannot delete build contained in active release", resp["error"])
}
}
示例10: TestProcessesListWithDetached
func TestProcessesListWithDetached(t *testing.T) {
models.TestProvider = &provider.TestProvider{
Instances: []structs.Instance{
structs.Instance{},
structs.Instance{},
structs.Instance{},
},
}
// setup expectations on current provider
models.TestProvider.On("InstanceList").Return(models.TestProvider.Instances, nil)
os.Setenv("RACK", "convox-test")
os.Setenv("CLUSTER", "convox-test-cluster")
aws := test.StubAws(
test.DescribeAppStackCycle("convox-test-myapp-staging"),
test.DescribeAppStackCycle("convox-test-myapp-staging"),
test.DescribeAppStackResourcesCycle("convox-test-myapp-staging"),
test.ListContainerInstancesCycle("convox-test-cluster"),
test.DescribeContainerInstancesCycle("convox-test-cluster"),
test.DescribeInstancesCycle(),
test.ListTasksCycle("convox-test-cluster", "convox-test-myapp-staging-worker-SCELGCIYSKF"),
test.DescribeTasksCycle("convox-test-cluster"),
test.ListTasksOneoffCycle("convox-test-cluster"),
test.DescribeTasksOneoffCycle("convox-test-cluster"),
test.DescribeTaskDefinitionCycle("convox-test-cluster"),
test.DescribeTaskDefinitionCycle("convox-test-cluster"),
test.DescribeAppStackResourcesCycle("convox-test-myapp-staging"),
test.DescribeServicesCycle("convox-test-cluster"),
)
defer aws.Close()
docker := test.StubDocker(
// query for every ECS task to get docker id, command, created
test.ListECSContainersCycle(),
test.ListECSOneoffContainersCycle(),
// query every instance for one-off containers
test.ListOneoffContainersEmptyCycle(),
test.ListOneoffContainersEmptyCycle(),
test.ListOneoffContainersEmptyCycle(),
)
defer docker.Close()
body := test.HTTPBody("GET", "http://convox/apps/myapp-staging/processes", url.Values{})
var resp client.Processes
err := json.Unmarshal([]byte(body), &resp)
if assert.Nil(t, err) {
assert.Equal(t, 2, len(resp))
assert.Equal(t, "echo 1", resp[0].Command)
assert.Equal(t, "/bin/sh -c yes", resp[1].Command)
}
}
示例11: TestProcessesList
func TestProcessesList(t *testing.T) {
// set current provider
models.TestProvider = &provider.TestProvider{
Instances: []structs.Instance{
structs.Instance{},
structs.Instance{},
structs.Instance{},
},
}
// setup expectations on current provider
models.TestProvider.On("InstanceList").Return(models.TestProvider.Instances, nil)
aws := test.StubAws(
test.DescribeAppStackCycle("convox-test-myapp-staging"),
test.DescribeAppStackCycle("convox-test-myapp-staging"),
test.DescribeAppStackResourcesCycle("convox-test-myapp-staging"),
test.ListContainerInstancesCycle("convox-test-cluster"),
test.DescribeContainerInstancesCycle("convox-test-cluster"),
test.DescribeInstancesCycle(),
test.ListTasksCycle("convox-test-cluster", "convox-test-myapp-staging-worker-SCELGCIYSKF"),
test.DescribeTasksCycle("convox-test-cluster"),
test.ListTasksOneoffEmptyCycle("convox-test-cluster"),
test.DescribeTaskDefinitionCycle("convox-test-cluster"),
test.DescribeAppStackResourcesCycle("convox-test-myapp-staging"),
test.DescribeServicesCycle("convox-test-cluster"),
)
defer aws.Close()
docker := test.StubDocker(
// query for every ECS task to get docker id, command, created
test.ListECSContainersCycle(),
// query every instance for one-off containers
test.ListOneoffContainersEmptyCycle(),
test.ListOneoffContainersEmptyCycle(),
test.ListOneoffContainersEmptyCycle(),
// query for every container to get CPU and Memory stats
test.StatsCycle(),
)
defer docker.Close()
v := url.Values{}
v.Add("stats", "true")
body := test.HTTPBody("GET", "http://convox/apps/myapp-staging/processes", v)
var resp client.Processes
err := json.Unmarshal([]byte(body), &resp)
if assert.Nil(t, err) {
assert.Equal(t, 1, len(resp))
assert.Equal(t, 0.0974, resp[0].Memory)
}
}
示例12: TestGetProcessesWithDeployments
func TestGetProcessesWithDeployments(t *testing.T) {
os.Setenv("RACK", "convox-test")
os.Setenv("CLUSTER", "convox-test-cluster")
aws := test.StubAws(
test.DescribeAppStackCycle("convox-test-myapp-staging"),
test.DescribeAppStackCycle("convox-test-myapp-staging"),
test.DescribeAppStackResourcesCycle("convox-test-myapp-staging"),
test.ListContainerInstancesCycle("convox-test-cluster"),
test.DescribeContainerInstancesCycle("convox-test-cluster"),
test.DescribeInstancesCycle(),
test.ListTasksCycle("convox-test-cluster", "convox-test-myapp-staging-worker-SCELGCIYSKF"),
test.DescribeTasksCycle("convox-test-cluster"),
test.ListTasksOneoffEmptyCycle("convox-test-cluster"),
test.DescribeTaskDefinitionCycle("convox-test-cluster"),
test.DescribeAppStackResourcesCycle("convox-test-myapp-staging"),
test.DescribeServicesWithDeploymentsCycle("convox-test-cluster"),
test.DescribeTaskDefinition3Cycle("convox-test-cluster"),
test.DescribeTaskDefinition1Cycle("convox-test-cluster"),
)
defer aws.Close()
docker := test.StubDocker(
// query for every ECS task to get docker id, command, created
test.ListECSContainersCycle(),
// query every instance for one-off containers
test.ListOneoffContainersEmptyCycle(),
test.ListOneoffContainersEmptyCycle(),
test.ListOneoffContainersEmptyCycle(),
// query for every container to get CPU and Memory stats
test.StatsCycle(),
)
defer docker.Close()
v := url.Values{}
v.Add("stats", "true")
body := test.HTTPBody("GET", "http://convox/apps/myapp-staging/processes", v)
var resp client.Processes
err := json.Unmarshal([]byte(body), &resp)
if assert.Nil(t, err) {
assert.Equal(t, 2, len(resp))
assert.Equal(t, "8dfafdbc3a40", resp[0].Id)
assert.Equal(t, 0.0974, resp[0].Memory)
assert.Equal(t, "pending", resp[1].Id)
assert.EqualValues(t, 0, resp[1].Memory)
}
}
示例13: TestAppList
func TestAppList(t *testing.T) {
aws := test.StubAws(test.DescribeStackCycleWithoutQuery("convox-test-bar"))
defer aws.Close()
body := test.HTTPBody("GET", "http://convox/apps", nil)
var resp []map[string]string
err := json.Unmarshal([]byte(body), &resp)
if assert.Nil(t, err) {
assert.Equal(t, "bar", resp[0]["name"])
assert.Equal(t, "running", resp[0]["status"])
}
}
示例14: TestFormationScaleCount0
// post count=0 should set MainDesiredCount=0 in the stack update
func TestFormationScaleCount0(t *testing.T) {
aws := test.StubAws(
test.DescribeAppStackCycle("convox-test-application"),
test.DescribeAppStackCycle("convox-test-application"),
test.GetItemAppReleaseCycle("convox-test-application"),
test.UpdateAppStackCycle("convox-test-application", "0", "256"),
)
defer aws.Close()
val := url.Values{"count": []string{"0"}, "memory": []string{""}}
body := test.HTTPBody("POST", "http://convox/apps/application/formation/main", val)
assert.Equal(t, `{"success":true}`, body)
}
示例15: TestFormationScaleMemoryInvalid
// post memory=foo should 403
func TestFormationScaleMemoryInvalid(t *testing.T) {
aws := test.StubAws(
test.DescribeAppStackCycle("convox-test-application"),
test.DescribeAppStackCycle("convox-test-application"),
test.GetItemAppReleaseCycle("convox-test-application"),
test.UpdateAppStackCycle("convox-test-application", "1", "256"),
)
defer aws.Close()
val := url.Values{"count": []string{""}, "memory": []string{"foo"}}
body := test.HTTPBody("POST", "http://convox/apps/application/formation/main", val)
assert.Equal(t, `{"error":"memory must be numeric"}`, body)
}