| // Copyright 2020 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| package main |
| |
| import ( |
| "context" |
| "testing" |
| |
| "github.com/golang/mock/gomock" |
| "go.chromium.org/luci/common/proto/git" |
| gitilespb "go.chromium.org/luci/common/proto/gitiles" |
| ) |
| |
| func TestGetLatestCommit(t *testing.T) { |
| t.Parallel() |
| var tests = []struct { |
| project string |
| expected string |
| }{ |
| { |
| project: "test-project", |
| expected: "foobar", |
| }, |
| } |
| for _, test := range tests { |
| ctrl := gomock.NewController(t) |
| defer ctrl.Finish() |
| mockGitilesClient := gitilespb.NewMockGitilesClient(ctrl) |
| req := gitilespb.LogRequest{ |
| Project: test.project, |
| Committish: "refs/heads/master", |
| PageSize: 1, |
| } |
| // Client returns a successful ChangeInfo response. |
| resp := gitilespb.LogResponse{ |
| Log: []*git.Commit{{Id: "foobar"}}, |
| } |
| mockGitilesClient.EXPECT().Log(gomock.Any(), &req).Return(&resp, nil) |
| mockGitilesClientWrapper := gitilesClientWrapper{ |
| client: mockGitilesClient, |
| project: test.project, |
| } |
| ctx := context.Background() |
| commit, err := mockGitilesClientWrapper.getLatestCommit(ctx) |
| if err != nil { |
| t.Errorf("got unexpected err %v", err) |
| } |
| if test.expected != commit { |
| t.Errorf("expected: %s\nactual: %s\n", test.expected, commit) |
| } |
| } |
| } |