当前位置: 首页>>代码示例>>Golang>>正文


Golang httpmock.RegisterResponder函数代码示例

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


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

示例1: TestOrderCount

func TestOrderCount(t *testing.T) {
	setup()
	defer teardown()

	httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/count.json",
		httpmock.NewStringResponder(200, `{"count": 7}`))

	httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/count.json?created_at_min=2016-01-01T00%3A00%3A00Z",
		httpmock.NewStringResponder(200, `{"count": 2}`))

	cnt, err := client.Order.Count(nil)
	if err != nil {
		t.Errorf("Order.Count returned error: %v", err)
	}

	expected := 7
	if cnt != expected {
		t.Errorf("Order.Count returned %d, expected %d", cnt, expected)
	}

	date := time.Date(2016, time.January, 1, 0, 0, 0, 0, time.UTC)
	cnt, err = client.Order.Count(CountOptions{CreatedAtMin: date})
	if err != nil {
		t.Errorf("Order.Count returned error: %v", err)
	}

	expected = 2
	if cnt != expected {
		t.Errorf("Order.Count returned %d, expected %d", cnt, expected)
	}
}
开发者ID:Receiptful,项目名称:go-shopify,代码行数:31,代码来源:order_test.go

示例2: setHasMoreResponderPutValid

func setHasMoreResponderPutValid() {
	httpmock.RegisterResponder("POST", "http://arangodb:8000/_db/dbName/path",
		httpmock.NewStringResponder(200, `{"error": false, "errorMessage": "", "result": [{}], "hasMore":true, "id":"1000"}`))

	httpmock.RegisterResponder("PUT", "http://arangodb:8000/_db/dbName/path/1000",
		httpmock.NewStringResponder(200, `{"error": false, "errorMessage": "", "result": [{}], "hasMore":false}`))
}
开发者ID:howesteve,项目名称:arangolite,代码行数:7,代码来源:database_test.go

示例3: 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

示例4: TestWebhookCount

func TestWebhookCount(t *testing.T) {
	setup()
	defer teardown()

	httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/webhooks/count.json",
		httpmock.NewStringResponder(200, `{"count": 7}`))

	httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/webhooks/count.json?topic=orders%2Fpaid",
		httpmock.NewStringResponder(200, `{"count": 2}`))

	cnt, err := client.Webhook.Count(nil)
	if err != nil {
		t.Errorf("Webhook.Count returned error: %v", err)
	}

	expected := 7
	if cnt != expected {
		t.Errorf("Webhook.Count returned %d, expected %d", cnt, expected)
	}

	options := WebhookOptions{Topic: "orders/paid"}
	cnt, err = client.Webhook.Count(options)
	if err != nil {
		t.Errorf("Webhook.Count returned error: %v", err)
	}

	expected = 2
	if cnt != expected {
		t.Errorf("Webhook.Count returned %d, expected %d", cnt, expected)
	}
}
开发者ID:Receiptful,项目名称:go-shopify,代码行数:31,代码来源:webhook_test.go

示例5: TestCount

func TestCount(t *testing.T) {
	setup()
	defer teardown()

	httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/foocount",
		httpmock.NewStringResponder(200, `{"count": 5}`))

	httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/foocount?created_at_min=2016-01-01T00%3A00%3A00Z",
		httpmock.NewStringResponder(200, `{"count": 2}`))

	// Test without options
	cnt, err := client.Count("foocount", nil)
	if err != nil {
		t.Errorf("Client.Count returned error: %v", err)
	}

	expected := 5
	if cnt != expected {
		t.Errorf("Client.Count returned %d, expected %d", cnt, expected)
	}

	// Test with options
	date := time.Date(2016, time.January, 1, 0, 0, 0, 0, time.UTC)
	cnt, err = client.Count("foocount", CountOptions{CreatedAtMin: date})
	if err != nil {
		t.Errorf("Client.Count returned error: %v", err)
	}

	expected = 2
	if cnt != expected {
		t.Errorf("Client.Count returned %d, expected %d", cnt, expected)
	}
}
开发者ID:Receiptful,项目名称:go-shopify,代码行数:33,代码来源:goshopify_test.go

示例6: 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

示例7: TestQueryRun

