當前位置: 首頁>>代碼示例>>Golang>>正文


Golang forest.Path函數代碼示例

本文整理匯總了Golang中github.com/emicklei/forest.Path函數的典型用法代碼示例。如果您正苦於以下問題:Golang Path函數的具體用法?Golang Path怎麽用?Golang Path使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Path函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestAPI

func TestAPI(t *testing.T) {
	go main()

	api := forest.NewClient("http://localhost:8888", new(http.Client))

	r := api.POST(t, forest.Path("/api/shorten").Body("https://github.com/stefanteixeira"))
	r2 := api.POST(t, forest.Path("/api/shorten").Body("https://github.com/stefanteixeira"))

	assert.Equal(t, r.StatusCode, 201)
	assert.Equal(t, r2.StatusCode, 200)
}
開發者ID:stefanteixeira,項目名稱:learning-go,代碼行數:11,代碼來源:shortener_api_test.go

示例2: TestForestCreateOrderInvalidTime

func TestForestCreateOrderInvalidTime(t *testing.T) {

	invalidTimes := []uint64{
		// 0, // valid
		// uint64(time.Now().UTC().Unix()), // valid
		uint64(time.Now().UTC().Add(-(engine.PastTimeTreshold + time.Second)).Unix()),
	}

	for _, invalidTime := range invalidTimes {

		payload := data.Order{
			Time: invalidTime,
		}

		got := Error{}

		r := getForestClient().POST(t, forest.Path("/orders/{}", "").Content(payload, MimeJSON))

		// TODO:
		// forest.ExpectStatus(t, r, http.StatusBadRequest)
		forest.ExpectStatus(t, r, http.StatusInternalServerError)

		forest.ExpectJSONDocument(t, r, &got)

		if got.Message == "" {
			t.Error("Got empty error message")
		}

	}

}
開發者ID:mxmCherry,項目名稱:goshop,代碼行數:31,代碼來源:order_forest_test.go

示例3: TestForestListOrders

func TestForestListOrders(t *testing.T) {

	expected := []data.Order{}

	for i := 1; i <= 3; i++ {

		_time := uint64(time.Now().UTC().Unix())

		order := data.Order{
			Time: _time,
		}

		createOrder(&order)

		// newest come first:
		expected = append([]data.Order{order}, expected...)

	}

	got := []data.Order{}

	r := getForestClient().GET(t, forest.Path("/orders/{}", "").Query("limit", len(expected)))

	forest.ExpectStatus(t, r, http.StatusOK)

	forest.ExpectJSONDocument(t, r, &got)

	if !reflect.DeepEqual(got, expected) {
		t.Errorf("Got: %s\n\nExpected: %s", testutils.JSON(got), testutils.JSON(expected))
	}

}
開發者ID:mxmCherry,項目名稱:goshop,代碼行數:32,代碼來源:order_forest_test.go

示例4: TestForestRemoveOrderItemNonExisting

func TestForestRemoveOrderItemNonExisting(t *testing.T) {

	product := data.Product{
		Name: generateName("Product"),
		Price: data.Price{
			Vat: 20,
			Net: 100,
		},
	}

	createProduct(&product)

	order := data.Order{}

	createOrder(&order)

	got := Error{}

	r := getForestClient().DELETE(t, forest.Path("/orders/{orderID}/items/{productID}", order.ID, product.ID))

	// TODO:
	// forest.ExpectStatus(t, r, http.StatusNotFound)
	forest.ExpectStatus(t, r, http.StatusInternalServerError)

	forest.ExpectJSONDocument(t, r, &got)

	if got.Message == "" {
		t.Error("Got empty error message")
	}

}
開發者ID:mxmCherry,項目名稱:goshop,代碼行數:31,代碼來源:order_item_forest_test.go

示例5: TestForestOrderItemCreateNonExistingProduct

