• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang testhelper.CheckDeepEquals函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/jrperritt/rack/internal/github.com/rackspace/gophercloud/testhelper.CheckDeepEquals函数的典型用法代码示例。如果您正苦于以下问题:Golang CheckDeepEquals函数的具体用法?Golang CheckDeepEquals怎么用?Golang CheckDeepEquals使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了CheckDeepEquals函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestListServers

func TestListServers(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleServerListSuccessfully(t)

	pages := 0
	err := List(client.ServiceClient(), ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
		pages++

		actual, err := ExtractServers(page)
		if err != nil {
			return false, err
		}

		if len(actual) != 2 {
			t.Fatalf("Expected 2 servers, got %d", len(actual))
		}
		th.CheckDeepEquals(t, ServerHerp, actual[0])
		th.CheckDeepEquals(t, ServerDerp, actual[1])

		return true, nil
	})

	th.AssertNoErr(t, err)

	if pages != 1 {
		t.Errorf("Expected 1 page, saw %d", pages)
	}
}
开发者ID:hdansou,项目名称:rack,代码行数:29,代码来源:requests_test.go


示例2: IsSuccessful

// IsSuccessful ensures that a CreateResult was successful and contains the correct token and
// service catalog.
func IsSuccessful(t *testing.T, result CreateResult) {
	token, err := result.ExtractToken()
	th.AssertNoErr(t, err)
	th.CheckDeepEquals(t, ExpectedToken, token)

	serviceCatalog, err := result.ExtractServiceCatalog()
	th.AssertNoErr(t, err)
	th.CheckDeepEquals(t, ExpectedServiceCatalog, serviceCatalog)
}
开发者ID:hdansou,项目名称:rack,代码行数:11,代码来源:fixtures.go


示例3: TestMaybeInt

func TestMaybeInt(t *testing.T) {
	testInt := 0
	var expected *int
	actual := MaybeInt(testInt)
	th.CheckDeepEquals(t, expected, actual)

	testInt = 4
	expected = &testInt
	actual = MaybeInt(testInt)
	th.CheckDeepEquals(t, expected, actual)
}
开发者ID:hdansou,项目名称:rack,代码行数:11,代码来源:params_test.go


示例4: TestMaybeString

func TestMaybeString(t *testing.T) {
	testString := ""
	var expected *string
	actual := MaybeString(testString)
	th.CheckDeepEquals(t, expected, actual)

	testString = "carol"
	expected = &testString
	actual = MaybeString(testString)
	th.CheckDeepEquals(t, expected, actual)
}
开发者ID:hdansou,项目名称:rack,代码行数:11,代码来源:params_test.go


示例5: TestApplyDefaultsToEndpointOpts

func TestApplyDefaultsToEndpointOpts(t *testing.T) {
	eo := EndpointOpts{Availability: AvailabilityPublic}
	eo.ApplyDefaults("compute")
	expected := EndpointOpts{Availability: AvailabilityPublic, Type: "compute"}
	th.CheckDeepEquals(t, expected, eo)

	eo = EndpointOpts{Type: "compute"}
	eo.ApplyDefaults("object-store")
	expected = EndpointOpts{Availability: AvailabilityPublic, Type: "compute"}
	th.CheckDeepEquals(t, expected, eo)
}
开发者ID:hdansou,项目名称:rack,代码行数:11,代码来源:endpoint_search_test.go


示例6: TestListAllServers

func TestListAllServers(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleServerListSuccessfully(t)

	allPages, err := List(client.ServiceClient(), ListOpts{}).AllPages()
	th.AssertNoErr(t, err)
	actual, err := ExtractServers(allPages)
	th.AssertNoErr(t, err)
	th.CheckDeepEquals(t, ServerHerp, actual[0])
	th.CheckDeepEquals(t, ServerDerp, actual[1])
}
开发者ID:hdansou,项目名称:rack,代码行数:12,代码来源:requests_test.go


示例7: TestListAll

func TestListAll(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	MockListResponse(t)

	allPages, err := List(client.ServiceClient(), &ListOpts{}).AllPages()
	th.AssertNoErr(t, err)
	actual, err := ExtractVolumes(allPages)
	th.AssertNoErr(t, err)

	expected := []Volume{
		Volume{
			ID:   "289da7f8-6440-407c-9fb4-7db01ec49164",
			Name: "vol-001",
		},
		Volume{
			ID:   "96c3bda7-c82a-4f50-be73-ca7621794835",
			Name: "vol-002",
		},
	}

	th.CheckDeepEquals(t, expected, actual)

}
开发者ID:hdansou,项目名称:rack,代码行数:25,代码来源:requests_test.go


