github.com/go-chef/chef@v0.30.1/principal_test.go (about) 1 package chef 2 3 import ( 4 "fmt" 5 "net/http" 6 "reflect" 7 "testing" 8 ) 9 10 func TestPrincipalsGet(t *testing.T) { 11 setup() 12 defer teardown() 13 14 mux.HandleFunc("/principals/client_node", func(w http.ResponseWriter, r *http.Request) { 15 fmt.Fprint(w, `{ 16 "principals": [{ 17 "name": "client_node", 18 "type": "client", 19 "authz_id": "afe1234", 20 "org_member": true, 21 "public_key": "-----BEGIN PUBLIC KEY" 22 }]}`) 23 }) 24 25 p, err := client.Principals.Get("client_node") 26 if err != nil { 27 t.Errorf("GET principal error %+v making request: ", err) 28 return 29 } 30 31 pWant := Principal{} 32 client := Principals{ 33 Name: "client_node", 34 Type: "client", 35 PublicKey: "-----BEGIN PUBLIC KEY", 36 AuthzId: "afe1234", 37 OrgMember: true, 38 } 39 pWant.Principals = append(pWant.Principals, client) 40 41 if !reflect.DeepEqual(p, pWant) { 42 t.Errorf("Unexpected principal values got: %+v wanted: %+v", p, pWant) 43 } 44 }