本文整理汇总了Golang中github.com/rackspace/gophercloud/testhelper.CheckNoErr函数的典型用法代码示例。如果您正苦于以下问题:Golang CheckNoErr函数的具体用法?Golang CheckNoErr怎么用?Golang CheckNoErr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CheckNoErr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestWaitForStatus
func TestWaitForStatus(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/volumes/1234", func(w http.ResponseWriter, r *http.Request) {
time.Sleep(3 * time.Second)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `
{
"volume": {
"display_name": "vol-001",
"id": "1234",
"status":"available"
}
}`)
})
err := WaitForStatus(client.ServiceClient(), "1234", "available", 0)
if err == nil {
t.Errorf("Expected error: 'Time Out in WaitFor'")
}
err = WaitForStatus(client.ServiceClient(), "1234", "available", 6)
th.CheckNoErr(t, err)
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:26,代码来源:util_test.go
示例2: TestWaitForStatus
func TestWaitForStatus(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/servers/4321", func(w http.ResponseWriter, r *http.Request) {
time.Sleep(2 * time.Second)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `
{
"server": {
"name": "the-server",
"id": "4321",
"status": "ACTIVE"
}
}`)
})
err := WaitForStatus(client.ServiceClient(), "4321", "ACTIVE", 0)
if err == nil {
t.Errorf("Expected error: 'Time Out in WaitFor'")
}
err = WaitForStatus(client.ServiceClient(), "4321", "ACTIVE", 3)
th.CheckNoErr(t, err)
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:26,代码来源:util_test.go
示例3: TestBuildHeaders
func TestBuildHeaders(t *testing.T) {
testStruct := struct {
Accept string `h:"Accept"`
Num int `h:"Number,required"`
Style bool `h:"Style"`
}{
Accept: "application/json",
Num: 4,
Style: true,
}
expected := map[string]string{"Accept": "application/json", "Number": "4", "Style": "true"}
actual, err := BuildHeaders(&testStruct)
th.CheckNoErr(t, err)
th.CheckDeepEquals(t, expected, actual)
testStruct.Num = 0
_, err = BuildHeaders(&testStruct)
if err == nil {
t.Errorf("Expected error: 'Required header not set'")
}
_, err = BuildHeaders(map[string]interface{}{"Number": 4})
if err == nil {
t.Errorf("Expected error: 'Options type is not a struct'")
}
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:26,代码来源:params_test.go
示例4: TestGetHomeDocument
func TestGetHomeDocument(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
os.HandleGetSuccessfully(t)
actual, err := Get(fake.ServiceClient()).Extract()
th.CheckNoErr(t, err)
expected := os.HomeDocument{
"rel/cdn": map[string]interface{}{
"href-template": "services{?marker,limit}",
"href-vars": map[string]interface{}{
"marker": "param/marker",
"limit": "param/limit",
},
"hints": map[string]interface{}{
"allow": []string{"GET"},
"formats": map[string]interface{}{
"application/json": map[string]interface{}{},
},
},
},
}
th.CheckDeepEquals(t, expected, *actual)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:25,代码来源:delegate_test.go
示例5: TestProjectCRUDOperations
func TestProjectCRUDOperations(t *testing.T) {
serviceClient := createAuthenticatedClient(t)
if serviceClient == nil {
return
}
// Create project
opts := projects.ProjectOpts{
Enabled: true,
Name: "Test project",
Description: "This is test project",
}
project, err := projects.Create(serviceClient, opts).Extract()
th.AssertNoErr(t, err)
defer projects.Delete(serviceClient, project.ID)
th.AssertEquals(t, project.Enabled, true)
th.AssertEquals(t, project.Name, "Test project")
th.AssertEquals(t, project.Description, "This is test project")
// List projects
pager := projects.List(serviceClient, projects.ListOpts{})
err = pager.EachPage(func(page pagination.Page) (bool, error) {
t.Logf("--- Page ---")
projectList, err := projects.ExtractProjects(page)
th.AssertNoErr(t, err)
for _, p := range projectList {
t.Logf("Project: ID [%s] Name [%s] Is enabled? [%s]",
p.ID, p.Name, p.Enabled)
}
return true, nil
})
th.CheckNoErr(t, err)
projectID := project.ID
// Get a project
if projectID == "" {
t.Fatalf("In order to retrieve a project, the ProjectID must be set")
}
project, err = projects.Get(serviceClient, projectID).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, project.ID, projectID)
th.AssertEquals(t, project.DomainID, "")
th.AssertEquals(t, project.ParentID, "")
th.AssertEquals(t, project.Enabled, true)
th.AssertEquals(t, project.Name, "Test project")
th.AssertEquals(t, project.Description, "This is test project")
// Update project
project, err = projects.Update(serviceClient, projectID, projects.ProjectOpts{Name: "New test project name"}).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, project.Name, "New test project name")
// Delete project
res := projects.Delete(serviceClient, projectID)
th.AssertNoErr(t, res.Err)
}
开发者ID:cloudwan,项目名称:gophercloud,代码行数:59,代码来源:project_test.go
示例6: TestDeleteContainers
func TestDeleteContainers(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
os.HandleDeleteContainerSuccessfully(t)
res := Delete(fake.ServiceClient(), "testContainer")
th.CheckNoErr(t, res.Err)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:8,代码来源:delegate_test.go
示例7: TestPing
func TestPing(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
os.HandlePingSuccessfully(t)
err := Ping(fake.ServiceClient()).ExtractErr()
th.CheckNoErr(t, err)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:8,代码来源:delegate_test.go
示例8: TestGetContainers
func TestGetContainers(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
os.HandleGetContainerSuccessfully(t)
_, err := Get(fake.ServiceClient(), "testContainer").ExtractMetadata()
th.CheckNoErr(t, err)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:8,代码来源:delegate_test.go
示例9: TestGetAccounts
func TestGetAccounts(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
os.HandleGetAccountSuccessfully(t)
options := &UpdateOpts{Metadata: map[string]string{"gophercloud-test": "accounts"}}
res := Update(fake.ServiceClient(), options)
th.CheckNoErr(t, res.Err)
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:9,代码来源:delegate_test.go
示例10: TestUpdateContainers
func TestUpdateContainers(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
os.HandleUpdateContainerSuccessfully(t)
options := &os.UpdateOpts{Metadata: map[string]string{"foo": "bar"}}
res := Update(fake.ServiceClient(), "testContainer", options)
th.CheckNoErr(t, res.Err)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:9,代码来源:delegate_test.go
示例11: TestCreateContainer
func TestCreateContainer(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleCreateContainerSuccessfully(t)
options := CreateOpts{ContentType: "application/json", Metadata: map[string]string{"foo": "bar"}}
res := Create(fake.ServiceClient(), "testContainer", options)
th.CheckNoErr(t, res.Err)
th.CheckEquals(t, "bar", res.Header["X-Container-Meta-Foo"][0])
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:10,代码来源:requests_test.go
示例12: TestUpdateAccounts
func TestUpdateAccounts(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
os.HandleUpdateAccountSuccessfully(t)
expected := map[string]string{"Foo": "bar"}
actual, err := Get(fake.ServiceClient()).ExtractMetadata()
th.CheckNoErr(t, err)
th.CheckDeepEquals(t, expected, actual)
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:10,代码来源:delegate_test.go
示例13: TestUpdateCDNContainer
func TestUpdateCDNContainer(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
os.HandleUpdateContainerSuccessfully(t)
options := &UpdateOpts{TTL: 3600}
res := Update(fake.ServiceClient(), "testContainer", options)
th.CheckNoErr(t, res.Err)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:10,代码来源:delegate_test.go
示例14: TestNetworkCRUDOperations
func TestNetworkCRUDOperations(t *testing.T) {
Setup(t)
defer Teardown()
// Create a network
n, err := networks.Create(Client, networks.CreateOpts{Name: "sample_network", AdminStateUp: networks.Up}).Extract()
th.AssertNoErr(t, err)
defer networks.Delete(Client, n.ID)
th.AssertEquals(t, n.Name, "sample_network")
th.AssertEquals(t, n.AdminStateUp, true)
networkID := n.ID
// List networks
pager := networks.List(Client, networks.ListOpts{Limit: 2})
err = pager.EachPage(func(page pagination.Page) (bool, error) {
t.Logf("--- Page ---")
networkList, err := networks.ExtractNetworks(page)
th.AssertNoErr(t, err)
for _, n := range networkList {
t.Logf("Network: ID [%s] Name [%s] Status [%s] Is shared? [%s]",
n.ID, n.Name, n.Status, strconv.FormatBool(n.Shared))
}
return true, nil
})
th.CheckNoErr(t, err)
// Get a network
if networkID == "" {
t.Fatalf("In order to retrieve a network, the NetworkID must be set")
}
n, err = networks.Get(Client, networkID).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, n.Status, "ACTIVE")
th.AssertDeepEquals(t, n.Subnets, []string{})
th.AssertEquals(t, n.Name, "sample_network")
th.AssertEquals(t, n.AdminStateUp, true)
th.AssertEquals(t, n.Shared, false)
th.AssertEquals(t, n.ID, networkID)
// Update network
n, err = networks.Update(Client, networkID, networks.UpdateOpts{Name: "new_network_name"}).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, n.Name, "new_network_name")
// Delete network
res := networks.Delete(Client, networkID)
th.AssertNoErr(t, res.Err)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:51,代码来源:network_test.go
示例15: TestEnumerateSinglePaged
func TestEnumerateSinglePaged(t *testing.T) {
callCount := 0
pager := setupSinglePaged()
defer testhelper.TeardownHTTP()
err := pager.EachPage(func(page Page) (bool, error) {
callCount++
expected := []int{1, 2, 3}
actual, err := ExtractSingleInts(page)
testhelper.AssertNoErr(t, err)
testhelper.CheckDeepEquals(t, expected, actual)
return true, nil
})
testhelper.CheckNoErr(t, err)
testhelper.CheckEquals(t, 1, callCount)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:17,代码来源:single_test.go
示例16: TestListAPIVersions
func TestListAPIVersions(t *testing.T) {
Setup(t)
defer Teardown()
pager := apiversions.ListVersions(Client)
err := pager.EachPage(func(page pagination.Page) (bool, error) {
t.Logf("--- Page ---")
versions, err := apiversions.ExtractAPIVersions(page)
th.AssertNoErr(t, err)
for _, v := range versions {
t.Logf("API Version: ID [%s] Status [%s]", v.ID, v.Status)
}
return true, nil
})
th.CheckNoErr(t, err)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:19,代码来源:apiversion_test.go
示例17: TestListAPIResources
func TestListAPIResources(t *testing.T) {
Setup(t)
defer Teardown()
pager := apiversions.ListVersionResources(Client, "v2.0")
err := pager.EachPage(func(page pagination.Page) (bool, error) {
t.Logf("--- Page ---")
vrs, err := apiversions.ExtractVersionResources(page)
th.AssertNoErr(t, err)
for _, vr := range vrs {
t.Logf("Network: Name [%s] Collection [%s]", vr.Name, vr.Collection)
}
return true, nil
})
th.CheckNoErr(t, err)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:19,代码来源:apiversion_test.go
示例18: TestListExts
func TestListExts(t *testing.T) {
Setup(t)
defer Teardown()
pager := extensions.List(Client)
err := pager.EachPage(func(page pagination.Page) (bool, error) {
t.Logf("--- Page ---")
exts, err := extensions.ExtractExtensions(page)
th.AssertNoErr(t, err)
for _, ext := range exts {
t.Logf("Extension: Name [%s] Description [%s]", ext.Name, ext.Description)
}
return true, nil
})
th.CheckNoErr(t, err)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:19,代码来源:extension_test.go
示例19: TestSubnetList
func TestSubnetList(t *testing.T) {
Setup(t)
defer Teardown()
pager := subnets.List(Client, subnets.ListOpts{Limit: 2})
err := pager.EachPage(func(page pagination.Page) (bool, error) {
t.Logf("--- Page ---")
subnetList, err := subnets.ExtractSubnets(page)
th.AssertNoErr(t, err)
for _, s := range subnetList {
t.Logf("Subnet: ID [%s] Name [%s] IP Version [%d] CIDR [%s] GatewayIP [%s]",
s.ID, s.Name, s.IPVersion, s.CIDR, s.GatewayIP)
}
return true, nil
})
th.CheckNoErr(t, err)
}
开发者ID:sstrato,项目名称:gophercloud,代码行数:20,代码来源:subnet_test.go
示例20: TestNetworks
func TestNetworks(t *testing.T) {
client, err := newClient()
th.AssertNoErr(t, err)
// Create a network
n, err := networks.Create(client, networks.CreateOpts{Label: "sample_network", CIDR: "172.20.0.0/24"}).Extract()
th.AssertNoErr(t, err)
t.Logf("Created network: %+v\n", n)
defer networks.Delete(client, n.ID)
th.AssertEquals(t, n.Label, "sample_network")
th.AssertEquals(t, n.CIDR, "172.20.0.0/24")
networkID := n.ID
// List networks
pager := networks.List(client)
err = pager.EachPage(func(page pagination.Page) (bool, error) {
t.Logf("--- Page ---")
networkList, err := networks.ExtractNetworks(page)
th.AssertNoErr(t, err)
for _, n := range networkList {
t.Logf("Network: ID [%s] Label [%s] CIDR [%s]",
n.ID, n.Label, n.CIDR)
}
return true, nil
})
th.CheckNoErr(t, err)
// Get a network
if networkID == "" {
t.Fatalf("In order to retrieve a network, the NetworkID must be set")
}
n, err = networks.Get(client, networkID).Extract()
t.Logf("Retrieved Network: %+v\n", n)
th.AssertNoErr(t, err)
th.AssertEquals(t, n.CIDR, "172.20.0.0/24")
th.AssertEquals(t, n.Label, "sample_network")
th.AssertEquals(t, n.ID, networkID)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:41,代码来源:networks_test.go
注:本文中的github.com/rackspace/gophercloud/testhelper.CheckNoErr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论