// TestQueryRun runs tests on the Query Run method.
func TestQueryRun(t *testing.T) {
	a := assert.New(t)
	r := require.New(t)

	httpmock.Activate()
	defer httpmock.DeactivateAndReset()

	db := New().LoggerOptions(false, false, false)
	db.Connect("http://arangodb:8000", "dbName", "foo", "bar")

	result, err := db.Run(NewQuery(shortQuery))
	r.Error(err)
	a.Nil(result)

	httpmock.RegisterResponder("POST", "http://arangodb:8000/_db/dbName/_api/cursor",
		httpmock.NewStringResponder(200, `{"error": false, "errorMessage": "", "result": []}`))

	result, err = db.Run(NewQuery(""))
	r.NoError(err)
	a.Equal("[]", string(result))

	result, err = db.Run(NewQuery(shortQuery).Cache(true).BatchSize(500))
	r.NoError(err)
	a.Equal("[]", string(result))

	httpmock.RegisterResponder("POST", "http://arangodb:8000/_db/dbName/_api/cursor",
		httpmock.NewStringResponder(200, `{"error": false, "errorMessage": "", "result": [{}], "hasMore":true, "id":"1000"}`))

	httpmock.RegisterResponder("PUT", "http://arangodb:8000/_db/dbName/_api/cursor/1000",
		httpmock.NewStringResponder(200, `{"error": false, "errorMessage": "", "result": [{}], "hasMore":false}`))

	result, err = db.Run(NewQuery(""))
	r.NoError(err)
	a.Equal("[{},{}]", string(result))

	q := NewQuery(`
	    FOR d
	    IN documents
	    FILTER d._key == @key
	    RETURN d
	    `)
	q.Bind("key", 1000)
	result, err = db.Run(q)

	r.NoError(err)
	a.Equal("[{},{}]", string(result))

	httpmock.RegisterResponder("POST", "http://arangodb:8000/_db/dbName/_api/cursor",
		httpmock.NewStringResponder(500, `{"error": true, "errorMessage": "error !"}`))

	result, err = db.Run(NewQuery(shortQuery))
	r.Error(err)
	a.Nil(result)
}
开发者ID:snocorp,项目名称:arangolite,代码行数:55,代码来源:query_test.go

示例8: TestOrderListOptions

func TestOrderListOptions(t *testing.T) {
	setup()
	defer teardown()

	httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders.json?limit=250&page=10&status=any",
		httpmock.NewBytesResponder(200, loadFixture("orders.json")))

	options := OrderListOptions{
		Page:   10,
		Limit:  250,
		Status: "any"}

	orders, err := client.Order.List(options)
	if err != nil {
		t.Errorf("Order.List returned error: %v", err)
	}

	// Check that orders were parsed
	if len(orders) != 1 {
		t.Errorf("Order.List got %v orders, expected: 1", len(orders))
	}

	order := orders[0]
	orderTests(t, order)
}
开发者ID:Receiptful,项目名称:go-shopify,代码行数:25,代码来源:order_test.go

示例9: dataMarshalling

func dataMarshalling(t *testing.T) {
	httpmock.RegisterResponder("GET", fetcher.generateURL(),
		httpmock.NewStringResponder(200, "{\"response\": {\"games\": [{\"appid\": 10, \"name\": \"game\", \"playtime_forever\": 32}]}}"))

	fetcher.getOwnedGames()
	assert.Equal(t, 10, fetcher.OwnedGames.Response.Games[0].ID)
}
开发者ID:corybuecker,项目名称:steam-stats-fetcher,代码行数:7,代码来源:steam_test.go

示例10: TestGetMultipleTemplates

func TestGetMultipleTemplates(t *testing.T) {
	assert := assert.New(t)
	output := new(bytes.Buffer)
	httpmock.Activate()
	defer httpmock.DeactivateAndReset()
	httpmock.RegisterResponder("GET", templateUrl("Java.gitignore"),
		httpmock.NewStringResponder(200, "*.class"))
	httpmock.RegisterResponder("GET", templateUrl("Go.gitignore"),
		httpmock.NewStringResponder(200, "*.o"))

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

	assert.ThatString(output.String()).
		Contains(fmt.Sprintln("# Java\n*.class")).
		Contains(fmt.Sprintln("# Go\n*.o"))
}
开发者ID:jcgay,项目名称:chtignore,代码行数:16,代码来源:chtignore_test.go

示例11: 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

示例12: 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

示例13: 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

示例14: 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

示例15: 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


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