本文整理汇总了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")
}
}
示例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")
}
}
示例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")
}
}
示例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")
}
}
示例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")
}
}
示例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")
}
}
示例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")
}
}
示例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")
}
}
示例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")
}
}
示例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")
}
}
示例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")
}
}
示例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")
}
}
示例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")
}
}
示例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")
}
}
示例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")
}
}