示例8: 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:hdansou,项目名称:rack,代码行数:26,代码来源:params_test.go


示例9: TestListImageDetails

func TestListImageDetails(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	th.Mux.HandleFunc("/images/detail", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "GET")
		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)

		w.Header().Add("Content-Type", "application/json")
		r.ParseForm()
		marker := r.Form.Get("marker")
		switch marker {
		case "":
			fmt.Fprintf(w, ListOutput)
		case "e19a734c-c7e6-443a-830c-242209c4d65d":
			fmt.Fprintf(w, `{ "images": [] }`)
		default:
			t.Fatalf("Unexpected marker: [%s]", marker)
		}
	})

	count := 0
	err := ListDetail(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) {
		count++
		actual, err := ExtractImages(page)
		th.AssertNoErr(t, err)
		th.CheckDeepEquals(t, ExpectedImageSlice, actual)

		return true, nil
	})
	th.AssertNoErr(t, err)
	th.CheckEquals(t, 1, count)
}
开发者ID:hdansou,项目名称:rack,代码行数:33,代码来源:delegate_test.go


示例10: TestEnumerateMarker

func TestEnumerateMarker(t *testing.T) {
	pager := createMarkerPaged(t)
	defer testhelper.TeardownHTTP()

	callCount := 0
	err := pager.EachPage(func(page Page) (bool, error) {
		actual, err := ExtractMarkerStrings(page)
		if err != nil {
			return false, err
		}

		t.Logf("Handler invoked with %v", actual)

		var expected []string
		switch callCount {
		case 0:
			expected = []string{"aaa", "bbb", "ccc"}
		case 1:
			expected = []string{"ddd", "eee", "fff"}
		case 2:
			expected = []string{"ggg", "hhh", "iii"}
		default:
			t.Fatalf("Unexpected call count: %d", callCount)
			return false, nil
		}

		testhelper.CheckDeepEquals(t, expected, actual)

		callCount++
		return true, nil
	})
	testhelper.AssertNoErr(t, err)
	testhelper.AssertEquals(t, callCount, 3)
}
开发者ID:hdansou,项目名称:rack,代码行数:34,代码来源:marker_test.go


示例11: tokenPostErr

func tokenPostErr(t *testing.T, options gophercloud.AuthOptions, expectedErr error) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleTokenPost(t, "")

	actualErr := Create(client.ServiceClient(), AuthOptions{options}).Err
	th.CheckDeepEquals(t, expectedErr, actualErr)
}
开发者ID:harshalhshah,项目名称:rack,代码行数:8,代码来源:requests_test.go


示例12: TestAuthenticatedHeaders

func TestAuthenticatedHeaders(t *testing.T) {
	p := &ProviderClient{
		TokenID: "1234",
	}
	expected := map[string]string{"X-Auth-Token": "1234"}
	actual := p.AuthenticatedHeaders()
	th.CheckDeepEquals(t, expected, actual)
}
开发者ID:hdansou,项目名称:rack,代码行数:8,代码来源:provider_client_test.go


示例13: TestBuildQueryString

func TestBuildQueryString(t *testing.T) {
	type testVar string
	opts := struct {
		J  int       `q:"j"`
		R  string    `q:"r,required"`
		C  bool      `q:"c"`
		S  []string  `q:"s"`
		TS []testVar `q:"ts"`
		TI []int     `q:"ti"`
	}{
		J:  2,
		R:  "red",
		C:  true,
		S:  []string{"one", "two", "three"},
		TS: []testVar{"a", "b"},
		TI: []int{1, 2},
	}
	expected := &url.URL{RawQuery: "c=true&j=2&r=red&s=one&s=two&s=three&ti=1&ti=2&ts=a&ts=b"}
	actual, err := BuildQueryString(&opts)
	if err != nil {
		t.Errorf("Error building query string: %v", err)
	}
	th.CheckDeepEquals(t, expected, actual)

	opts = struct {
		J  int       `q:"j"`
		R  string    `q:"r,required"`
		C  bool      `q:"c"`
		S  []string  `q:"s"`
		TS []testVar `q:"ts"`
		TI []int     `q:"ti"`
	}{
		J: 2,
		C: true,
	}
	_, err = BuildQueryString(&opts)
	if err == nil {
		t.Errorf("Expected error: 'Required field not set'")
	}
	th.CheckDeepEquals(t, expected, actual)

	_, err = BuildQueryString(map[string]interface{}{"Number": 4})
	if err == nil {
		t.Errorf("Expected error: 'Options type is not a struct'")
	}
}
开发者ID:hdansou,项目名称:rack,代码行数:46,代码来源:params_test.go


