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


Golang invdmockserver.New函數代碼示例

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


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


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