github.com/google/go-github/v33@v33.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  	"reflect"
    13  	"testing"
    14  )
    15  
    16  const (
    17  	manifestJSON = `{
    18  	"id": 1,
    19    "client_id": "a" ,
    20    "client_secret": "b",
    21    "webhook_secret": "c",
    22    "pem": "key"
    23  }
    24  `
    25  )
    26  
    27  func TestGetConfig(t *testing.T) {
    28  	client, mux, _, teardown := setup()
    29  	defer teardown()
    30  
    31  	mux.HandleFunc("/app-manifests/code/conversions", func(w http.ResponseWriter, r *http.Request) {
    32  		testMethod(t, r, "POST")
    33  		testHeader(t, r, "Accept", mediaTypeAppManifestPreview)
    34  		fmt.Fprint(w, manifestJSON)
    35  	})
    36  
    37  	cfg, _, err := client.Apps.CompleteAppManifest(context.Background(), "code")
    38  	if err != nil {
    39  		t.Errorf("AppManifest.GetConfig returned error: %v", err)
    40  	}
    41  
    42  	want := &AppConfig{
    43  		ID:            Int64(1),
    44  		ClientID:      String("a"),
    45  		ClientSecret:  String("b"),
    46  		WebhookSecret: String("c"),
    47  		PEM:           String("key"),
    48  	}
    49  
    50  	if !reflect.DeepEqual(cfg, want) {
    51  		t.Errorf("GetConfig returned %+v, want %+v", cfg, want)
    52  	}
    53  }