本文整理汇总了Golang中github.com/convox/rack/test.NewHandlerFunc函数的典型用法代码示例。如果您正苦于以下问题:Golang NewHandlerFunc函数的具体用法?Golang NewHandlerFunc怎么用?Golang NewHandlerFunc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewHandlerFunc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestFormationList
func TestFormationList(t *testing.T) {
models.Test(t, func() {
formation := structs.Formation{
structs.ProcessFormation{Name: "web", Count: 2, CPU: 128, Memory: 1024, Ports: []int{3000, 3001}},
structs.ProcessFormation{Name: "worker", Count: 3, CPU: 129, Memory: 1025, Ports: []int{4000, 4001}},
}
models.TestProvider.On("FormationList", "myapp").Return(formation, nil)
hf := test.NewHandlerFunc(controllers.HandlerFunc)
if assert.Nil(t, hf.Request("GET", "/apps/myapp/formation", nil)) {
hf.AssertCode(t, 200)
hf.AssertJSON(t, `[
{"balancer":"", "count":2, "cpu":128, "memory":1024, "name":"web", "ports":[3000,3001]},
{"balancer":"", "count":3, "cpu":129, "memory":1025, "name":"worker", "ports":[4000,4001]}
]`)
}
})
models.Test(t, func() {
models.TestProvider.On("FormationList", "myapp").Return(nil, fmt.Errorf("some error"))
hf := test.NewHandlerFunc(controllers.HandlerFunc)
if assert.Nil(t, hf.Request("GET", "/apps/myapp/formation", nil)) {
hf.AssertCode(t, 500)
hf.AssertError(t, "some error")
}
})
}
示例2: TestProcessStop
func TestProcessStop(t *testing.T) {
models.Test(t, func() {
models.TestProvider.On("ProcessStop", "myapp-staging", "p1234").Return(nil)
hf := test.NewHandlerFunc(controllers.HandlerFunc)
if assert.Nil(t, hf.Request("DELETE", "/apps/myapp-staging/processes/p1234", nil)) {
hf.AssertCode(t, 200)
hf.AssertJSON(t, `{"success":true}`)
}
})
models.Test(t, func() {
models.TestProvider.On("ProcessStop", "myapp-staging", "p1234").Return(test.ErrorNotFound("no such process"))
hf := test.NewHandlerFunc(controllers.HandlerFunc)
if assert.Nil(t, hf.Request("DELETE", "/apps/myapp-staging/processes/p1234", nil)) {
hf.AssertCode(t, 404)
hf.AssertError(t, "no such process")
}
})
models.Test(t, func() {
models.TestProvider.On("ProcessStop", "myapp-staging", "p1234").Return(fmt.Errorf("unknown error"))
hf := test.NewHandlerFunc(controllers.HandlerFunc)
if assert.Nil(t, hf.Request("DELETE", "/apps/myapp-staging/processes/p1234", nil)) {
hf.AssertCode(t, 500)
hf.AssertError(t, "unknown error")
}
})
}
示例3: TestProcessList
func TestProcessList(t *testing.T) {
models.Test(t, func() {
processes := structs.Processes{
structs.Process{
ID: "foo",
App: "myapp-staging",
Name: "procname",
Release: "R123",
Command: "ls -la",
Host: "127.0.0.1",
Image: "image:tag",
Instance: "i-1234",
Ports: []string{"80", "443"},
CPU: 0.345,
Memory: 0.456,
Started: time.Unix(1473483567, 0).UTC(),
},
}
models.TestProvider.On("ProcessList", "myapp-staging").Return(processes, nil)
hf := test.NewHandlerFunc(controllers.HandlerFunc)
if assert.Nil(t, hf.Request("GET", "/apps/myapp-staging/processes", nil)) {
hf.AssertCode(t, 200)
hf.AssertJSON(t, "[{\"app\":\"myapp-staging\",\"command\":\"ls -la\",\"cpu\":0.345,\"host\":\"127.0.0.1\",\"id\":\"foo\",\"image\":\"image:tag\",\"instance\":\"i-1234\",\"memory\":0.456,\"name\":\"procname\",\"ports\":[\"80\",\"443\"],\"release\":\"R123\",\"started\":\"2016-09-10T04:59:27Z\"}]")
}
})
models.Test(t, func() {
models.TestProvider.On("ProcessList", "myapp-staging").Return(nil, test.ErrorNotFound("no such process"))
hf := test.NewHandlerFunc(controllers.HandlerFunc)
if assert.Nil(t, hf.Request("GET", "/apps/myapp-staging/processes", nil)) {
hf.AssertCode(t, 404)
hf.AssertError(t, "no such process")
}
})
models.Test(t, func() {
models.TestProvider.On("ProcessList", "myapp-staging").Return(nil, fmt.Errorf("unknown error"))
hf := test.NewHandlerFunc(controllers.HandlerFunc)
if assert.Nil(t, hf.Request("GET", "/apps/myapp-staging/processes", nil)) {
hf.AssertCode(t, 500)
hf.AssertError(t, "unknown error")
}
})
}
示例4: TestFormationSetNonNumeric
func TestFormationSetNonNumeric(t *testing.T) {
models.Test(t, func() {
before := &structs.ProcessFormation{Name: "web", Count: 2, CPU: 128, Memory: 1024, Ports: []int{3000, 3001}}
models.TestProvider.On("FormationGet", "myapp", "web").Return(before, nil)
hf := test.NewHandlerFunc(controllers.HandlerFunc)
v := url.Values{}
v.Add("count", "foo")
if assert.Nil(t, hf.Request("POST", "/apps/myapp/formation/web", v)) {
hf.AssertCode(t, 403)
hf.AssertError(t, "count must be numeric")
}
})
models.Test(t, func() {
before := &structs.ProcessFormation{Name: "web", Count: 2, CPU: 128, Memory: 1024, Ports: []int{3000, 3001}}
models.TestProvider.On("FormationGet", "myapp", "web").Return(before, nil)
hf := test.NewHandlerFunc(controllers.HandlerFunc)
v := url.Values{}
v.Add("cpu", "foo")
if assert.Nil(t, hf.Request("POST", "/apps/myapp/formation/web", v)) {
hf.AssertCode(t, 403)
hf.AssertError(t, "cpu must be numeric")
}
})
models.Test(t, func() {
before := &structs.ProcessFormation{Name: "web", Count: 2, CPU: 128, Memory: 1024, Ports: []int{3000, 3001}}
models.TestProvider.On("FormationGet", "myapp", "web").Return(before, nil)
hf := test.NewHandlerFunc(controllers.HandlerFunc)
v := url.Values{}
v.Add("memory", "foo")
if assert.Nil(t, hf.Request("POST", "/apps/myapp/formation/web", v)) {
hf.AssertCode(t, 403)
hf.AssertError(t, "memory must be numeric")
}
})
}
示例5: TestInstanceList
func TestInstanceList(t *testing.T) {
models.Test(t, func() {
instances := structs.Instances{
structs.Instance{
Agent: true,
Cpu: 0.28,
Id: "test",
Memory: 0.18,
PrivateIp: "1.2.3.4",
Processes: 5,
PublicIp: "2.3.4.5",
Status: "running",
Started: time.Unix(1475610360, 0).UTC(),
},
}
models.TestProvider.On("InstanceList").Return(instances, nil)
hf := test.NewHandlerFunc(controllers.HandlerFunc)
if assert.Nil(t, hf.Request("GET", "/instances", nil)) {
hf.AssertCode(t, 200)
hf.AssertJSON(t, "[{\"agent\":true,\"cpu\":0.28,\"id\":\"test\",\"memory\":0.18,\"private-ip\":\"1.2.3.4\",\"processes\":5,\"public-ip\":\"2.3.4.5\",\"started\":\"2016-10-04T19:46:00Z\",\"status\":\"running\"}]")
}
})
}
示例6: TestReleaseList
func TestReleaseList(t *testing.T) {
models.Test(t, func() {
releases := structs.Releases{
structs.Release{
Id: "RVFETUHHKKD",
App: "httpd",
Build: "BHINCLZYYVN",
Env: "foo=bar",
Manifest: "web:\n image: httpd\n ports:\n - 80:80\n",
Created: time.Unix(1459780542, 627770380).UTC(),
},
structs.Release{
Id: "RFVZFLKVTYO",
App: "httpd",
Build: "BNOARQMVHUO",
Env: "foo=bar",
Manifest: "web:\n image: httpd\n ports:\n - 80:80\n",
Created: time.Unix(1459709199, 166694813).UTC(),
},
}
models.TestProvider.On("ReleaseList", "example", int64(20)).Return(releases, nil)
hf := test.NewHandlerFunc(controllers.HandlerFunc)
if assert.Nil(t, hf.Request("GET", "/apps/example/releases", nil)) {
hf.AssertCode(t, 200)
hf.AssertJSON(t, "[{\"app\":\"httpd\",\"build\":\"BHINCLZYYVN\",\"created\":\"2016-04-04T14:35:42.62777038Z\",\"env\":\"foo=bar\",\"id\":\"RVFETUHHKKD\",\"manifest\":\"web:\\n image: httpd\\n ports:\\n - 80:80\\n\"},{\"app\":\"httpd\",\"build\":\"BNOARQMVHUO\",\"created\":\"2016-04-03T18:46:39.166694813Z\",\"env\":\"foo=bar\",\"id\":\"RFVZFLKVTYO\",\"manifest\":\"web:\\n image: httpd\\n ports:\\n - 80:80\\n\"}]")
}
})
}
示例7: TestBuildDelete
func TestBuildDelete(t *testing.T) {
models.Test(t, func() {
build := &structs.Build{
App: "myapp",
Description: "desc",
Ended: time.Unix(1475611334, 0).UTC(),
Id: "B1234",
Logs: "",
Manifest: "",
Reason: "",
Release: "R2345",
Started: time.Unix(1475611334, 0).UTC(),
Status: "complete",
}
models.TestProvider.On("ReleaseDelete", "example", "B1234").Return(nil)
models.TestProvider.On("BuildDelete", "example", "B1234").Return(build, nil)
hf := test.NewHandlerFunc(controllers.HandlerFunc)
if assert.Nil(t, hf.Request("DELETE", "/apps/example/builds/B1234", nil)) {
hf.AssertCode(t, 200)
hf.AssertJSON(t, "{\"app\":\"myapp\",\"description\":\"desc\",\"ended\":\"2016-10-04T20:02:14Z\",\"id\":\"B1234\",\"logs\":\"\",\"manifest\":\"\",\"reason\":\"\",\"release\":\"R2345\",\"started\":\"2016-10-04T20:02:14Z\",\"status\":\"complete\"}")
}
})
}
示例8: TestSystemUpdateAutoscaleCount
func TestSystemUpdateAutoscaleCount(t *testing.T) {
models.Test(t, func() {
as := os.Getenv("AUTOSCALE")
os.Setenv("AUTOSCALE", "true")
defer os.Setenv("AUTOSCALE", as)
before := &structs.System{
Count: 3,
Name: "test",
Region: "us-test-1",
Status: "running",
Type: "t2.small",
Version: "dev",
}
models.TestProvider.On("SystemGet").Return(before, nil)
hf := test.NewHandlerFunc(controllers.HandlerFunc)
v := url.Values{}
v.Add("count", "5")
if assert.Nil(t, hf.Request("PUT", "/system", v)) {
hf.AssertCode(t, 403)
hf.AssertError(t, "scaling count prohibited when autoscale enabled")
}
})
}
示例9: TestSystemUpdateSaveError
func TestSystemUpdateSaveError(t *testing.T) {
models.Test(t, func() {
before := &structs.System{
Count: 3,
Name: "test",
Region: "us-test-1",
Status: "running",
Type: "t2.small",
Version: "dev",
}
change := structs.System{
Count: 4,
Name: "test",
Region: "us-test-1",
Status: "running",
Type: "t2.small",
Version: "dev",
}
models.TestProvider.On("SystemGet").Return(before, nil)
models.TestProvider.On("SystemSave", change).Return(fmt.Errorf("bad save"))
hf := test.NewHandlerFunc(controllers.HandlerFunc)
v := url.Values{}
v.Add("count", "4")
if assert.Nil(t, hf.Request("PUT", "/system", v)) {
hf.AssertCode(t, 500)
hf.AssertError(t, "bad save")
}
})
}
示例10: TestSystemUpdate
func TestSystemUpdate(t *testing.T) {
models.Test(t, func() {
before := &structs.System{
Count: 3,
Name: "test",
Region: "us-test-1",
Status: "running",
Type: "t2.small",
Version: "dev",
}
change := structs.System{
Count: 5,
Name: "test",
Region: "us-test-1",
Status: "running",
Type: "t2.test",
Version: "latest",
}
models.TestProvider.On("SystemGet").Return(before, nil)
models.TestProvider.On("SystemSave", change).Return(nil)
hf := test.NewHandlerFunc(controllers.HandlerFunc)
v := url.Values{}
v.Add("count", "5")
v.Add("type", "t2.test")
v.Add("version", "latest")
if assert.Nil(t, hf.Request("PUT", "/system", v)) {
hf.AssertCode(t, 200)
hf.AssertJSON(t, `{"count":5,"name":"test","region":"us-test-1","status":"running","type":"t2.test","version":"latest"}`)
}
})
}
示例11: TestSystemUpdateBadCount
func TestSystemUpdateBadCount(t *testing.T) {
models.Test(t, func() {
before := &structs.System{
Count: 3,
Name: "test",
Region: "us-test-1",
Status: "running",
Type: "t2.small",
Version: "dev",
}
models.TestProvider.On("SystemGet").Return(before, nil)
hf := test.NewHandlerFunc(controllers.HandlerFunc)
v := url.Values{}
v.Add("count", "foo")
if assert.Nil(t, hf.Request("PUT", "/system", v)) {
hf.AssertCode(t, 403)
hf.AssertError(t, "count must be numeric")
}
})
models.Test(t, func() {
before := &structs.System{
Count: 3,
Name: "test",
Region: "us-test-1",
Status: "running",
Type: "t2.small",
Version: "dev",
}
models.TestProvider.On("SystemGet").Return(before, nil)
hf := test.NewHandlerFunc(controllers.HandlerFunc)
v := url.Values{}
v.Add("count", "-2")
if assert.Nil(t, hf.Request("PUT", "/system", v)) {
hf.AssertCode(t, 403)
hf.AssertError(t, "count must be greater than 1")
}
})
}
示例12: TestProcessRunDetached
func TestProcessRunDetached(t *testing.T) {
opts := structs.ProcessRunOptions{
Command: "test-command",
Release: "R1234",
}
v := url.Values{}
v.Add("command", "test-command")
v.Add("release", "R1234")
models.Test(t, func() {
models.TestProvider.On("ProcessRun", "myapp-staging", "web", opts).Return("pid", nil)
hf := test.NewHandlerFunc(controllers.HandlerFunc)
if assert.Nil(t, hf.Request("POST", "/apps/myapp-staging/processes/web/run", v)) {
hf.AssertCode(t, 200)
hf.AssertJSON(t, `{"success":true}`)
}
})
models.Test(t, func() {
models.TestProvider.On("ProcessRun", "myapp-staging", "web", opts).Return("", test.ErrorNotFound("no such process"))
hf := test.NewHandlerFunc(controllers.HandlerFunc)
if assert.Nil(t, hf.Request("POST", "/apps/myapp-staging/processes/web/run", v)) {
hf.AssertCode(t, 404)
hf.AssertError(t, "no such process")
}
})
models.Test(t, func() {
models.TestProvider.On("ProcessRun", "myapp-staging", "web", opts).Return("", fmt.Errorf("unknown error"))
hf := test.NewHandlerFunc(controllers.HandlerFunc)
if assert.Nil(t, hf.Request("POST", "/apps/myapp-staging/processes/web/run", v)) {
hf.AssertCode(t, 500)
hf.AssertError(t, "unknown error")
}
})
}
示例13: TestFormationListError
func TestFormationListError(t *testing.T) {
models.TestProvider = &provider.TestProvider{}
models.TestProvider.On("FormationList", "myapp").Return(nil, fmt.Errorf("some error"))
hf := test.NewHandlerFunc(controllers.HandlerFunc)
hf.Request("GET", "/apps/myapp/formation", nil)
hf.AssertCode(t, 500)
hf.AssertError(t, "some error")
models.TestProvider.AssertExpectations(t)
}
示例14: TestSystemUpdateRackFetchError
func TestSystemUpdateRackFetchError(t *testing.T) {
models.Test(t, func() {
models.TestProvider.On("SystemGet").Return(nil, fmt.Errorf("some error"))
hf := test.NewHandlerFunc(controllers.HandlerFunc)
if assert.Nil(t, hf.Request("PUT", "/system", nil)) {
hf.AssertCode(t, 500)
hf.AssertError(t, "some error")
}
})
}
示例15: TestSystemReleasesError
func TestSystemReleasesError(t *testing.T) {
models.Test(t, func() {
models.TestProvider.On("SystemReleases").Return(nil, fmt.Errorf("some error"))
hf := test.NewHandlerFunc(controllers.HandlerFunc)
if assert.Nil(t, hf.Request("GET", "/system/releases", nil)) {
hf.AssertCode(t, 500)
hf.AssertError(t, "some error")
}
})
}