Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Unified Diff: logdog/client/butlerlib/bootstrap/bootstrap_test.go

Issue 2456953003: LogDog: Update client/bootstrap to generate URLs. (Closed)
Patch Set: Winders Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « logdog/client/butlerlib/bootstrap/bootstrap.go ('k') | logdog/client/butlerlib/streamclient/client.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: logdog/client/butlerlib/bootstrap/bootstrap_test.go
diff --git a/logdog/client/butlerlib/bootstrap/bootstrap_test.go b/logdog/client/butlerlib/bootstrap/bootstrap_test.go
index 4c823dd0377c05a67b1326d39fa242caf609a19a..153b7045e4e8c45f72ace2c29eca50836eb8ac45 100644
--- a/logdog/client/butlerlib/bootstrap/bootstrap_test.go
+++ b/logdog/client/butlerlib/bootstrap/bootstrap_test.go
@@ -5,12 +5,14 @@
package bootstrap
import (
- "errors"
+ "fmt"
"testing"
"github.com/luci/luci-go/client/environ"
+ "github.com/luci/luci-go/common/errors"
"github.com/luci/luci-go/logdog/client/butlerlib/streamclient"
"github.com/luci/luci-go/logdog/client/butlerlib/streamproto"
+ "github.com/luci/luci-go/logdog/common/types"
. "github.com/luci/luci-go/common/testing/assertions"
. "github.com/smartystreets/goconvey/convey"
@@ -18,9 +20,21 @@ import (
type sentinelClient struct{}
-func (*sentinelClient) NewStream(f streamproto.Flags) (streamclient.Stream, error) { return nil, nil }
+func (sc *sentinelClient) NewStream(f streamproto.Flags) (streamclient.Stream, error) {
+ return &sentinelStream{props: f.Properties()}, nil
+}
+
+type sentinelStream struct {
+ streamclient.Stream
+ props *streamproto.Properties
+}
+
+func (ss *sentinelStream) Properties() *streamproto.Properties { return ss.props }
+func (ss *sentinelStream) Close() error { return nil }
func TestBootstrap(t *testing.T) {
+ t.Parallel()
+
Convey(`A test Environment`, t, func() {
reg := &streamclient.Registry{}
regSpec := ""
@@ -61,11 +75,15 @@ func TestBootstrap(t *testing.T) {
bs, err := getFromEnv(env, reg)
So(err, ShouldBeNil)
+ // Check that the client is populated, so we can test the remaining
+ // fields without reconstructing it.
+ So(bs.Client, ShouldHaveSameTypeAs, &sentinelClient{})
+ bs.Client = nil
+
So(bs, ShouldResemble, &Bootstrap{
CoordinatorHost: "example.appspot.com",
Project: "test-project",
Prefix: "butler/prefix",
- Client: &sentinelClient{},
})
So(regSpec, ShouldEqual, "client:params")
})
@@ -97,3 +115,84 @@ func TestBootstrap(t *testing.T) {
})
})
}
+
+func TestBootstrapURLGeneration(t *testing.T) {
+ t.Parallel()
+
+ Convey(`A bootstrap instance`, t, func() {
+ bs := &Bootstrap{
+ Project: "test",
+ Prefix: "foo",
+ CoordinatorHost: "example.appspot.com",
+ }
+
+ Convey(`Can generate viewer URLs`, func() {
+ for _, tc := range []struct {
+ paths []types.StreamPath
+ url string
+ }{
+ {[]types.StreamPath{"foo/bar/+/baz"}, "https://example.appspot.com/v/?s=test%2Ffoo%2Fbar%2F%2B%2Fbaz"},
+ {[]types.StreamPath{"foo/bar/+/**"}, "https://example.appspot.com/v/?s=test%2Ffoo%2Fbar%2F%2B%2F%2A%2A"},
+ {[]types.StreamPath{
+ "foo/bar/+/baz",
+ "foo/bar/+/qux",
+ }, "https://example.appspot.com/v/?s=test%2Ffoo%2Fbar%2F%2B%2Fbaz&s=test%2Ffoo%2Fbar%2F%2B%2Fqux"},
+ } {
+ Convey(fmt.Sprintf(`Will generate [%s] from %q`, tc.url, tc.paths), func() {
+ url, err := bs.GetViewerURL(tc.paths...)
+ So(err, ShouldBeNil)
+ So(url, ShouldEqual, tc.url)
+ })
+ }
+ })
+
+ Convey(`With no project, will not generate URLs.`, func() {
+ bs.Project = ""
+
+ _, err := bs.GetViewerURL("bar")
+ So(err, ShouldErrLike, "no project is configured")
+ })
+
+ Convey(`With no coordinator host, will not generate URLs.`, func() {
+ bs.CoordinatorHost = ""
+
+ _, err := bs.GetViewerURL("bar")
+ So(err, ShouldErrLike, "no coordinator host is configured")
+ })
+
+ Convey(`With a stream client configured`, func() {
+ reg := streamclient.Registry{}
+ reg.Register("test", func(spec string) (streamclient.Client, error) {
+ return &sentinelClient{}, nil
+ })
+
+ So(bs.initializeClient("test:", &reg), ShouldBeNil)
+ So(bs.Client, ShouldHaveSameTypeAs, &sentinelClient{})
+
+ Convey(`Can generate viewer URLs for streams.`, func() {
+ barS, err := bs.Client.NewStream(streamproto.Flags{Name: "bar"})
+ So(err, ShouldBeNil)
+ defer barS.Close()
+
+ bazS, err := bs.Client.NewStream(streamproto.Flags{Name: "baz"})
+ So(err, ShouldBeNil)
+ defer bazS.Close()
+
+ url, err := bs.GetViewerURLForStreams(barS, bazS)
+ So(err, ShouldBeNil)
+ So(url, ShouldEqual, "https://example.appspot.com/v/?s=test%2Ffoo%2F%2B%2Fbar&s=test%2Ffoo%2F%2B%2Fbaz")
+ })
+
+ Convey(`Will not generate viewer URLs if a prefix is not defined.`, func() {
+ bs.Prefix = ""
+
+ barS, err := bs.Client.NewStream(streamproto.Flags{Name: "bar"})
+ So(err, ShouldBeNil)
+ defer barS.Close()
+
+ _, err = bs.GetViewerURLForStreams(barS)
+ So(err, ShouldErrLike, "no prefix is configured")
+ })
+ })
+ })
+}
« no previous file with comments | « logdog/client/butlerlib/bootstrap/bootstrap.go ('k') | logdog/client/butlerlib/streamclient/client.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698