本文整理汇总了Golang中github.com/convox/rack/test.NewHandlerFunc函数的典型用法代码示例。如果您正苦于以下问题:Golang NewHandlerFunc函数的具体用法?Golang NewHandlerFunc怎么用?Golang NewHandlerFunc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewHandlerFunc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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")
}
})
}
开发者ID:convox,项目名称:rack,代码行数:31,代码来源:formation_test.go
示例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")
}
})
}
开发者ID:convox,项目名称:rack,代码行数:34,代码来源:processes_test.go
示例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")
}
})
}
开发者ID:convox,项目名称:rack,代码行数:51,代码来源:processes_test.go
示例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")
}
})
}
开发者ID:gmelika,项目名称:rack,代码行数:49,代码来源:formation_test.go
示例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\"}]")
}
})
}
开发者ID:convox,项目名称:rack,代码行数:26,代码来源:instances_test.go
示例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\"}]")
}
})
}
开发者ID:convox,项目名称:rack,代码行数:31,代码来源:releases_test.go
示例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\"}")
}
})
}
开发者ID:convox,项目名称:rack,代码行数:26,代码来源:builds_test.go
示例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")
}
})
}
开发者ID:gmelika,项目名称:rack,代码行数:28,代码来源:system_test.go
示例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")
}
})
}
开发者ID:gmelika,项目名称:rack,代码行数:33,代码来源:system_test.go
示例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"}`)
}
})
}
开发者ID:gmelika,项目名称:rack,代码行数:35,代码来源:system_test.go
示例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")
}
})
}
开发者ID:gmelika,项目名称:rack,代码行数:47,代码来源:system_test.go
示例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")
}
})
}
开发者ID:convox,项目名称:rack,代码行数:43,代码来源:processes_test.go
示例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)
}
开发者ID:gmelika,项目名称:rack,代码行数:12,代码来源:formation_test.go
示例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")
}
})
}
开发者ID:gmelika,项目名称:rack,代码行数:12,代码来源:system_test.go
示例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")
}
})
}
开发者ID:gmelika,项目名称:rack,代码行数:12,代码来源:system_test.go
示例16: TestInstanceTerminate
func TestInstanceTerminate(t *testing.T) {
models.Test(t, func() {
models.TestProvider.On("InstanceTerminate", "i-1234").Return(nil)
hf := test.NewHandlerFunc(controllers.HandlerFunc)
if assert.Nil(t, hf.Request("DELETE", "/instances/i-1234", nil)) {
hf.AssertCode(t, 200)
hf.AssertSuccess(t)
}
})
models.Test(t, func() {
models.TestProvider.On("InstanceTerminate", "i-1234").Return(fmt.Errorf("broken"))
hf := test.NewHandlerFunc(controllers.HandlerFunc)
if assert.Nil(t, hf.Request("DELETE", "/instances/i-1234", nil)) {
hf.AssertCode(t, 500)
hf.AssertError(t, "broken")
}
})
}
开发者ID:convox,项目名称:rack,代码行数:23,代码来源:instances_test.go
示例17: TestFormationSetFailedGet
func TestFormationSetFailedGet(t *testing.T) {
models.Test(t, func() {
models.TestProvider.On("FormationGet", "myapp", "web").Return(nil, fmt.Errorf("could not fetch"))
hf := test.NewHandlerFunc(controllers.HandlerFunc)
v := url.Values{}
v.Add("count", "4")
v.Add("cpu", "200")
v.Add("memory", "300")
if assert.Nil(t, hf.Request("POST", "/apps/myapp/formation/web", v)) {
hf.AssertCode(t, 500)
hf.AssertError(t, "could not fetch")
}
})
}
开发者ID:gmelika,项目名称:rack,代码行数:17,代码来源:formation_test.go
示例18: TestFormationSetOne
func TestFormationSetOne(t *testing.T) {
models.Test(t, func() {
before := &structs.ProcessFormation{Name: "web", Count: 2, CPU: 128, Memory: 1024, Ports: []int{3000, 3001}}
after := &structs.ProcessFormation{Name: "web", Count: 2, CPU: 200, Memory: 1024, Ports: []int{3000, 3001}}
models.TestProvider.On("FormationGet", "myapp", "web").Return(before, nil)
models.TestProvider.On("FormationSave", "myapp", after).Return(nil)
hf := test.NewHandlerFunc(controllers.HandlerFunc)
v := url.Values{}
v.Add("cpu", "200")
if assert.Nil(t, hf.Request("POST", "/apps/myapp/formation/web", v)) {
hf.AssertCode(t, 200)
hf.AssertSuccess(t)
}
})
}
开发者ID:gmelika,项目名称:rack,代码行数:19,代码来源:formation_test.go
示例19: TestSystemReleases
func TestSystemReleases(t *testing.T) {
models.Test(t, func() {
releases := structs.Releases{
structs.Release{Id: "R0000001", App: "test", Build: "B0000001", Created: time.Date(2016, 3, 4, 5, 6, 7, 12, time.UTC)},
structs.Release{Id: "R0000002", App: "test", Build: "B0000002", Created: time.Date(2016, 3, 4, 9, 6, 7, 14, time.UTC)},
}
models.TestProvider.On("SystemReleases").Return(releases, nil)
hf := test.NewHandlerFunc(controllers.HandlerFunc)
if assert.Nil(t, hf.Request("GET", "/system/releases", nil)) {
hf.AssertCode(t, 200)
hf.AssertJSON(t, `[
{"app":"test","build":"B0000001","created":"2016-03-04T05:06:07.000000012Z","env":"","id":"R0000001","manifest":""},
{"app":"test","build":"B0000002","created":"2016-03-04T09:06:07.000000014Z","env":"","id":"R0000002","manifest":""}
]`)
}
})
}
开发者ID:gmelika,项目名称:rack,代码行数:20,代码来源:system_test.go
示例20: TestSystemShow
func TestSystemShow(t *testing.T) {
models.Test(t, func() {
system := &structs.System{
Count: 3,
Name: "test",
Region: "us-test-1",
Status: "running",
Type: "t2.small",
Version: "dev",
}
models.TestProvider.On("SystemGet").Return(system, nil)
hf := test.NewHandlerFunc(controllers.HandlerFunc)
if assert.Nil(t, hf.Request("GET", "/system", nil)) {
hf.AssertCode(t, 200)
hf.AssertJSON(t, `{"count":3,"name":"test","region":"us-test-1","status":"running","type":"t2.small","version":"dev"}`)
}
})
}
开发者ID:gmelika,项目名称:rack,代码行数:21,代码来源:system_test.go
注:本文中的github.com/convox/rack/test.NewHandlerFunc函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论