go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/logdog/common/viewer/url_test.go (about)

     1  // Copyright 2015 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 viewer
    16  
    17  import (
    18  	"fmt"
    19  	"testing"
    20  
    21  	"go.chromium.org/luci/logdog/common/types"
    22  
    23  	. "github.com/smartystreets/goconvey/convey"
    24  )
    25  
    26  func TestGetURL(t *testing.T) {
    27  	t.Parallel()
    28  
    29  	Convey(`Testing viewer URL generation`, t, func() {
    30  		for _, tc := range []struct {
    31  			host    string
    32  			project string
    33  			paths   []types.StreamPath
    34  			url     string
    35  		}{
    36  			{"example.appspot.com", "test", []types.StreamPath{"foo/bar/+/baz"},
    37  				"https://example.appspot.com/logs/test/foo/bar/+/baz"},
    38  			{"example.appspot.com", "test", []types.StreamPath{"foo/bar/+/baz", "qux/+/quux"},
    39  				"https://example.appspot.com/v/?s=test%2Ffoo%2Fbar%2F%2B%2Fbaz&s=test%2Fqux%2F%2B%2Fquux"},
    40  		} {
    41  			Convey(fmt.Sprintf(`Can generate a URL for host %q, project %q, paths %q: [%s]`, tc.host, tc.project, tc.paths, tc.url), func() {
    42  				So(GetURL(tc.host, tc.project, tc.paths...), ShouldEqual, tc.url)
    43  			})
    44  		}
    45  	})
    46  }