...

Source file src/github.com/google/go-github/v55/github/apps_manifest_test.go

Documentation: github.com/google/go-github/v55/github

     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  	client, mux, _, teardown := setup()
    30  	defer teardown()
    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  	testJSONMarshal(t, &AppConfig{}, "{}")
    72  
    73  	u := &AppConfig{
    74  		ID:     Int64(1),
    75  		Slug:   String("s"),
    76  		NodeID: String("nid"),
    77  		Owner: &User{
    78  			Login:           String("l"),
    79  			ID:              Int64(1),
    80  			URL:             String("u"),
    81  			AvatarURL:       String("a"),
    82  			GravatarID:      String("g"),
    83  			Name:            String("n"),
    84  			Company:         String("c"),
    85  			Blog:            String("b"),
    86  			Location:        String("l"),
    87  			Email:           String("e"),
    88  			Hireable:        Bool(true),
    89  			Bio:             String("b"),
    90  			TwitterUsername: String("t"),
    91  			PublicRepos:     Int(1),
    92  			Followers:       Int(1),
    93  			Following:       Int(1),
    94  			CreatedAt:       &Timestamp{referenceTime},
    95  			SuspendedAt:     &Timestamp{referenceTime},
    96  		},
    97  		Name:          String("n"),
    98  		Description:   String("d"),
    99  		ExternalURL:   String("eu"),
   100  		HTMLURL:       String("hu"),
   101  		CreatedAt:     &Timestamp{referenceTime},
   102  		UpdatedAt:     &Timestamp{referenceTime},
   103  		ClientID:      String("ci"),
   104  		ClientSecret:  String("cs"),
   105  		WebhookSecret: String("ws"),
   106  		PEM:           String("pem"),
   107  	}
   108  
   109  	want := `{
   110  		"id": 1,
   111  		"slug": "s",
   112  		"node_id": "nid",
   113  		"owner": {
   114  			"login": "l",
   115  			"id": 1,
   116  			"avatar_url": "a",
   117  			"gravatar_id": "g",
   118  			"name": "n",
   119  			"company": "c",
   120  			"blog": "b",
   121  			"location": "l",
   122  			"email": "e",
   123  			"hireable": true,
   124  			"bio": "b",
   125  			"twitter_username": "t",
   126  			"public_repos": 1,
   127  			"followers": 1,
   128  			"following": 1,
   129  			"created_at": ` + referenceTimeStr + `,
   130  			"suspended_at": ` + referenceTimeStr + `,
   131  			"url": "u"
   132  		},
   133  		"name": "n",
   134  		"description": "d",
   135  		"external_url": "eu",
   136  		"html_url": "hu",
   137  		"created_at": ` + referenceTimeStr + `,
   138  		"updated_at": ` + referenceTimeStr + `,
   139  		"client_id": "ci",
   140  		"client_secret": "cs",
   141  		"webhook_secret": "ws",
   142  		"pem": "pem"
   143  	}`
   144  
   145  	testJSONMarshal(t, u, want)
   146  }
   147  

View as plain text