...

Source file src/github.com/google/go-github/v47/github/apps_hooks_test.go

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

     1  // Copyright 2021 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  func TestAppsService_GetHookConfig(t *testing.T) {
    18  	client, mux, _, teardown := setup()
    19  	defer teardown()
    20  
    21  	mux.HandleFunc("/app/hook/config", func(w http.ResponseWriter, r *http.Request) {
    22  		testMethod(t, r, "GET")
    23  		fmt.Fprint(w, `{
    24  			"content_type": "json",
    25  			"insecure_ssl": "0",
    26  			"secret": "********",
    27  			"url": "https://example.com/webhook"
    28  		}`)
    29  	})
    30  
    31  	ctx := context.Background()
    32  	config, _, err := client.Apps.GetHookConfig(ctx)
    33  	if err != nil {
    34  		t.Errorf("Apps.GetHookConfig returned error: %v", err)
    35  	}
    36  
    37  	want := &HookConfig{
    38  		ContentType: String("json"),
    39  		InsecureSSL: String("0"),
    40  		Secret:      String("********"),
    41  		URL:         String("https://example.com/webhook"),
    42  	}
    43  	if !cmp.Equal(config, want) {
    44  		t.Errorf("Apps.GetHookConfig returned %+v, want %+v", config, want)
    45  	}
    46  
    47  	const methodName = "GetHookConfig"
    48  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
    49  		got, resp, err := client.Apps.GetHookConfig(ctx)
    50  		if got != nil {
    51  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
    52  		}
    53  		return resp, err
    54  	})
    55  }
    56  
    57  func TestAppsService_UpdateHookConfig(t *testing.T) {
    58  	client, mux, _, teardown := setup()
    59  	defer teardown()
    60  
    61  	input := &HookConfig{
    62  		ContentType: String("json"),
    63  		InsecureSSL: String("1"),
    64  		Secret:      String("s"),
    65  		URL:         String("u"),
    66  	}
    67  
    68  	mux.HandleFunc("/app/hook/config", func(w http.ResponseWriter, r *http.Request) {
    69  		testMethod(t, r, "PATCH")
    70  		testBody(t, r, `{"content_type":"json","insecure_ssl":"1","url":"u","secret":"s"}`+"\n")
    71  		fmt.Fprint(w, `{
    72  			"content_type": "json",
    73  			"insecure_ssl": "1",
    74  			"secret": "********",
    75  			"url": "u"
    76  		}`)
    77  	})
    78  
    79  	ctx := context.Background()
    80  	config, _, err := client.Apps.UpdateHookConfig(ctx, input)
    81  	if err != nil {
    82  		t.Errorf("Apps.UpdateHookConfig returned error: %v", err)
    83  	}
    84  
    85  	want := &HookConfig{
    86  		ContentType: String("json"),
    87  		InsecureSSL: String("1"),
    88  		Secret:      String("********"),
    89  		URL:         String("u"),
    90  	}
    91  	if !cmp.Equal(config, want) {
    92  		t.Errorf("Apps.UpdateHookConfig returned %+v, want %+v", config, want)
    93  	}
    94  
    95  	const methodName = "UpdateHookConfig"
    96  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
    97  		got, resp, err := client.Apps.UpdateHookConfig(ctx, input)
    98  		if got != nil {
    99  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
   100  		}
   101  		return resp, err
   102  	})
   103  }
   104  

View as plain text