| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package frontend | 5 package frontend |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "flag" | 8 "flag" |
| 9 "fmt" | 9 "fmt" |
| 10 "io/ioutil" | 10 "io/ioutil" |
| 11 "net/http" | 11 "net/http" |
| 12 "net/url" |
| 12 "path/filepath" | 13 "path/filepath" |
| 13 "reflect" | 14 "reflect" |
| 14 "regexp" | 15 "regexp" |
| 15 "strings" | 16 "strings" |
| 16 "testing" | 17 "testing" |
| 17 "time" | 18 "time" |
| 18 | 19 |
| 19 "github.com/luci/gae/impl/memory" | 20 "github.com/luci/gae/impl/memory" |
| 20 "github.com/luci/luci-go/common/clock/testclock" | 21 "github.com/luci/luci-go/common/clock/testclock" |
| 21 "github.com/luci/luci-go/milo/appengine/buildbot" | 22 "github.com/luci/luci-go/milo/appengine/buildbot" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 } | 72 } |
| 72 | 73 |
| 73 func (m fakeOAuthMethod) Authenticate(context.Context, *http.Request) (*auth.Use
r, error) { | 74 func (m fakeOAuthMethod) Authenticate(context.Context, *http.Request) (*auth.Use
r, error) { |
| 74 return &auth.User{ | 75 return &auth.User{ |
| 75 Identity: identity.Identity("user:abc@example.com"), | 76 Identity: identity.Identity("user:abc@example.com"), |
| 76 Email: "abc@example.com", | 77 Email: "abc@example.com", |
| 77 ClientID: m.clientID, | 78 ClientID: m.clientID, |
| 78 }, nil | 79 }, nil |
| 79 } | 80 } |
| 80 | 81 |
| 81 func (m fakeOAuthMethod) LoginURL(context.Context, string) (string, error) { | 82 func (m fakeOAuthMethod) LoginURL(c context.Context, target string) (string, err
or) { |
| 82 » return "https://login.url/", nil | 83 » return "https://login.url/?target=" + target, nil |
| 83 } | 84 } |
| 84 | 85 |
| 85 func (m fakeOAuthMethod) LogoutURL(context.Context, string) (string, error) { | 86 func (m fakeOAuthMethod) LogoutURL(c context.Context, target string) (string, er
ror) { |
| 86 » return "https://logout.url/", nil | 87 » return "https://logout.url/?target=" + target, nil |
| 87 } | 88 } |
| 88 | 89 |
| 89 type analyticsSettings struct { | 90 type analyticsSettings struct { |
| 90 AnalyticsID string `json:"analytics_id"` | 91 AnalyticsID string `json:"analytics_id"` |
| 91 } | 92 } |
| 92 | 93 |
| 93 func TestPages(t *testing.T) { | 94 func TestPages(t *testing.T) { |
| 94 fixZeroDurationRE := regexp.MustCompile(`(Running for:|waiting) 0s?`) | 95 fixZeroDurationRE := regexp.MustCompile(`(Running for:|waiting) 0s?`) |
| 95 fixZeroDuration := func(text string) string { | 96 fixZeroDuration := func(text string) string { |
| 96 return fixZeroDurationRE.ReplaceAllLiteralString(text, "[ZERO DU
RATION]") | 97 return fixZeroDurationRE.ReplaceAllLiteralString(text, "[ZERO DU
RATION]") |
| 97 } | 98 } |
| 98 | 99 |
| 99 Convey("Testing basic rendering.", t, func() { | 100 Convey("Testing basic rendering.", t, func() { |
| 100 // Load all the bundles. | 101 // Load all the bundles. |
| 101 c := context.Background() | 102 c := context.Background() |
| 102 c = memory.Use(c) | 103 c = memory.Use(c) |
| 104 c = settings.WithRequest(c, &http.Request{URL: &url.URL{Path: "/
foobar"}}) |
| 103 c, _ = testclock.UseTime(c, testclock.TestTimeUTC) | 105 c, _ = testclock.UseTime(c, testclock.TestTimeUTC) |
| 104 a := auth.Authenticator{fakeOAuthMethod{"some_client_id"}} | 106 a := auth.Authenticator{fakeOAuthMethod{"some_client_id"}} |
| 105 c = auth.SetAuthenticator(c, a) | 107 c = auth.SetAuthenticator(c, a) |
| 106 c = luciSettings.Use(c, luciSettings.New(&luciSettings.MemorySto
rage{Expiration: time.Second})) | 108 c = luciSettings.Use(c, luciSettings.New(&luciSettings.MemorySto
rage{Expiration: time.Second})) |
| 107 err := luciSettings.Set(c, "analytics", &analyticsSettings{"UA-1
2345-01"}, "", "") | 109 err := luciSettings.Set(c, "analytics", &analyticsSettings{"UA-1
2345-01"}, "", "") |
| 108 So(err, ShouldBeNil) | 110 So(err, ShouldBeNil) |
| 109 for _, nb := range settings.GetTemplateBundles() { | 111 for _, nb := range settings.GetTemplateBundles() { |
| 110 Convey(fmt.Sprintf("Testing theme %q", nb.Name), func()
{ | 112 Convey(fmt.Sprintf("Testing theme %q", nb.Name), func()
{ |
| 111 err := nb.Bundle.EnsureLoaded(c) | 113 err := nb.Bundle.EnsureLoaded(c) |
| 112 So(err, ShouldBeNil) | 114 So(err, ShouldBeNil) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 131 So(fixZe
roDuration(string(buf)), ShouldEqual, fixZeroDuration(string(localBuf))) | 133 So(fixZe
roDuration(string(buf)), ShouldEqual, fixZeroDuration(string(localBuf))) |
| 132 } | 134 } |
| 133 }) | 135 }) |
| 134 } | 136 } |
| 135 }) | 137 }) |
| 136 } | 138 } |
| 137 }) | 139 }) |
| 138 } | 140 } |
| 139 }) | 141 }) |
| 140 } | 142 } |
| OLD | NEW |