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

Golang invdmockserver.New函数代码示例

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

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



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

示例1: TestCustomerDeleteError

func TestCustomerDeleteError(t *testing.T) {
	key := "api key"

	mockErrorResponse := new(APIError)
	mockErrorResponse.Type = "invalid_request"
	mockErrorResponse.Message = "You do not have permission to do that"

	mockCustomerID := int64(-999)

	server, err := invdmockserver.New(403, mockErrorResponse, "json", false)

	if err != nil {
		t.Fatal(err)
	}

	defer server.Close()

	conn := mockConnection(key, server)

	customer := conn.NewCustomer()

	customer.Id = mockCustomerID

	err = customer.Delete()

	if err == nil {
		t.Fatal("Error Should Have Been Raised")
	}

	if !reflect.DeepEqual(mockErrorResponse.Error(), err.Error()) {
		t.Fatal("Error Messages Do Not Match Up")
	}

}
开发者ID:Invoiced,项目名称:invoiced-go,代码行数:34,代码来源:customer_test.go


示例2: TestCustomerDelete

func TestCustomerDelete(t *testing.T) {

	key := "api key"

	mockCustomerResponse := ""
	mockCustomerID := int64(2341)

	server, err := invdmockserver.New(204, mockCustomerResponse, "json", true)

	if err != nil {
		t.Fatal(err)
	}

	defer server.Close()

	conn := mockConnection(key, server)

	customer := conn.NewCustomer()

	customer.Id = mockCustomerID

	err = customer.Delete()

	if err != nil {
		t.Fatal("Error occured deleting customer")
	}

}
开发者ID:Invoiced,项目名称:invoiced-go,代码行数:28,代码来源:customer_test.go


示例3: TestSubscriptionDeleteError

func TestSubscriptionDeleteError(t *testing.T) {
	key := "api key"

	mockErrorResponse := new(APIError)
	mockErrorResponse.Type = "invalid_request"
	mockErrorResponse.Message = "You do not have permission to do that"

	mockSubscriptionID := int64(-999)

	server, err := invdmockserver.New(403, mockErrorResponse, "json", true)

	if err != nil {
		t.Fatal(err)
	}

	defer server.Close()

	conn := mockConnection(key, server)

	subscription := conn.NewSubscription()

	subscription.Id = mockSubscriptionID

	err = subscription.Cancel()

	if !reflect.DeepEqual(mockErrorResponse.Error(), err.Error()) {
		t.Fatal("Error Messages Do Not Match Up")
	}

}
开发者ID:Invoiced,项目名称:invoiced-go,代码行数:30,代码来源:subscriptions_test.go


示例4: TestInvoiceUpdateError

func TestInvoiceUpdateError(t *testing.T) {
	key := "wrong api key"

	mockErrorResponse := new(APIError)
	mockErrorResponse.Type = "invalid_request"
	mockErrorResponse.Message = "We could not authenticate the supplied API Key."

	server, err := invdmockserver.New(401, mockErrorResponse, "json", true)

	if err != nil {
		t.Fatal(err)
	}

	defer server.Close()

	conn := mockConnection(key, server)

	invoiceToUpdate := conn.NewInvoice()

	invoiceToUpdate.Balance = 400.12

	err = invoiceToUpdate.Save()

	if err == nil {
		t.Fatal("Error Updating invoice", err)
	}

	if !reflect.DeepEqual(mockErrorResponse.Error(), err.Error()) {
		t.Fatal("Error Messages Do Not Match Up")
	}

}
开发者ID:Invoiced,项目名称:invoiced-go,代码行数:32,代码来源:invoice_test.go


示例5: TestInvoiceDeleteError

func TestInvoiceDeleteError(t *testing.T) {
	key := "api key"

	mockErrorResponse := new(APIError)
	mockErrorResponse.Type = "invalid_request"
	mockErrorResponse.Message = "You Do Not Have Permission To Do That"

	server, err := invdmockserver.New(403, mockErrorResponse, "json", true)

	if err != nil {
		t.Fatal()
	}

	defer server.Close()

	conn := mockConnection(key, server)

	invoice := conn.NewInvoice()

	err = invoice.Delete()

	if err == nil {
		t.Fatal("Error Occured Deleting Invoice")
	}

	if !reflect.DeepEqual(mockErrorResponse.Error(), err.Error()) {
		t.Fatal("Error Messages Do Not Match Up")
	}

}
开发者ID:Invoiced,项目名称:invoiced-go,代码行数:30,代码来源:invoice_test.go


