github.com/google/go-github/v33@v33.0.0/github/repos_merging_test.go (about)

     1  // Copyright 2014 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  	"encoding/json"
    11  	"fmt"
    12  	"net/http"
    13  	"reflect"
    14  	"testing"
    15  )
    16  
    17  func TestRepositoriesService_Merge(t *testing.T) {
    18  	client, mux, _, teardown := setup()
    19  	defer teardown()
    20  
    21  	input := &RepositoryMergeRequest{
    22  		Base:          String("b"),
    23  		Head:          String("h"),
    24  		CommitMessage: String("c"),
    25  	}
    26  
    27  	mux.HandleFunc("/repos/o/r/merges", func(w http.ResponseWriter, r *http.Request) {
    28  		v := new(RepositoryMergeRequest)
    29  		json.NewDecoder(r.Body).Decode(v)
    30  
    31  		testMethod(t, r, "POST")
    32  		if !reflect.DeepEqual(v, input) {
    33  			t.Errorf("Request body = %+v, want %+v", v, input)
    34  		}
    35  
    36  		fmt.Fprint(w, `{"sha":"s"}`)
    37  	})
    38  
    39  	commit, _, err := client.Repositories.Merge(context.Background(), "o", "r", input)
    40  	if err != nil {
    41  		t.Errorf("Repositories.Merge returned error: %v", err)
    42  	}
    43  
    44  	want := &RepositoryCommit{SHA: String("s")}
    45  	if !reflect.DeepEqual(commit, want) {
    46  		t.Errorf("Repositories.Merge returned %+v, want %+v", commit, want)
    47  	}
    48  }