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

Golang httpmock.Activate函数代码示例

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

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



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

示例1: TestImportTaskWithSuccess

func TestImportTaskWithSuccess(t *testing.T) {
	httpmock.Activate()
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	httpmock.RegisterNoResponder(httpmock.NewStringResponder(200, `{"meta":{"status":200},"data":{"id":176,"file":{"name":"string.po","format":"GNU_PO","locale":{"code":"en-US","english_name":"English (United States)","local_name":"English (United States)","locale":"en","region":"US"}},"string_count":236,"word_count":1260,"status":"in-progress","created_at":"2013-10-07T15:27:10+0000","created_at_timestamp":1381159630}}`))
	client := Client{APIKey: "abcdef", Secret: "abcdef", ProjectID: 1}

	res, err := client.ImportTask(1)
	assert.Nil(t, err)

	assert.Equal(t,
		TaskData{
			ID:         176,
			OriginalID: float64(176),
			File: TaskFile{
				Name:   "string.po",
				Format: "GNU_PO",
				Locale: Language{
					Code:        "en-US",
					EnglishName: "English (United States)",
					LocalName:   "English (United States)",
					Locale:      "en",
					Region:      "US",
				},
			},
			StringCount:         236,
			WordCount:           1260,
			Status:              "in-progress",
			CreateddAt:          "2013-10-07T15:27:10+0000",
			CreateddAtTimestamp: 1381159630,
		}, res)
}
开发者ID:SebastianCzoch,项目名称:onesky-go,代码行数:32,代码来源:onesky_test.go


示例2: TestMemPlugin

func TestMemPlugin(t *testing.T) {
	Convey("getMemstat Should return memory amount value", t, func() {

		httpmock.Activate()
		defer httpmock.DeactivateAndReset()
		httpmock.RegisterResponder("GET", "http://192.168.192.200:8000/os/memory/free",
			func(req *http.Request) (*http.Response, error) {
				resp := httpmock.NewStringResponse(200, "20000")
				return resp, nil

			},
		)
		httpmock.RegisterResponder("GET", "http://192.168.192.200:8000/os/memory/total",
			func(req *http.Request) (*http.Response, error) {
				resp := httpmock.NewStringResponse(200, "10000")
				return resp, nil

			},
		)

		memFree, err := getMemStat("http://192.168.192.200:8000", "free")
		So(err, ShouldBeNil)
		So(strconv.FormatUint(memFree, 10), ShouldResemble, "20000")
		memTotal, err := getMemStat("http://192.168.192.200:8000", "total")
		So(err, ShouldBeNil)
		So(strconv.FormatUint(memTotal, 10), ShouldResemble, "10000")

	})
	Convey("MemStat Should return pluginMetricType Data", t, func() {

		httpmock.Activate()
		defer httpmock.DeactivateAndReset()
		httpmock.RegisterResponder("GET", "http://192.168.192.200:8000/os/memory/free",
			func(req *http.Request) (*http.Response, error) {
				resp := httpmock.NewStringResponse(200, "20000")
				return resp, nil

			},
		)
		httpmock.RegisterResponder("GET", "http://192.168.192.200:8000/os/memory/total",
			func(req *http.Request) (*http.Response, error) {
				resp := httpmock.NewStringResponse(200, "10000")
				return resp, nil

			},
		)

		ns := []string{"osv", "memory", "free"}
		ns2 := []string{"osv", "memory", "total"}
		memFree, err := memStat(ns, "http://192.168.192.200:8000")
		So(err, ShouldBeNil)
		So(memFree.Namespace_, ShouldResemble, ns)
		So(memFree.Data_, ShouldResemble, "20000")
		memTotal, err := memStat(ns2, "http://192.168.192.200:8000")
		So(err, ShouldBeNil)
		So(memTotal.Namespace_, ShouldResemble, ns2)
		So(memTotal.Data_, ShouldResemble, "10000")

	})
}
开发者ID:geauxvirtual,项目名称:snap-plugin-collector-osv,代码行数:60,代码来源:mem_test.go