示例6: TestTransactionDelete

func TestTransactionDelete(t *testing.T) {

	key := "api key"

	mocktransactionResponse := ""
	mocktransactionID := int64(2341)

	server, err := invdmockserver.New(204, mocktransactionResponse, "json", true)

	if err != nil {
		t.Fatal(err)
	}

	defer server.Close()

	conn := mockConnection(key, server)

	transaction := conn.NewTransaction()

	transaction.Id = mocktransactionID

	err = transaction.Delete()

	if err != nil {
		t.Fatal("Error Occured Deleting Transaction")
	}

}
开发者ID:Invoiced,项目名称:invoiced-go,代码行数:28,代码来源:transactions_test.go


示例7: TestTransactionCreateError

func TestTransactionCreateError(t *testing.T) {
	key := "test api key"
	mockErrorResponse := new(APIError)
	mockErrorResponse.Type = "invalid_request"
	mockErrorResponse.Message = "Name is invalid"
	mockErrorResponse.Param = "name"

	server, err := invdmockserver.New(400, mockErrorResponse, "json", true)

	if err != nil {
		t.Fatal(err)
	}

	defer server.Close()

	conn := mockConnection(key, server)
	transaction := conn.NewTransaction()
	transactionToCreate := transaction.NewTransaction()
	transactionToCreate.Customer = 234112
	transactionToCreate.GatewayId = "234"

	_, apiErr := transaction.Create(transactionToCreate)

	if apiErr == nil {
		t.Fatal("Api Should Have Errored Out")
	}

	if !reflect.DeepEqual(mockErrorResponse.Error(), apiErr.Error()) {
		t.Fatal("Error Messages Do Not Match Up")
	}

}
开发者ID:Invoiced,项目名称:invoiced-go,代码行数:32,代码来源:transactions_test.go


示例8: TestTransactionUpdate

func TestTransactionUpdate(t *testing.T) {
	key := "test api key"

	mockTransactionResponseID := int64(1523)
	mockTransactionResponse := new(invdendpoint.Transaction)
	mockTransactionResponse.Id = mockTransactionResponseID
	mockTransactionResponse.CreatedAt = time.Now().UnixNano()
	mockTransactionResponse.Customer = 234112
	mockTransactionResponse.GatewayId = "234"

	server, err := invdmockserver.New(200, mockTransactionResponse, "json", true)
	if err != nil {
		t.Fatal(err)
	}
	defer server.Close()

	conn := mockConnection(key, server)

	transactionToUpdate := conn.NewTransaction()

	mockTransactionResponse.Amount = 42
	transactionToUpdate.Amount = 42

	err = transactionToUpdate.Save()

	if err != nil {
		t.Fatal("Error Updating Transaction", err)
	}

	if !reflect.DeepEqual(mockTransactionResponse, transactionToUpdate.Transaction) {
		t.Fatal("Error Transaction Not Updated Properly")
	}

}
开发者ID:Invoiced,项目名称:invoiced-go,代码行数:34,代码来源:transactions_test.go


示例9: TestTransactionRetrieve

func TestTransactionRetrieve(t *testing.T) {

	key := "test api key"

	mockTransactionResponseID := int64(1523)
	mockTransactionResponse := new(invdendpoint.Transaction)
	mockTransactionResponse.Id = mockTransactionResponseID
	mockTransactionResponse.Customer = 234112
	mockTransactionResponse.GatewayId = "234"

	mockTransactionResponse.CreatedAt = time.Now().UnixNano()

	server, err := invdmockserver.New(200, mockTransactionResponse, "json", true)
	if err != nil {
		t.Fatal(err)
	}
	defer server.Close()

	conn := mockConnection(key, server)
	transaction := conn.NewTransaction()

	retrievedTransaction, err := transaction.Retrieve(mockTransactionResponseID)

	if err != nil {
		t.Fatal("Error Creating transaction", err)
	}

	if !reflect.DeepEqual(retrievedTransaction.Transaction, mockTransactionResponse) {
		t.Fatal("Error Messages Do Not Match Up")
	}

}
开发者ID:Invoiced,项目名称:invoiced-go,代码行数:32,代码来源:transactions_test.go


