github.com/google/go-github/v74@v74.0.0/github/apps_manifest_test.go (about) 1 // Copyright 2019 The go-github AUTHORS. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 package github 7 8 import ( 9 "context" 10 "fmt" 11 "net/http" 12 "testing" 13 14 "github.com/google/go-cmp/cmp" 15 ) 16 17 const ( 18 manifestJSON = `{ 19 "id": 1, 20 "client_id": "a" , 21 "client_secret": "b", 22 "webhook_secret": "c", 23 "pem": "key" 24 } 25 ` 26 ) 27 28 func TestGetConfig(t *testing.T) { 29 t.Parallel() 30 client, mux, _ := setup(t) 31 32 mux.HandleFunc("/app-manifests/code/conversions", func(w http.ResponseWriter, r *http.Request) { 33 testMethod(t, r, "POST") 34 fmt.Fprint(w, manifestJSON) 35 }) 36 37 ctx := context.Background() 38 cfg, _, err := client.Apps.CompleteAppManifest(ctx, "code") 39 if err != nil { 40 t.Errorf("AppManifest.GetConfig returned error: %v", err) 41 } 42 43 want := &AppConfig{ 44 ID: Ptr(int64(1)), 45 ClientID: Ptr("a"), 46 ClientSecret: Ptr("b"), 47 WebhookSecret: Ptr("c"), 48 PEM: Ptr("key"), 49 } 50 51 if !cmp.Equal(cfg, want) { 52 t.Errorf("GetConfig returned %+v, want %+v", cfg, want) 53 } 54 55 const methodName = "CompleteAppManifest" 56 testBadOptions(t, methodName, func() (err error) { 57 _, _, err = client.Apps.CompleteAppManifest(ctx, "\n") 58 return err 59 }) 60 61 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 62 got, resp, err := client.Apps.CompleteAppManifest(ctx, "code") 63 if got != nil { 64 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 65 } 66 return resp, err 67 }) 68 } 69 70 func TestAppConfig_Marshal(t *testing.T) { 71 t.Parallel() 72 testJSONMarshal(t, &AppConfig{}, "{}") 73 74 u := &AppConfig{ 75 ID: Ptr(int64(1)), 76 Slug: Ptr("s"), 77 NodeID: Ptr("nid"), 78 Owner: &User{ 79 Login: Ptr("l"), 80 ID: Ptr(int64(1)), 81 URL: Ptr("u"), 82 AvatarURL: Ptr("a"), 83 GravatarID: Ptr("g"), 84 Name: Ptr("n"), 85 Company: Ptr("c"), 86 Blog: Ptr("b"), 87 Location: Ptr("l"), 88 Email: Ptr("e"), 89 Hireable: Ptr(true), 90 Bio: Ptr("b"), 91 TwitterUsername: Ptr("t"), 92 PublicRepos: Ptr(1), 93 Followers: Ptr(1), 94 Following: Ptr(1), 95 CreatedAt: &Timestamp{referenceTime}, 96 SuspendedAt: &Timestamp{referenceTime}, 97 }, 98 Name: Ptr("n"), 99 Description: Ptr("d"), 100 ExternalURL: Ptr("eu"), 101 HTMLURL: Ptr("hu"), 102 CreatedAt: &Timestamp{referenceTime}, 103 UpdatedAt: &Timestamp{referenceTime}, 104 ClientID: Ptr("ci"), 105 ClientSecret: Ptr("cs"), 106 WebhookSecret: Ptr("ws"), 107 PEM: Ptr("pem"), 108 } 109 110 want := `{ 111 "id": 1, 112 "slug": "s", 113 "node_id": "nid", 114 "owner": { 115 "login": "l", 116 "id": 1, 117 "avatar_url": "a", 118 "gravatar_id": "g", 119 "name": "n", 120 "company": "c", 121 "blog": "b", 122 "location": "l", 123 "email": "e", 124 "hireable": true, 125 "bio": "b", 126 "twitter_username": "t", 127 "public_repos": 1, 128 "followers": 1, 129 "following": 1, 130 "created_at": ` + referenceTimeStr + `, 131 "suspended_at": ` + referenceTimeStr + `, 132 "url": "u" 133 }, 134 "name": "n", 135 "description": "d", 136 "external_url": "eu", 137 "html_url": "hu", 138 "created_at": ` + referenceTimeStr + `, 139 "updated_at": ` + referenceTimeStr + `, 140 "client_id": "ci", 141 "client_secret": "cs", 142 "webhook_secret": "ws", 143 "pem": "pem" 144 }` 145 146 testJSONMarshal(t, u, want) 147 }