示例3: TestUploadFileWithSuccess

func TestUploadFileWithSuccess(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	httpmock.RegisterNoResponder(httpmock.NewStringResponder(201, `{"meta":{"status":201},"data":{"name":"string.po","format":"GNU_PO","language":{"code":"en-US","english_name":"English (United States)","local_name":"English (United States)","locale":"en","region":"US"},"import":{"id":154,"created_at":"2013-10-07T15:27:10+0000","created_at_timestamp":1381159630}}}`))
	client := Client{APIKey: "abcdef", Secret: "abcdef", ProjectID: 1}

	tmpdir, err := ioutil.TempDir("", "")
	assert.Nil(t, err)
	defer os.RemoveAll(tmpdir)

	filename := path.Join(tmpdir, "string.po")
	ioutil.WriteFile(filename, []byte("test"), 0666)

	res, err := client.UploadFile(filename, "GNU_PO", "en_US", true)
	assert.Nil(t, err)

	assert.Equal(t, UploadData{
		Name:   "string.po",
		Format: "GNU_PO",
		Language: Language{
			Code:        "en-US",
			EnglishName: "English (United States)",
			LocalName:   "English (United States)",
			Locale:      "en",
			Region:      "US",
		},
		Import: TaskData{
			ID:                  154,
			OriginalID:          154.0,
			CreateddAt:          "2013-10-07T15:27:10+0000",
			CreateddAtTimestamp: 1381159630,
		},
	}, res)
}
开发者ID:SebastianCzoch,项目名称:onesky-go,代码行数:34,代码来源:onesky_test.go


示例4: TestGetBookmarkCountError

func TestGetBookmarkCountError(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()

	res := "0"
	httpmock.RegisterResponder(
		"GET",
		"http://api.b.st-hatena.com/entry.count?url=http%3A%2F%2Fdeveloper.hatena.ne.jp",
		func(req *http.Request) (*http.Response, error) {
			return nil, errors.New("internal server error")
		},
	)

	input := "http://developer.hatena.ne.jp"
	expected, err := strconv.Atoi(res)

	count, err := GetBookmarkCount(input)
	if err == nil {
		t.Errorf("fail mock: %s\n", input)
	}

	if count != expected {
		t.Errorf("expected count %d, but got %d\n", expected, count)
	}
}
开发者ID:yukihir0,项目名称:hbapi,代码行数:25,代码来源:hbapi_test.go


示例5: TestSegmentPager

func TestSegmentPager(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	mock.RegisterSegmentMocks()

	var (
		completed     bool
		countEntities int
	)

	client := NewLytics(mock.MockApiKey, nil, nil)

	// start the paging routine
	scan := client.PageSegmentId(mock.MockSegmentID1)
	assert.Equal(t, nil, scan.Err())

	// handle processing the entities
	for {
		e := scan.Next()
		if e == nil {
			completed = true
			break
		}
		countEntities++
		assert.Equal(t, e["email"], fmt.Sprintf("email%[email protected]", countEntities))
	}
	assert.Equal(t, countEntities, 13)
	assert.Equal(t, completed, true)
	t.Logf("*** COMPLETED SCAN: %d total entities", scan.Total)
}
开发者ID:lytics,项目名称:go-lytics,代码行数:30,代码来源:segment_test.go


示例6: TestGetBookmarkCounts

