/usr/share/gocode/src/github.com/weppos/dnsimple-go/dnsimple/contacts_test.go is in golang-github-weppos-dnsimple-go-dev 0.0~git20160204.0.65c1ca7-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | package dnsimple
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestContacts_contactPath(t *testing.T) {
var pathTests = []struct {
input interface{}
expected string
}{
{nil, "contacts"},
{1, "contacts/1"},
}
for _, pt := range pathTests {
actual := contactPath(pt.input)
if actual != pt.expected {
t.Errorf("contactPath(%+v): expected %s, actual %s", pt.input, pt.expected)
}
}
}
func TestContactsService_List(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v1/contacts", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `[{"contact":{"id":1,"label":"Default"}},{"contact":{"id":2,"label":"Simone"}}]`)
})
contacts, _, err := client.Contacts.List()
if err != nil {
t.Errorf("Contacts.List returned error: %v", err)
}
if size, want := len(contacts), 2; size != want {
t.Fatalf("Contacts.List returned %+v items, want %+v", size, want)
}
for i, item := range contacts {
if kind, want := reflect.TypeOf(item).Name(), "Contact"; kind != want {
t.Errorf("Contacts.List expected [%d] to be %s, got %s", i, want, kind)
}
}
}
func TestContactsService_Create(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v1/contacts", func(w http.ResponseWriter, r *http.Request) {
want := make(map[string]interface{})
want["contact"] = map[string]interface{}{"label": "Default"}
testMethod(t, r, "POST")
testRequestJSON(t, r, want)
fmt.Fprintf(w, `{"contact":{"id":1, "label":"Default"}}`)
})
contactValues := Contact{Label: "Default"}
contact, _, err := client.Contacts.Create(contactValues)
if err != nil {
t.Errorf("Contacts.Create returned error: %v", err)
}
want := Contact{Id: 1, Label: "Default"}
if !reflect.DeepEqual(contact, want) {
t.Fatalf("Contacts.Create returned %+v, want %+v", contact, want)
}
}
func TestContactsService_Get(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v1/contacts/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"contact":{"id":1,"user_id":21,"label":"Default","first_name":"Simone","last_name":"Carletti","job_title":"Underwater Programmer","organization_name":"DNSimple","email_address":"simone.carletti@dnsimple.com","phone":"+1 111 4567890","fax":"+1 222 4567890","address1":"Awesome Street","address2":"c/o Someone","city":"Rome","state_province":"RM","postal_code":"00171","country":"IT"}}`)
})
contact, _, err := client.Contacts.Get(1)
if err != nil {
t.Errorf("Contacts.Get returned error: %v", err)
}
want := Contact{
Id: 1,
Label: "Default",
FirstName: "Simone",
LastName: "Carletti",
JobTitle: "Underwater Programmer",
Organization: "DNSimple",
Email: "simone.carletti@dnsimple.com",
Phone: "+1 111 4567890",
Fax: "+1 222 4567890",
Address1: "Awesome Street",
Address2: "c/o Someone",
City: "Rome",
Zip: "00171",
Country: "IT"}
if !reflect.DeepEqual(contact, want) {
t.Fatalf("Contacts.Get returned %+v, want %+v", contact, want)
}
}
func TestContactsService_Update(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v1/contacts/1", func(w http.ResponseWriter, r *http.Request) {
want := make(map[string]interface{})
want["contact"] = map[string]interface{}{"label": "Default"}
testMethod(t, r, "PUT")
testRequestJSON(t, r, want)
fmt.Fprint(w, `{"contact":{"id":1, "label": "Default"}}`)
})
contactValues := Contact{Label: "Default"}
contact, _, err := client.Contacts.Update(1, contactValues)
if err != nil {
t.Errorf("Contacts.Update returned error: %v", err)
}
want := Contact{Id: 1, Label: "Default"}
if !reflect.DeepEqual(contact, want) {
t.Fatalf("Contacts.Update returned %+v, want %+v", contact, want)
}
}
func TestContactsService_Delete(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v1/contacts/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
w.WriteHeader(http.StatusNoContent)
})
_, err := client.Contacts.Delete(1)
if err != nil {
t.Errorf("Contacts.Delete returned error: %v", err)
}
}
|