go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/bisection/util/linkconstructor_test.go (about)

     1  // Copyright 2022 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package util
    16  
    17  import (
    18  	"context"
    19  	"testing"
    20  
    21  	"github.com/golang/mock/gomock"
    22  	. "github.com/smartystreets/goconvey/convey"
    23  
    24  	"go.chromium.org/luci/bisection/internal/gerrit"
    25  
    26  	gerritpb "go.chromium.org/luci/common/proto/gerrit"
    27  )
    28  
    29  func TestConstructAnalysisURL(t *testing.T) {
    30  	Convey("construct compile analysis URL", t, func() {
    31  		So(ConstructCompileAnalysisURL("testproject", 123456789876543), ShouldEqual,
    32  			"https://ci.chromium.org/ui/p/testproject/bisection/compile-analysis/b/123456789876543")
    33  	})
    34  
    35  	Convey("construct test analysis URL", t, func() {
    36  		So(ConstructTestAnalysisURL("testproject", 123456789876543), ShouldEqual,
    37  			"https://ci.chromium.org/ui/p/testproject/bisection/test-analysis/b/123456789876543")
    38  	})
    39  }
    40  
    41  func TestConstructBuildURL(t *testing.T) {
    42  	ctx := context.Background()
    43  
    44  	Convey("construct build URL", t, func() {
    45  		So(ConstructBuildURL(ctx, 123456789876543), ShouldEqual,
    46  			"https://ci.chromium.org/b/123456789876543")
    47  	})
    48  }
    49  
    50  func TestConstructGerritCodeReviewURL(t *testing.T) {
    51  	ctx := context.Background()
    52  
    53  	Convey("construct Gerrit code review URL", t, func() {
    54  		// Set up mock Gerrit client
    55  		ctl := gomock.NewController(t)
    56  		defer ctl.Finish()
    57  		mockClient := gerrit.NewMockedClient(ctx, ctl)
    58  		ctx = mockClient.Ctx
    59  
    60  		// Set up Gerrit client
    61  		gerritClient, err := gerrit.NewClient(ctx, "chromium-test.googlesource.com")
    62  		So(err, ShouldBeNil)
    63  
    64  		change := &gerritpb.ChangeInfo{
    65  			Project: "chromium/test",
    66  			Number:  123456,
    67  		}
    68  
    69  		So(ConstructGerritCodeReviewURL(ctx, gerritClient, change), ShouldEqual,
    70  			"https://chromium-test.googlesource.com/c/chromium/test/+/123456")
    71  	})
    72  }
    73  
    74  func TestConstructBuganizerURLForTestAnalysis(t *testing.T) {
    75  
    76  	commitReviewURL := "https://chromium-test-review.googlesource.com/c/chromium/test/src/+/1234567"
    77  
    78  	Convey("construct buganizer URL", t, func() {
    79  		analysisURL := "https://ci.chromium.org/ui/p/chromium/bisection/compile-analysis/b/8766961581788295857"
    80  		bugURL := ConstructBuganizerURLForAnalysis(commitReviewURL, analysisURL)
    81  		expectedBugURL := "http://b.corp.google.com/createIssue?component=1199205" +
    82  			"&description=Analysis%3A+https%3A%2F%2Fci.chromium.org%2Fui%2Fp%2Fchromium%2Fbi" +
    83  			"section%2Fcompile-analysis%2Fb%2F8766961581788295857&format=PLAIN&priority=P3&title=Wrongly+" +
    84  			"blamed+https%3A%2F%2Fchromium-test-review.googlesource.com%2Fc%2Fchromium%2F" +
    85  			"test%2Fsrc%2F%2B%2F1234567&type=BUG"
    86  		So(bugURL, ShouldEqual, expectedBugURL)
    87  	})
    88  }
    89  
    90  func TestConstructTestHistoryURL(t *testing.T) {
    91  	Convey("construct test history URL", t, func() {
    92  		testURL := ConstructTestHistoryURL("chromium", "testID", "6363b77a587c3046")
    93  		expectedTestURL := "https://ci.chromium.org/ui/test/chromium/testID?q=VHash%3A6363b77a587c3046"
    94  		So(testURL, ShouldEqual, expectedTestURL)
    95  	})
    96  }