示例10: TestTransactionRetrieveError

func TestTransactionRetrieveError(t *testing.T) {
	key := "api key"

	mockErrorResponse := new(APIError)
	mockErrorResponse.Type = "invalid_request"
	mockErrorResponse.Message = "You do not have permission to do that"

	mockTransactionID := int64(-999)

	server, err := invdmockserver.New(403, mockErrorResponse, "json", true)

	if err != nil {
		t.Fatal(err)
	}
	defer server.Close()

	conn := mockConnection(key, server)
	transaction := conn.NewTransaction()

	_, err = transaction.Retrieve(mockTransactionID)

	if !reflect.DeepEqual(mockErrorResponse.Error(), err.Error()) {
		t.Fatal("Error Messages Do Not Match Up")
	}

}
开发者ID:Invoiced,项目名称:invoiced-go,代码行数:26,代码来源:transactions_test.go


示例11: TestInvoiceListError

func TestInvoiceListError(t *testing.T) {
	key := "api key"

	mockErrorResponse := new(APIError)
	mockErrorResponse.Type = "invalid_request"
	mockErrorResponse.Message = "You do not have permission to do that"

	mockInvoiceNumber := "INV-32421"

	server, err := invdmockserver.New(403, mockErrorResponse, "json", true)

	if err != nil {
		t.Fatal(err)
	}

	defer server.Close()

	conn := mockConnection(key, server)

	invoice := conn.NewInvoice()

	_, err = invoice.ListInvoiceByNumber(mockInvoiceNumber)

	if err == nil {
		t.Fatal("Error occured deleting invoice")
	}

	if !reflect.DeepEqual(mockErrorResponse.Error(), err.Error()) {
		t.Fatal("Error Messages Do Not Match Up")
	}

}
开发者ID:Invoiced,项目名称:invoiced-go,代码行数:32,代码来源:invoice_test.go


示例12: TestCustomerUpdateError

func TestCustomerUpdateError(t *testing.T) {
	key := "wrong api key"

	mockErrorResponse := new(APIError)
	mockErrorResponse.Type = "invalid_request"
	mockErrorResponse.Message = "We could not authenticate the supplied API Key."

	server, err := invdmockserver.New(401, mockErrorResponse, "json", true)

	if err != nil {
		t.Fatal(err)
	}

	defer server.Close()

	conn := mockConnection(key, server)

	customer := conn.NewCustomer()
	customer.Name = "Parag Patel"
	customer.Id = 3411111
	customer.City = "Austin"

	err = customer.Save()

	if err == nil {
		t.Fatal("Error Updating Customer => ", err)
	}

	if !reflect.DeepEqual(mockErrorResponse.Error(), err.Error()) {
		t.Fatal("Error Messages Do Not Match Up")
	}

}
开发者ID:Invoiced,项目名称:invoiced-go,代码行数:33,代码来源:customer_test.go


示例13: TestInvoiceDelete

func TestInvoiceDelete(t *testing.T) {

	key := "api key"

	mockinvoiceResponse := ""
	mockinvoiceID := int64(2341)

	server, err := invdmockserver.New(204, mockinvoiceResponse, "json", true)

	if err != nil {
		t.Fatal(err)
	}

	defer server.Close()

	conn := mockConnection(key, server)

	invoice := conn.NewInvoice()

	invoice.Id = mockinvoiceID

	err = invoice.Delete()

	if err != nil {
		t.Fatal("Error Occured Deleting Invoice")
	}

}
开发者ID:Invoiced,项目名称:invoiced-go,代码行数:28,代码来源:invoice_test.go


示例14: TestSubscriptionUpdate