func TestGetBookmarkCounts(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()

	res := `
{
	"https://github.com":111,
	"https://bitbucket.org":222,
	"http://stackoverflow.com":333
}
`
	httpmock.RegisterResponder(
		"GET",
		"http://api.b.st-hatena.com/entry.counts?url=https%3A%2F%2Fgithub.com&url=https%3A%2F%2Fbitbucket.org&url=http%3A%2F%2Fstackoverflow.com",
		httpmock.NewStringResponder(200, res))

	input := []string{
		"https://github.com",
		"https://bitbucket.org",
		"http://stackoverflow.com",
	}
	expected := map[string]int{}
	json.Unmarshal([]byte(res), &expected)

	counts, err := GetBookmarkCounts(input)
	if err != nil {
		t.Errorf("fail mock: %#v\n", input)
	}

	for url, count := range counts {
		if count != expected[url] {
			t.Errorf("expected count %d, but got %d\n", expected[url], count)
		}
	}
}
开发者ID:yukihir0,项目名称:hbapi,代码行数:35,代码来源:hbapi_test.go


示例7: TestImportTasksWithSuccess

func TestImportTasksWithSuccess(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	httpmock.RegisterNoResponder(httpmock.NewStringResponder(200, `{"meta":{"status":200},"data":[{"id":"177","file":{"name":"string2.po"},"status":"in-progress","created_at":"2013-10-07T15:25:00+0000","created_at_timestamp":1381159500},{"id":"176","file":{"name":"string.po"},"status":"in-progress","created_at":"2013-10-07T15:27:10+0000","created_at_timestamp":1381159630}]}`))
	client := Client{APIKey: "abcdef", Secret: "abcdef", ProjectID: 1}

	res, err := client.ImportTasks(map[string]interface{}{"page": 1, "per_page": 50, "status": "in-progress"})
	assert.Nil(t, err)

	assert.Equal(t,
		[]TaskData{
			TaskData{
				ID:         177,
				OriginalID: "177",
				File: TaskFile{
					Name: "string2.po",
				},
				Status:              "in-progress",
				CreateddAt:          "2013-10-07T15:25:00+0000",
				CreateddAtTimestamp: 1381159500,
			},
			TaskData{
				ID:         176,
				OriginalID: "176",
				File: TaskFile{
					Name: "string.po",
				},
				Status:              "in-progress",
				CreateddAt:          "2013-10-07T15:27:10+0000",
				CreateddAtTimestamp: 1381159630,
			},
		}, res)
}
开发者ID:SebastianCzoch,项目名称:onesky-go,代码行数:33,代码来源:onesky_test.go


示例8: TestGetOrders

func TestGetOrders(t *testing.T) {

	httpmock.Activate()
	defer httpmock.DeactivateAndReset()

	httpmock.RegisterResponder("GET", TICTAIL_TEST_URL+"/v1/stores/x1234/orders",
		func(req *http.Request) (*http.Response, error) {
			if req.Header.Get("Authorization") == "Bearer "+TICTAIL_TEST_KEY {
				return httpmock.NewStringResponse(200, TICTAIL_MOCK_GET_ORDERS_200_RESPONSE), nil
			}
			return httpmock.NewStringResponse(401, "{}"), nil
		},
	)

	tt := NewTictail(TICTAIL_TEST_KEY)

	response, err := tt.GetAllOrders("x1234")
	if err != nil {
		t.Error(err.Error())
	}
	t.Logf("response: %#v", response)

	var expectedData []spec.OrdersResponse
	err = json.Unmarshal([]byte(TICTAIL_MOCK_GET_ORDERS_200_RESPONSE), &expectedData)
	if err != nil {
		t.Error(err.Error())
	}

	if !reflect.DeepEqual(expectedData, response) {
		t.Error("Response and mock data didn't match")
	}

}
开发者ID:byrnedo,项目名称:tictochimp,代码行数:33,代码来源:tictail_test.go


示例9: TestGetSegmentSizes

func TestGetSegmentSizes(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	mock.RegisterSegmentMocks()

	var segments []string

	client := NewLytics(mock.MockApiKey, nil, nil)

	segments = []string{
		mock.MockSegmentID1,
	}

	seg, err := client.GetSegmentSizes(segments)
	assert.Equal(t, err, nil)
	assert.T(t, seg[0].Id == segments[0])

	segments = []string{
		mock.MockSegmentID1,
		mock.MockSegmentID2,
	}

	// params
	seg, err = client.GetSegmentSizes(segments)
	assert.Equal(t, err, nil)
	assert.T(t, len(seg) == 2)
}
开发者ID:lytics,项目名称:go-lytics,代码行数:27,代码来源:segment_test.go


