github.com/google/go-github/v66@v66.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: Int64(1), 45 ClientID: String("a"), 46 ClientSecret: String("b"), 47 WebhookSecret: String("c"), 48 PEM: String("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: Int64(1), 76 Slug: String("s"), 77 NodeID: String("nid"), 78 Owner: &User{ 79 Login: String("l"), 80 ID: Int64(1), 81 URL: String("u"), 82 AvatarURL: String("a"), 83 GravatarID: String("g"), 84 Name: String("n"), 85 Company: String("c"), 86 Blog: String("b"), 87 Location: String("l"), 88 Email: String("e"), 89 Hireable: Bool(true), 90 Bio: String("b"), 91 TwitterUsername: String("t"), 92 PublicRepos: Int(1), 93 Followers: Int(1), 94 Following: Int(1), 95 CreatedAt: &Timestamp{referenceTime}, 96 SuspendedAt: &Timestamp{referenceTime}, 97 }, 98 Name: String("n"), 99 Description: String("d"), 100 ExternalURL: String("eu"), 101 HTMLURL: String("hu"), 102 CreatedAt: &Timestamp{referenceTime}, 103 UpdatedAt: &Timestamp{referenceTime}, 104 ClientID: String("ci"), 105 ClientSecret: String("cs"), 106 WebhookSecret: String("ws"), 107 PEM: String("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 }