func TestSubscriptionUpdate(t *testing.T) {
	key := "test api key"

	mockSubscriptionResponseID := int64(1523)
	mockSubscriptionResponse := new(invdendpoint.Subscription)
	mockSubscriptionResponse.Id = mockSubscriptionResponseID
	mockSubscriptionResponse.CreatedAt = time.Now().UnixNano()
	mockSubscriptionResponse.Customer = 234112
	mockSubscriptionResponse.Plan = "234"

	server, err := invdmockserver.New(200, mockSubscriptionResponse, "json", true)
	if err != nil {
		t.Fatal(err)
	}
	defer server.Close()

	conn := mockConnection(key, server)

	subscriptionToUpdate := conn.NewSubscription()

	mockSubscriptionResponse.Cycles = 42
	subscriptionToUpdate.Cycles = 42

	err = subscriptionToUpdate.Save()

	if err != nil {
		t.Fatal("Error Updating Subscription", err)
	}

	if !reflect.DeepEqual(mockSubscriptionResponse, subscriptionToUpdate.Subscription) {
		t.Fatal("Error Subscription Not Updated Properly")
	}

}
开发者ID:Invoiced,项目名称:invoiced-go,代码行数:34,代码来源:subscriptions_test.go


示例15: TestSubscriptionDelete

func TestSubscriptionDelete(t *testing.T) {

	key := "api key"

	mocksubscriptionResponse := ""
	mocksubscriptionID := int64(2341)

	server, err := invdmockserver.New(204, mocksubscriptionResponse, "json", true)

	if err != nil {
		t.Fatal(err)
	}

	defer server.Close()

	conn := mockConnection(key, server)

	subscription := conn.NewSubscription()

	subscription.Id = mocksubscriptionID

	err = subscription.Cancel()

	if err != nil {
		t.Fatal("Error Occured Canceling Subscription")
	}

}
开发者ID:Invoiced,项目名称:invoiced-go,代码行数:28,代码来源:subscriptions_test.go


示例16: TestInvoiceCreateError

func TestInvoiceCreateError(t *testing.T) {
	key := "test api key"
	mockErrorResponse := new(APIError)
	mockErrorResponse.Type = "invalid_request"
	mockErrorResponse.Message = "Name is invalid"
	mockErrorResponse.Param = "name"

	server, err := invdmockserver.New(400, mockErrorResponse, "json", true)

	if err != nil {
		t.Fatal(err)
	}

	defer server.Close()

	conn := mockConnection(key, server)

	invoice := conn.NewInvoice()

	invoiceToCreate := invoice.NewInvoice()
	invoiceToCreate.Total = 342.234

	_, err = invoice.Create(invoiceToCreate)

	if err == nil {
		t.Fatal("Api Should Have Errored Out")
	}

	if !reflect.DeepEqual(mockErrorResponse.Error(), err.Error()) {
		t.Fatal("Error Messages Do Not Match Up")
	}

}
开发者ID:Invoiced,项目名称:invoiced-go,代码行数:33,代码来源:invoice_test.go


示例17: TestCustomerCreateError

func TestCustomerCreateError(t *testing.T) {
	key := "test api key"
	mockErrorResponse := new(APIError)
	mockErrorResponse.Type = "invalid_request"
	mockErrorResponse.Message = "Name is invalid"
	mockErrorResponse.Param = "name"

	server, err := invdmockserver.New(400, mockErrorResponse, "json", true)

	if err != nil {
		t.Fatal(err)
	}

	defer server.Close()

	conn := mockConnection(key, server)

	custConn := conn.NewCustomer()

	customerToCreate := custConn.NewCustomer()
	customerToCreate.Email = "[email protected]"

	_, apiErr := custConn.Create(customerToCreate)

	if apiErr == nil {
		t.Fatal("Api should have errored out")
	}

	if !reflect.DeepEqual(mockErrorResponse.Error(), apiErr.Error()) {
		t.Fatal("Error messages do not match up", mockErrorResponse, ",", apiErr)
	}

}
开发者ID:Invoiced,项目名称:invoiced-go,代码行数:33,代码来源:customer_test.go


示例18: TestCustomerCreate