示例10: TestListTemplatesSortedByName

func TestListTemplatesSortedByName(t *testing.T) {
	assert := assert.New(t)
	output := new(bytes.Buffer)
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	httpmock.RegisterResponder("GET", "https://api.github.com/repos/github/gitignore/contents/",
		httpmock.NewStringResponder(200, `[
  {
    "name": "C.gitignore"
  },
  {
    "name": "A.gitignore"
  }
]
`))
	httpmock.RegisterResponder("GET", "https://api.github.com/repos/github/gitignore/contents/Global",
		httpmock.NewStringResponder(200, `[
  {
    "name": "B.gitignore"
  }
]
`))

	app([]string{"chtignore", "list"}, output)

	assert.ThatString(output.String()).IsEqualTo(fmt.Sprintln("A, B, C, JetBrains-build"))
}
开发者ID:jcgay,项目名称:chtignore,代码行数:27,代码来源:chtignore_test.go


示例11: TestGetTranslationsStatusWithSuccess

func TestGetTranslationsStatusWithSuccess(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	httpmock.RegisterNoResponder(httpmock.NewStringResponder(200, `{"meta":{"status":200},"data":{"file_name":"string.po","locale":{"code":"ja-JP","english_name":"Japanese","local_name":"\u65e5\u672c\u8a9e","locale":"ja","region":"JP"},"progress":"92%","string_count":1359,"word_count":3956}}`))
	client := Client{APIKey: "abcdef", Secret: "abcdef", ProjectID: 1}

	res, err := client.GetTranslationsStatus("string.po", "ja-JP")
	assert.Nil(t, err)

	assert.Equal(t,
		TranslationsStatus{
			FileName: "string.po",
			Locale: Language{
				Code:         "ja-JP",
				EnglishName:  "Japanese",
				LocalName:    "日本語",
				CustomLocale: "",
				Locale:       "ja",
				Region:       "JP",
			},
			Progress:    "92%",
			StringCount: 1359,
			WordCount:   3956,
		}, res)
}
开发者ID:SebastianCzoch,项目名称:onesky-go,代码行数:25,代码来源:onesky_test.go


示例12: TestGetFavoriteFeedError

func TestGetFavoriteFeedError(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()

	httpmock.RegisterResponder(
		"GET",
		"http://b.hatena.ne.jp/yukihir0/favorite.rss",
		func(req *http.Request) (*http.Response, error) {
			return nil, errors.New("internal server error")
		},
	)

	input := "yukihir0"
	params := NewFavoriteFeedParams(input)
	expected := FavoriteFeed{}

	feed, err := GetFavoriteFeed(params)
	if err == nil {
		t.Errorf("fail mock: %#v\n", input)
	}

	if !reflect.DeepEqual(feed, expected) {
		t.Errorf("expected favorite feed %#v, but got %#v\n", expected, feed)
	}
}
开发者ID:yukihir0,项目名称:hbapi,代码行数:25,代码来源:hbapi_test.go


示例13: TestGetBookmarkCountsError

func TestGetBookmarkCountsError(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()

	httpmock.RegisterResponder(
		"GET",
		"http://api.b.st-hatena.com/entry.counts?url=https%3A%2F%2Fgithub.com&url=https%3A%2F%2Fbitbucket.org&url=http%3A%2F%2Fstackoverflow.com",
		func(req *http.Request) (*http.Response, error) {
			return nil, errors.New("internal server error")
		},
	)

	input := []string{
		"https://github.com",
		"https://bitbucket.org",
		"http://stackoverflow.com",
	}
	expected := map[string]int{}

	counts, err := GetBookmarkCounts(input)
	if err == nil {
		t.Errorf("fail mock: %#v\n", input)
	}

	if !reflect.DeepEqual(counts, expected) {
		t.Errorf("expected counts %#v, but got %#v\n", expected, counts)
	}
}
开发者ID:yukihir0,项目名称:hbapi,代码行数:28,代码来源:hbapi_test.go


