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

     1  // Copyright 2016 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  	"strings"
    14  	"testing"
    15  )
    16  
    17  func TestIssuesService_ListIssueTimeline(t *testing.T) {
    18  	client, mux, _, teardown := setup()
    19  	defer teardown()
    20  
    21  	wantAcceptHeaders := []string{mediaTypeTimelinePreview, mediaTypeProjectCardDetailsPreview}
    22  	mux.HandleFunc("/repos/o/r/issues/1/timeline", func(w http.ResponseWriter, r *http.Request) {
    23  		testMethod(t, r, "GET")
    24  		testHeader(t, r, "Accept", strings.Join(wantAcceptHeaders, ", "))
    25  		testFormValues(t, r, values{
    26  			"page":     "1",
    27  			"per_page": "2",
    28  		})
    29  		fmt.Fprint(w, `[{"id":1}]`)
    30  	})
    31  
    32  	opt := &ListOptions{Page: 1, PerPage: 2}
    33  	events, _, err := client.Issues.ListIssueTimeline(context.Background(), "o", "r", 1, opt)
    34  	if err != nil {
    35  		t.Errorf("Issues.ListIssueTimeline returned error: %v", err)
    36  	}
    37  
    38  	want := []*Timeline{{ID: Int64(1)}}
    39  	if !reflect.DeepEqual(events, want) {
    40  		t.Errorf("Issues.ListIssueTimeline = %+v, want %+v", events, want)
    41  	}
    42  }