func TestForestOrderItemCreateNonExistingProduct(t *testing.T) {

	nonExistingProductID := uint64(1000000) // TODO

	order := data.Order{}

	createOrder(&order)

	payload := data.OrderItem{
		Product: data.Product{
			ID: nonExistingProductID,
		},
		Quantity: 1,
	}

	got := Error{}

	r := getForestClient().POST(t, forest.Path("/orders/{orderID}/items/{}", order.ID, "").Content(payload, MimeJSON))

	// TODO:
	// forest.ExpectStatus(t, r, http.StatusNotFound)
	forest.ExpectStatus(t, r, http.StatusInternalServerError)

	forest.ExpectJSONDocument(t, r, &got)

	if got.Message == "" {
		t.Error("Got empty error message")
	}

}
開發者ID:mxmCherry,項目名稱:goshop,代碼行數:30,代碼來源:order_item_forest_test.go

示例6: TestForestRemoveOrderItem

func TestForestRemoveOrderItem(t *testing.T) {

	product := data.Product{
		Name: generateName("Product"),
		Price: data.Price{
			Vat: 20,
			Net: 100,
		},
	}

	createProduct(&product)

	order := data.Order{
		Items: []data.OrderItem{
			data.OrderItem{
				Product:  product,
				Quantity: 1,
			},
		},
	}

	createOrder(&order)

	r := getForestClient().DELETE(t, forest.Path("/orders/{orderID}/items/{itemID}", order.ID, product.ID))

	forest.ExpectStatus(t, r, http.StatusNoContent)

}
開發者ID:mxmCherry,項目名稱:goshop,代碼行數:28,代碼來源:order_item_forest_test.go

示例7: TestForestUpdateOrder

func TestForestUpdateOrder(t *testing.T) {

	_time := uint64(time.Now().UTC().Unix())
	_newTime := _time + 300 // 5 min

	order := data.Order{
		Time: _time,
	}

	createOrder(&order)

	expected := order

	expected.Time = _newTime

	payload := data.Order{
		Time: _newTime,
	}

	got := data.Order{}

	r := getForestClient().PUT(t, forest.Path("/orders/{id}", order.ID).Content(payload, MimeJSON))

	forest.ExpectStatus(t, r, http.StatusOK)

	forest.ExpectJSONDocument(t, r, &got)

	expected.ID = got.ID

	if !reflect.DeepEqual(got, expected) {
		t.Errorf("Got: %s\n\nExpected: %s", testutils.JSON(got), testutils.JSON(expected))
	}

}
開發者ID:mxmCherry,項目名稱:goshop,代碼行數:34,代碼來源:order_forest_test.go

示例8: TestForestUpdateOrderDraftCancelled

func TestForestUpdateOrderDraftCancelled(t *testing.T) {

	order := data.Order{}

	createOrder(&order)

	expected := order

	expected.State = data.OrderStateCancelled

	payload := data.Order{
		State: data.OrderStateCancelled,
	}

	got := data.Order{}

	r := getForestClient().PUT(t, forest.Path("/orders/{id}", order.ID).Content(payload, MimeJSON))

	forest.ExpectStatus(t, r, http.StatusOK)

	forest.ExpectJSONDocument(t, r, &got)

	expected.ID = got.ID

	if !reflect.DeepEqual(got, expected) {
		t.Errorf("Got: %s\n\nExpected: %s", testutils.JSON(got), testutils.JSON(expected))
	}

}
開發者ID:mxmCherry,項目名稱:goshop,代碼行數:29,代碼來源:order_forest_test.go

示例9: TestForestCreateOrder