示例14: TestGet

func TestGet(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	os.HandleGetSuccessfully(t)

	actual, err := Get(client.ServiceClient(), "firstkey").Extract()
	th.AssertNoErr(t, err)
	th.CheckDeepEquals(t, &os.FirstKeyPair, actual)
}
开发者ID:hdansou,项目名称:rack,代码行数:9,代码来源:delegate_test.go


示例15: TestGetObject

func TestGetObject(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	os.HandleGetObjectSuccessfully(t)

	expected := map[string]string{"Gophercloud-Test": "objects"}
	actual, err := Get(fake.ServiceClient(), "testContainer", "testObject", nil).ExtractMetadata()
	th.AssertNoErr(t, err)
	th.CheckDeepEquals(t, expected, actual)
}
开发者ID:harshalhshah,项目名称:rack,代码行数:10,代码来源:delegate_test.go


示例16: TestList

func TestList(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()

	th.Mux.HandleFunc("/v2.0/security-groups", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "GET")
		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)

		w.Header().Add("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)

		fmt.Fprintf(w, `
{
    "security_groups": [
        {
            "description": "default",
            "id": "85cc3048-abc3-43cc-89b3-377341426ac5",
            "name": "default",
            "security_group_rules": [],
            "tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550"
        }
    ]
}
      `)
	})

	count := 0

	List(fake.ServiceClient(), ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
		count++
		actual, err := ExtractGroups(page)
		if err != nil {
			t.Errorf("Failed to extract secgroups: %v", err)
			return false, err
		}

		expected := []SecGroup{
			SecGroup{
				Description: "default",
				ID:          "85cc3048-abc3-43cc-89b3-377341426ac5",
				Name:        "default",
				Rules:       []rules.SecGroupRule{},
				TenantID:    "e4f50856753b4dc6afee5fa6b9b6c550",
			},
		}

		th.CheckDeepEquals(t, expected, actual)

		return true, nil
	})

	if count != 1 {
		t.Errorf("Expected 1 page, got %d", count)
	}
}
开发者ID:hdansou,项目名称:rack,代码行数:55,代码来源:requests_test.go


示例17: TestGet

func TestGet(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleGetSuccessfully(t)
	aId := "a26887c6-c47b-4654-abb5-dfadf7d3f804"
	serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"

	actual, err := Get(client.ServiceClient(), serverId, aId).Extract()
	th.AssertNoErr(t, err)
	th.CheckDeepEquals(t, &SecondVolumeAttachment, actual)
}
开发者ID:harshalhshah,项目名称:rack,代码行数:11,代码来源:requests_test.go


示例18: TestCreate

func TestCreate(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	os.HandleCreateSuccessfully(t)

	actual, err := Create(client.ServiceClient(), os.CreateOpts{
		Name: "createdkey",
	}).Extract()
	th.AssertNoErr(t, err)
	th.CheckDeepEquals(t, &os.CreatedKeyPair, actual)
}
开发者ID:hdansou,项目名称:rack,代码行数:11,代码来源:delegate_test.go


示例19: TestListAllContainerNames

func TestListAllContainerNames(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleListContainerNamesSuccessfully(t)

	allPages, err := List(fake.ServiceClient(), &ListOpts{Full: false}).AllPages()
	th.AssertNoErr(t, err)
	actual, err := ExtractNames(allPages)
	th.AssertNoErr(t, err)
	th.CheckDeepEquals(t, ExpectedListNames, actual)
}
开发者ID:hdansou,项目名称:rack,代码行数:11,代码来源:requests_test.go


示例20: TestAllPagesLinked

func TestAllPagesLinked(t *testing.T) {
	pager := createLinked(t)
	defer testhelper.TeardownHTTP()

	page, err := pager.AllPages()
	testhelper.AssertNoErr(t, err)

	expected := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
	actual, err := ExtractLinkedInts(page)
	testhelper.AssertNoErr(t, err)
	testhelper.CheckDeepEquals(t, expected, actual)
}
开发者ID:hdansou,项目名称:rack,代码行数:12,代码来源:linked_test.go



注:本文中的github.com/jrperritt/rack/internal/github.com/rackspace/gophercloud/testhelper.CheckDeepEquals函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang testhelper.CheckEquals函数代码示例发布时间:2022-05-23
下一篇:
Golang testhelper.AssertNoErr函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap