コード例 #1
0
func TestPullRequestsService_CreateComment(t *testing.T) {
	setup()
	defer teardown()

	pullSpec := PullRequestSpec{Repo: RepoSpec{URI: "r.com/foo"}, Number: 22}
	comment := PullRequestComment{
		PullRequestComment: github.PullRequestComment{
			Body:      github.String("this is a comment"),
			Path:      github.String("/"),
			Position:  github.Int(2),
			CommitID:  github.String("54be46135e45be9bd3318b8fd39a456ff1e2895e"),
			User:      &github.User{},
			CreatedAt: timePtr(time.Unix(100, 100).UTC()),
			UpdatedAt: timePtr(time.Unix(200, 200).UTC()),
		},
	}
	wantComment := comment
	wantComment.ID = github.Int(1)

	called := false
	mux.HandleFunc(urlPath(t, router.RepoPullRequestCommentsCreate, pullSpec.RouteVars()), func(w http.ResponseWriter, req *http.Request) {
		called = true
		testMethod(t, req, "POST")

		var unmarshalled PullRequestComment
		err := json.NewDecoder(req.Body).Decode(&unmarshalled)
		if err != nil {
			t.Fatal(err)
		}
		if !reflect.DeepEqual(unmarshalled, comment) {
			t.Errorf("Got unmarshalled comment %+v, want %+v", unmarshalled, comment)
		}

		writeJSON(w, wantComment)
	})

	gotComment, _, err := client.PullRequests.CreateComment(pullSpec, &comment)
	if err != nil {
		t.Fatal(err)
	}

	if !called {
		t.Errorf("!called")
	}

	if !jsonEqual(t, gotComment, wantComment) {
		t.Errorf("Got %+v, want %+v", gotComment, wantComment)
	}
}
コード例 #2
0
func TestPullRequestsService_EditComment_ErrorNoID(t *testing.T) {
	setup()
	defer teardown()

	pullSpec := PullRequestSpec{Repo: RepoSpec{URI: "r.com/foo"}, Number: 22}
	comment := PullRequestComment{
		PullRequestComment: github.PullRequestComment{
			Body:      github.String("this is a comment"),
			Path:      github.String("/"),
			Position:  github.Int(2),
			CommitID:  github.String("54be46135e45be9bd3318b8fd39a456ff1e2895e"),
			User:      &github.User{},
			CreatedAt: timePtr(time.Unix(100, 100).UTC()),
			UpdatedAt: timePtr(time.Unix(200, 200).UTC()),
		},
	}

	_, _, err := client.PullRequests.EditComment(pullSpec, &comment)
	if err.Error() != "comment ID not specified" {
		t.Errorf(`expected error "comment ID not specified", but got none`)
	}
}
コード例 #3
0
func TestPullRequestsService_Merge(t *testing.T) {
	setup()
	defer teardown()

	pullSpec := PullRequestSpec{Repo: RepoSpec{URI: "r.com/foo"}, Number: 22}
	mergeRequest := &PullRequestMergeRequest{CommitMessage: "message"}
	wantMergeResult := &PullRequestMergeResult{github.PullRequestMergeResult{
		SHA:     github.String("42c066aecc289359dcaaff61e9a85396ed7c376f"),
		Merged:  github.Bool(true),
		Message: github.String("Pull Request successfully merged"),
	}}

	called := false
	mux.HandleFunc(urlPath(t, router.RepoPullRequestMerge, pullSpec.RouteVars()), func(w http.ResponseWriter, req *http.Request) {
		called = true
		testMethod(t, req, "PUT")

		var unmarshalled PullRequestMergeRequest
		err := json.NewDecoder(req.Body).Decode(&unmarshalled)
		if err != nil {
			t.Fatal(err)
		}
		if !reflect.DeepEqual(&unmarshalled, mergeRequest) {
			t.Errorf("Got unmarshalled merge request %+v, want %+v", unmarshalled, mergeRequest)
		}

		writeJSON(w, wantMergeResult)
	})

	mergeResult, _, err := client.PullRequests.Merge(pullSpec, mergeRequest)
	if err != nil {
		t.Fatal(err)
	}

	if !reflect.DeepEqual(mergeResult, wantMergeResult) {
		t.Errorf("got %+v, want %+v", mergeResult, wantMergeResult)
	}
}