func TestCustomerCreate(t *testing.T) {

	//Set up the mock customer response
	mockCustomerResponseID := int64(1523)
	mockCustomerResponse := new(Customer)
	mockCustomerResponseData := new(invdendpoint.Customer)
	mockCustomerResponse.Customer = mockCustomerResponseData
	mockCustomerResponse.Id = mockCustomerResponseID

	//Launch our mock server
	server, err := invdmockserver.New(200, mockCustomerResponse, "json", true)

	if err != nil {
		t.Fatal(err)
	}

	defer server.Close()

	//Establish our mock connection
	key := "test api key"
	conn := mockConnection(key, server)

	customer := conn.NewCustomer()

	nowUnix := time.Now().UnixNano()
	s := strconv.FormatInt(nowUnix, 10)

	customerToCreate := customer.NewCustomer()
	customerToCreate.Name = "Test Customer Original " + s
	customerToCreate.Id = mockCustomerResponse.Id
	mockCustomerResponse.Name = customerToCreate.Name
	//mockCustomerResponse.Connection = conn

	//Make the call to create our customer
	createdCustomer, err := customer.Create(customerToCreate)

	if err != nil {
		t.Fatal("Error Creating Customer", err)
	}

	//Customer that we wanted to create should equal the customer we created
	if !reflect.DeepEqual(createdCustomer, customerToCreate) {
		t.Fatal(createdCustomer.Customer, customerToCreate.Customer)
	}

}
开发者ID:Invoiced,项目名称:invoiced-go,代码行数:46,代码来源:customer_test.go


示例19: TestCustomerList

func TestCustomerList(t *testing.T) {

	key := "test api key"

	var mockCustomersResponse invdendpoint.Customers
	mockCustomerResponseID := int64(1523)
	mockCustomerResponse := new(invdendpoint.Customer)
	mockCustomerResponse.Id = mockCustomerResponseID
	mockCustomerResponse.Name = "Mock Customer"
	mockCustomerResponse.Address1 = "23 Wayne street"
	mockCustomerResponse.City = "Austin"
	mockCustomerResponse.Country = "USA"
	mockCustomerResponse.CreatedAt = time.Now().UnixNano()
	mockCustomerResponse.Number = "CUST-21312"

	mockCustomersResponse = append(mockCustomersResponse, *mockCustomerResponse)

	server, err := invdmockserver.New(200, mockCustomersResponse, "json", true)

	if err != nil {
		t.Fatal(err)
	}

	defer server.Close()

	conn := mockConnection(key, server)

	customer := conn.NewCustomer()

	retrievedCustomer, err := customer.ListCustomerByNumber("CUST-21312")

	if err != nil {
		t.Fatal("Error Creating Customer", err)
	}

	if !reflect.DeepEqual(retrievedCustomer.Customer, mockCustomerResponse) {
		t.Fatal("Retrieved Customer does not match the mock customer retrievedCustomer => ", retrievedCustomer.Customer, ", mockCustomer => ", mockCustomerResponse)
	}

}
开发者ID:Invoiced,项目名称:invoiced-go,代码行数:40,代码来源:customer_test.go


示例20: TestCustomerUpdate

func TestCustomerUpdate(t *testing.T) {
	key := "test api key"

	mockCustomerResponseID := int64(1523)
	mockCreatedTime := time.Now().UnixNano()
	mockName := "MOCK CUSTOMER"
	mockCustomerResponse := new(invdendpoint.Customer)
	mockCustomerResponse.Id = mockCustomerResponseID
	mockCustomerResponse.Name = mockName
	mockCustomerResponse.CreatedAt = mockCreatedTime

	server, err := invdmockserver.New(200, mockCustomerResponse, "json", true)

	if err != nil {
		t.Fatal(err)
	}

	defer server.Close()

	conn := mockConnection(key, server)

	customerToUpdate := conn.NewCustomer()

	customerToUpdate.Id = mockCustomerResponseID
	customerToUpdate.Name = "MOCK CUSTOMER"
	addressToUpdate := "7500 Rialto BLVD"
	customerToUpdate.Address1 = addressToUpdate
	mockCustomerResponse.Address1 = addressToUpdate

	apiErr := customerToUpdate.Save()

	if apiErr != nil {
		t.Fatal("Error Updating Customer", apiErr)
	}

	if !reflect.DeepEqual(mockCustomerResponse, customerToUpdate.Customer) {
		t.Fatal("Updated Customers Do Not Match Up")
	}

}
开发者ID:Invoiced,项目名称:invoiced-go,代码行数:40,代码来源:customer_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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