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

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

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

Powered by Google App Engine
This is Rietveld 408576698