go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/analysis/internal/testresults/host_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 testresults
    16  
    17  import (
    18  	"testing"
    19  
    20  	. "github.com/smartystreets/goconvey/convey"
    21  )
    22  
    23  func TestHost(t *testing.T) {
    24  	Convey("Gerrit hostnames", t, func() {
    25  		Convey("Roundtrip", func() {
    26  			values := []string{
    27  				"myproject-review.googlesource.com",
    28  				"other123-review.googlesource.com",
    29  				"something-other-123.gerrit.instance",
    30  			}
    31  			for _, input := range values {
    32  				So(DecompressHost(CompressHost(input)), ShouldEqual, input)
    33  			}
    34  		})
    35  		Convey("Compress", func() {
    36  			testCases := map[string]string{
    37  				// Should get some compression.
    38  				"myproject-review.googlesource.com": "myproject",
    39  				"some.other.instance":               "some.other.instance",
    40  			}
    41  			for input, expectedOutput := range testCases {
    42  				So(CompressHost(input), ShouldEqual, expectedOutput)
    43  			}
    44  		})
    45  		Convey("Decompress", func() {
    46  			testCases := map[string]string{
    47  				"myproject":           "myproject-review.googlesource.com",
    48  				"some.other.instance": "some.other.instance",
    49  			}
    50  			for input, expectedOutput := range testCases {
    51  				So(DecompressHost(input), ShouldEqual, expectedOutput)
    52  			}
    53  		})
    54  	})
    55  }