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

Side by Side Diff: milo/appengine/frontend/main_test.go

Issue 2748073006: Milo Refactor: Remove theme support (Closed)
Patch Set: Fix builder.html pointer Created 3 years, 9 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 unified diff | Download patch
OLDNEW
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 "net/url"
13 "path/filepath" 13 "path/filepath"
14 "reflect"
15 "regexp" 14 "regexp"
16 "strings" 15 "strings"
17 "testing" 16 "testing"
18 "time" 17 "time"
19 18
19 "golang.org/x/net/context"
20
20 "github.com/luci/gae/impl/memory" 21 "github.com/luci/gae/impl/memory"
21 "github.com/luci/luci-go/common/clock/testclock" 22 "github.com/luci/luci-go/common/clock/testclock"
22 "github.com/luci/luci-go/milo/appengine/buildbot" 23 "github.com/luci/luci-go/milo/appengine/buildbot"
23 » "github.com/luci/luci-go/milo/appengine/settings" 24 » "github.com/luci/luci-go/milo/appengine/common"
24 "github.com/luci/luci-go/milo/appengine/swarming" 25 "github.com/luci/luci-go/milo/appengine/swarming"
25 "github.com/luci/luci-go/server/auth" 26 "github.com/luci/luci-go/server/auth"
26 "github.com/luci/luci-go/server/auth/identity" 27 "github.com/luci/luci-go/server/auth/identity"
27 » luciSettings "github.com/luci/luci-go/server/settings" 28 » "github.com/luci/luci-go/server/settings"
29 » "github.com/luci/luci-go/server/templates"
30
28 . "github.com/smartystreets/goconvey/convey" 31 . "github.com/smartystreets/goconvey/convey"
29 "golang.org/x/net/context"
30 ) 32 )
31 33
34 type testPackage struct {
35 Data func() []common.TestBundle
36 DisplayName string
37 TemplateName string
38 }
39
32 var ( 40 var (
33 » allHandlers = []settings.TestableHandler{ 41 » allPackages = []testPackage{
34 » » settings.TestableSettings{}, 42 » » {buildbot.BuildTestData, "buildbot.build", "build.html"},
35 » » buildbot.TestableBuild{}, 43 » » {buildbot.BuilderTestData, "buildbot.builder", "builder.html"},
36 » » buildbot.TestableBuilder{}, 44 » » {swarming.BuildTestData, "swarming.build", "build.html"},
37 » » swarming.TestableBuild{}, 45 » » {swarming.LogTestData, "swarming.log", "log.html"},
38 » » swarming.TestableLog{}, 46 » » {frontpageTestData, "frontpage", "frontpage.html"},
39 » » testableFrontpage{},
40 } 47 }
41 ) 48 )
42 49
43 var generate = flag.Bool( 50 var generate = flag.Bool(
44 "test.generate", false, "Generate expectations instead of running tests. ") 51 "test.generate", false, "Generate expectations instead of running tests. ")
45 52
46 func expectFileName(name string) string { 53 func expectFileName(name string) string {
47 name = strings.Replace(name, " ", "_", -1) 54 name = strings.Replace(name, " ", "_", -1)
48 name = strings.Replace(name, "/", "_", -1) 55 name = strings.Replace(name, "/", "_", -1)
49 name = strings.Replace(name, ":", "-", -1) 56 name = strings.Replace(name, ":", "-", -1)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 func TestPages(t *testing.T) { 101 func TestPages(t *testing.T) {
95 fixZeroDurationRE := regexp.MustCompile(`(Running for:|waiting) 0s?`) 102 fixZeroDurationRE := regexp.MustCompile(`(Running for:|waiting) 0s?`)
96 fixZeroDuration := func(text string) string { 103 fixZeroDuration := func(text string) string {
97 return fixZeroDurationRE.ReplaceAllLiteralString(text, "[ZERO DU RATION]") 104 return fixZeroDurationRE.ReplaceAllLiteralString(text, "[ZERO DU RATION]")
98 } 105 }
99 106
100 Convey("Testing basic rendering.", t, func() { 107 Convey("Testing basic rendering.", t, func() {
101 // Load all the bundles. 108 // Load all the bundles.
102 c := context.Background() 109 c := context.Background()
103 c = memory.Use(c) 110 c = memory.Use(c)
104 » » c = settings.WithRequest(c, &http.Request{URL: &url.URL{Path: "/ foobar"}}) 111 » » c = common.WithRequest(c, &http.Request{URL: &url.URL{Path: "/fo obar"}})
105 c, _ = testclock.UseTime(c, testclock.TestTimeUTC) 112 c, _ = testclock.UseTime(c, testclock.TestTimeUTC)
106 a := auth.Authenticator{fakeOAuthMethod{"some_client_id"}} 113 a := auth.Authenticator{fakeOAuthMethod{"some_client_id"}}
107 c = auth.SetAuthenticator(c, a) 114 c = auth.SetAuthenticator(c, a)
108 » » c = luciSettings.Use(c, luciSettings.New(&luciSettings.MemorySto rage{Expiration: time.Second})) 115 » » c = settings.Use(c, settings.New(&settings.MemoryStorage{Expirat ion: time.Second}))
109 » » err := luciSettings.Set(c, "analytics", &analyticsSettings{"UA-1 2345-01"}, "", "") 116 » » err := settings.Set(c, "analytics", &analyticsSettings{"UA-12345 -01"}, "", "")
110 So(err, ShouldBeNil) 117 So(err, ShouldBeNil)
111 » » for _, nb := range settings.GetTemplateBundles() { 118 » » c = templates.Use(c, common.GetTemplateBundle())
112 » » » Convey(fmt.Sprintf("Testing theme %q", nb.Name), func() { 119 » » for _, p := range allPackages {
113 » » » » err := nb.Bundle.EnsureLoaded(c) 120 » » » Convey(fmt.Sprintf("Testing handler %q", p.DisplayName), func() {
114 » » » » So(err, ShouldBeNil) 121 » » » » for _, b := range p.Data() {
115 » » » » for _, h := range allHandlers { 122 » » » » » Convey(fmt.Sprintf("Testing: %q", b.Desc ription), func() {
116 » » » » » hName := reflect.TypeOf(h).String() 123 » » » » » » args := b.Data
117 » » » » » Convey(fmt.Sprintf("Testing handler %q", hName), func() { 124 » » » » » » // This is not a path, but a fil e key, should always be "/".
118 » » » » » » for _, b := range h.TestData() { 125 » » » » » » tmplName := "pages/" + p.Templat eName
119 » » » » » » » Convey(fmt.Sprintf("Test ing: %q", b.Description), func() { 126 » » » » » » buf, err := templates.Render(c, tmplName, args)
120 » » » » » » » » args := b.Data 127 » » » » » » So(err, ShouldBeNil)
121 » » » » » » » » // This is not a path, but a file key, should always be "/". 128 » » » » » » fname := fmt.Sprintf(
122 » » » » » » » » tmplName := fmt. Sprintf( 129 » » » » » » » "%s-%s.html", p.DisplayN ame, b.Description)
123 » » » » » » » » » "pages/% s", h.GetTemplateName(*nb.Theme)) 130 » » » » » » if *generate {
124 » » » » » » » » buf, err := nb.B undle.Render(c, tmplName, args) 131 » » » » » » » mustWrite(fname, buf)
125 » » » » » » » » So(err, ShouldBe Nil) 132 » » » » » » } else {
126 » » » » » » » » fname := fmt.Spr intf( 133 » » » » » » » localBuf, err := load(fn ame)
127 » » » » » » » » » "%s-%s-% s.html", nb.Name, hName, b.Description) 134 » » » » » » » So(err, ShouldBeNil)
128 » » » » » » » » if *generate { 135 » » » » » » » So(fixZeroDuration(strin g(buf)), ShouldEqual, fixZeroDuration(string(localBuf)))
129 » » » » » » » » » mustWrit e(fname, buf)
130 » » » » » » » » } else {
131 » » » » » » » » » localBuf , err := load(fname)
132 » » » » » » » » » So(err, ShouldBeNil)
133 » » » » » » » » » So(fixZe roDuration(string(buf)), ShouldEqual, fixZeroDuration(string(localBuf)))
134 » » » » » » » » }
135 » » » » » » » })
136 } 136 }
137 }) 137 })
138 } 138 }
139 }) 139 })
140 } 140 }
141 }) 141 })
142 } 142 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698