func TestForestCreateOrder(t *testing.T) {

	_time := uint64(time.Now().UTC().Unix())

	expected := data.Order{
		State: data.OrderStateDraft,
		Time:  _time,
	}
	populate.Order(&expected)

	payload := data.Order{
		Time: _time,
	}

	got := data.Order{}

	r := getForestClient().POST(t, forest.Path("/orders/{}", "").Content(payload, MimeJSON))

	forest.ExpectStatus(t, r, http.StatusCreated)

	forest.ExpectJSONDocument(t, r, &got)

	expected.ID = got.ID

	if !reflect.DeepEqual(got, expected) {
		t.Errorf("Got: %s\n\nExpected: %s", testutils.JSON(got), testutils.JSON(expected))
	}

}
開發者ID:mxmCherry,項目名稱:goshop,代碼行數:29,代碼來源:order_forest_test.go

示例10: TestForestOrderItemCreateOrderPlaced

func TestForestOrderItemCreateOrderPlaced(t *testing.T) {

	productInOrder := data.Product{
		Name: generateName("Product"),
		Price: data.Price{
			Vat: 20,
			Net: 100,
		},
	}

	createProduct(&productInOrder)

	product := data.Product{
		Name: generateName("Product"),
		Price: data.Price{
			Vat: 20,
			Net: 100,
		},
	}

	createProduct(&product)

	order := data.Order{
		Items: []data.OrderItem{
			data.OrderItem{
				Product:  productInOrder,
				Quantity: 1,
			},
		},
	}

	createOrder(&order)

	order.State = data.OrderStatePlaced

	updateOrder(&order)

	payload := data.OrderItem{
		Product: data.Product{
			ID: product.ID,
		},
		Quantity: 0,
	}

	got := Error{}

	r := getForestClient().POST(t, forest.Path("/orders/{orderID}/items/{}", order.ID, "").Content(payload, MimeJSON))

	// TODO:
	// forest.ExpectStatus(t, r, http.StatusForbidden)
	forest.ExpectStatus(t, r, http.StatusInternalServerError)

	forest.ExpectJSONDocument(t, r, &got)

	if got.Message == "" {
		t.Error("Got empty error message")
	}

}
開發者ID:mxmCherry,項目名稱:goshop,代碼行數:59,代碼來源:order_item_forest_test.go

示例11: TestForestCreateOrderWithItems

func TestForestCreateOrderWithItems(t *testing.T) {

	_time := uint64(time.Now().UTC().Unix())

	expected := data.Order{
		State: data.OrderStateDraft,
		Time:  _time,
	}

	payload := data.Order{
		Time: _time,
	}

	for i := 1; i <= 3; i++ {

		product := data.Product{
			Name: generateName("Product"),
			Price: data.Price{
				Vat: 20,
				Net: uint64(100 * i),
			},
		}

		createProduct(&product)

		item := data.OrderItem{
			Product:  product,
			Quantity: uint64(i),
		}

		// newest come first:
		payload.Items = append([]data.OrderItem{item}, payload.Items...)
		expected.Items = append([]data.OrderItem{item}, expected.Items...)

	}

	populate.Order(&expected)

	got := data.Order{}

	r := getForestClient().POST(t, forest.Path("/orders/{}", "").Content(payload, MimeJSON))

	forest.ExpectStatus(t, r, http.StatusCreated)

	forest.ExpectJSONDocument(t, r, &got)

	expected.ID = got.ID

	if !reflect.DeepEqual(got, expected) {
		t.Errorf("Got: %s\n\nExpected: %s", testutils.JSON(got), testutils.JSON(expected))
	}

}
開發者ID:mxmCherry,項目名稱:goshop,代碼行數:53,代碼來源:order_forest_test.go

示例12: TestForestOrderItemUpdate