示例14: TestPostsRecentHighCount

func TestPostsRecentHighCount(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	_, _, err := client.Posts.Recent(nil, 1000)
	if err.Error() != "count must be below 100" {
		t.Error(err)
	}
}
开发者ID:zachlatta,项目名称:pin,代码行数:8,代码来源:posts_test.go


示例15: TestSendEcoSMSSuccess

func TestSendEcoSMSSuccess(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	httpmock.RegisterResponder("POST", "https://api.smsapi.pl/sms.do", httpmock.NewStringResponder(200, `OK:1013211`))

	object := New("testuser", "testpasswd")
	err := object.SendEcoSMS("XXXXXXXXX", "test message")
	assert.NoError(t, err)
}
开发者ID:SebastianCzoch,项目名称:smsapi-go,代码行数:9,代码来源:smsapi_test.go


示例16: TestListFilesWithFailure

func TestListFilesWithFailure(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	httpmock.RegisterNoResponder(httpmock.NewStringResponder(500, ""))
	client := Client{APIKey: "abcdef", Secret: "abcdef", ProjectID: 1}

	_, err := client.ListFiles(1, 1)
	assert.Equal(t, err, fmt.Errorf("bad status: %d", 500))
}
开发者ID:SebastianCzoch,项目名称:onesky-go,代码行数:9,代码来源:onesky_test.go


示例17: TestDeleteFileWithSuccess

func TestDeleteFileWithSuccess(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	httpmock.RegisterNoResponder(httpmock.NewStringResponder(200, ""))
	client := Client{APIKey: "abcdef", Secret: "abcdef", ProjectID: 1}

	err := client.DeleteFile("test.yml")
	assert.Nil(t, err)
}
开发者ID:SebastianCzoch,项目名称:onesky-go,代码行数:9,代码来源:onesky_test.go


示例18: TestGetTranslationsStatusWithFailure

func TestGetTranslationsStatusWithFailure(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	httpmock.RegisterNoResponder(httpmock.NewStringResponder(500, ""))
	client := Client{APIKey: "abcdef", Secret: "abcdef", ProjectID: 1}

	_, err := client.GetTranslationsStatus("string.po", "ja-JP")
	assert.Equal(t, err, fmt.Errorf("bad status: %d", 500))
}
开发者ID:SebastianCzoch,项目名称:onesky-go,代码行数:9,代码来源:onesky_test.go


示例19: TestImportTasksWithFailure

func TestImportTasksWithFailure(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	httpmock.RegisterNoResponder(httpmock.NewStringResponder(500, ""))
	client := Client{APIKey: "abcdef", Secret: "abcdef", ProjectID: 1}

	_, err := client.ImportTasks(map[string]interface{}{"page": 1, "per_page": 50, "status": "all"})
	assert.Equal(t, err, fmt.Errorf("bad status: %d", 500))
}
开发者ID:SebastianCzoch,项目名称:onesky-go,代码行数:9,代码来源:onesky_test.go


示例20: TestVeryfiClient

func TestVeryfiClient(t *testing.T) {
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	httpmock.RegisterResponder("GET", "https://rest.akismet.com/1.1/verify-key?blog=test_site&key=test_api_key", httpmock.NewStringResponder(200, `valid`))

	client := NewClient("test_api_key", "test_site")
	err := client.VeryfiClient()
	assert.Nil(t, err)
}
开发者ID:SebastianCzoch,项目名称:akismet-go,代码行数:9,代码来源:akismet_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang httpmock.DeactivateAndReset函数代码示例发布时间:2022-05-23
下一篇:
Golang textsecure.Message类代码示例发布时间: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