func TestForestOrderItemUpdate(t *testing.T) {

	product := data.Product{
		Name: generateName("Product"),
		Price: data.Price{
			Vat: 20,
			Net: 100,
		},
	}

	createProduct(&product)

	order := data.Order{
		Items: []data.OrderItem{
			data.OrderItem{
				Product:  product,
				Quantity: 1,
			},
		},
	}

	createOrder(&order)

	expected := data.OrderItem{
		Product:  product,
		Quantity: 20,
	}
	populate.OrderItem(&expected)

	payload := data.OrderItem{
		Product: data.Product{
			ID: product.ID,
		},
		Quantity: 20,
	}

	got := data.OrderItem{}

	r := getForestClient().PUT(t, forest.Path("/orders/{orderID}/items/{productID}", order.ID, product.ID).Content(payload, MimeJSON))

	forest.ExpectStatus(t, r, http.StatusOK)

	forest.ExpectJSONDocument(t, r, &got)

	if !reflect.DeepEqual(got, expected) {
		t.Errorf("Got: %s\n\nExpected: %s", testutils.JSON(got), testutils.JSON(expected))
	}

}
開發者ID:mxmCherry,項目名稱:goshop,代碼行數:49,代碼來源:order_item_forest_test.go

示例13: TestForestUpdateOrderDraftPlaced

func TestForestUpdateOrderDraftPlaced(t *testing.T) {

	product := data.Product{
		Name: generateName("Product"),
		Price: data.Price{
			Vat: 20,
			Net: 100,
		},
	}

	createProduct(&product)

	order := data.Order{
		Items: []data.OrderItem{
			data.OrderItem{
				Product:  product,
				Quantity: 1,
			},
		},
	}

	createOrder(&order)

	expected := order

	expected.State = data.OrderStatePlaced

	payload := data.Order{
		State: data.OrderStatePlaced,
	}

	got := data.Order{}

	r := getForestClient().PUT(t, forest.Path("/orders/{id}", order.ID).Content(payload, MimeJSON))

	forest.ExpectStatus(t, r, http.StatusOK)

	forest.ExpectJSONDocument(t, r, &got)

	expected.ID = got.ID

	if !reflect.DeepEqual(got, expected) {
		t.Errorf("Got: %s\n\nExpected: %s", testutils.JSON(got), testutils.JSON(expected))
	}

}
開發者ID:mxmCherry,項目名稱:goshop,代碼行數:46,代碼來源:order_forest_test.go

示例14: TestForestLoadOrderNonExisting

func TestForestLoadOrderNonExisting(t *testing.T) {

	nonExistingOrderID := 1000000 // TODO

	got := Error{}

	r := getForestClient().GET(t, forest.Path("/orders/{id}", nonExistingOrderID))

	// TODO:
	// forest.ExpectStatus(t, r, http.StatusNotFound)
	forest.ExpectStatus(t, r, http.StatusInternalServerError)

	forest.ExpectJSONDocument(t, r, &got)

	if got.Message == "" {
		t.Error("Got empty error message")
	}

}
開發者ID:mxmCherry,項目名稱:goshop,代碼行數:19,代碼來源:order_forest_test.go

示例15: TestForestListOrderItems

func TestForestListOrderItems(t *testing.T) {

	order := data.Order{}

	for i := 1; i <= 3; i++ {

		product := data.Product{
			Name: generateName("Product"),
			Price: data.Price{
				Vat: 20,
				Net: 100,
			},
		}

		createProduct(&product)

		item := data.OrderItem{
			Product:  product,
			Quantity: 1,
		}

		order.Items = append([]data.OrderItem{item}, order.Items...)

	}

	createOrder(&order)

	expected := order.Items

	got := []data.OrderItem{}

	r := getForestClient().GET(t, forest.Path("/orders/{orderID}/items/{}", order.ID, "").Query("limit", len(expected)))

	forest.ExpectStatus(t, r, http.StatusOK)

	forest.ExpectJSONDocument(t, r, &got)

	if !reflect.DeepEqual(got, expected) {
		t.Errorf("Got: %s\n\nExpected: %s", testutils.JSON(got), testutils.JSON(expected))
	}

}
開發者ID:mxmCherry,項目名稱:goshop,代碼行數:42,代碼來源:order_item_forest_test.go


注:本文中的github.com/emicklei/forest.Path函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。