OLD | NEW |
1 // Copyright 2016 The LUCI Authors. | 1 // Copyright 2016 The LUCI Authors. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with 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 | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 12 matching lines...) Expand all Loading... |
23 "path/filepath" | 23 "path/filepath" |
24 "regexp" | 24 "regexp" |
25 "strings" | 25 "strings" |
26 "testing" | 26 "testing" |
27 "time" | 27 "time" |
28 | 28 |
29 "golang.org/x/net/context" | 29 "golang.org/x/net/context" |
30 | 30 |
31 "github.com/luci/gae/impl/memory" | 31 "github.com/luci/gae/impl/memory" |
32 "github.com/luci/luci-go/common/clock/testclock" | 32 "github.com/luci/luci-go/common/clock/testclock" |
| 33 "github.com/luci/luci-go/milo/api/resp" |
| 34 "github.com/luci/luci-go/milo/buildsource/buildbot" |
33 "github.com/luci/luci-go/milo/buildsource/swarming" | 35 "github.com/luci/luci-go/milo/buildsource/swarming" |
34 "github.com/luci/luci-go/milo/common" | 36 "github.com/luci/luci-go/milo/common" |
35 "github.com/luci/luci-go/server/auth" | 37 "github.com/luci/luci-go/server/auth" |
36 "github.com/luci/luci-go/server/auth/authtest" | 38 "github.com/luci/luci-go/server/auth/authtest" |
37 "github.com/luci/luci-go/server/auth/identity" | 39 "github.com/luci/luci-go/server/auth/identity" |
38 "github.com/luci/luci-go/server/settings" | 40 "github.com/luci/luci-go/server/settings" |
39 "github.com/luci/luci-go/server/templates" | 41 "github.com/luci/luci-go/server/templates" |
40 | 42 |
41 . "github.com/smartystreets/goconvey/convey" | 43 . "github.com/smartystreets/goconvey/convey" |
42 ) | 44 ) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 93 |
92 func TestPages(t *testing.T) { | 94 func TestPages(t *testing.T) { |
93 fixZeroDurationRE := regexp.MustCompile(`(Running for:|waiting) 0s?`) | 95 fixZeroDurationRE := regexp.MustCompile(`(Running for:|waiting) 0s?`) |
94 fixZeroDuration := func(text string) string { | 96 fixZeroDuration := func(text string) string { |
95 return fixZeroDurationRE.ReplaceAllLiteralString(text, "[ZERO DU
RATION]") | 97 return fixZeroDurationRE.ReplaceAllLiteralString(text, "[ZERO DU
RATION]") |
96 } | 98 } |
97 | 99 |
98 Convey("Testing basic rendering.", t, func() { | 100 Convey("Testing basic rendering.", t, func() { |
99 c := context.Background() | 101 c := context.Background() |
100 c = memory.Use(c) | 102 c = memory.Use(c) |
101 » » c = common.WithRequest(c, &http.Request{URL: &url.URL{Path: "/fo
obar"}}) | 103 » » c = withRequest(c, &http.Request{URL: &url.URL{Path: "/foobar"}}
) |
102 c, _ = testclock.UseTime(c, testclock.TestTimeUTC) | 104 c, _ = testclock.UseTime(c, testclock.TestTimeUTC) |
103 c = auth.WithState(c, &authtest.FakeState{Identity: identity.Ano
nymousIdentity}) | 105 c = auth.WithState(c, &authtest.FakeState{Identity: identity.Ano
nymousIdentity}) |
104 c = settings.Use(c, settings.New(&settings.MemoryStorage{Expirat
ion: time.Second})) | 106 c = settings.Use(c, settings.New(&settings.MemoryStorage{Expirat
ion: time.Second})) |
105 err := settings.Set(c, "analytics", &analyticsSettings{"UA-12345
-01"}, "", "") | 107 err := settings.Set(c, "analytics", &analyticsSettings{"UA-12345
-01"}, "", "") |
106 So(err, ShouldBeNil) | 108 So(err, ShouldBeNil) |
107 » » c = templates.Use(c, common.GetTemplateBundle("appengine/templat
es")) | 109 » » c = templates.Use(c, getTemplateBundle("appengine/templates")) |
108 for _, p := range allPackages { | 110 for _, p := range allPackages { |
109 Convey(fmt.Sprintf("Testing handler %q", p.DisplayName),
func() { | 111 Convey(fmt.Sprintf("Testing handler %q", p.DisplayName),
func() { |
110 for _, b := range p.Data() { | 112 for _, b := range p.Data() { |
111 Convey(fmt.Sprintf("Testing: %q", b.Desc
ription), func() { | 113 Convey(fmt.Sprintf("Testing: %q", b.Desc
ription), func() { |
112 args := b.Data | 114 args := b.Data |
113 // This is not a path, but a fil
e key, should always be "/". | 115 // This is not a path, but a fil
e key, should always be "/". |
114 tmplName := "pages/" + p.Templat
eName | 116 tmplName := "pages/" + p.Templat
eName |
115 buf, err := templates.Render(c,
tmplName, args) | 117 buf, err := templates.Render(c,
tmplName, args) |
116 So(err, ShouldBeNil) | 118 So(err, ShouldBeNil) |
117 fname := fmt.Sprintf( | 119 fname := fmt.Sprintf( |
118 "%s-%s.html", p.DisplayN
ame, b.Description) | 120 "%s-%s.html", p.DisplayN
ame, b.Description) |
119 if *generate { | 121 if *generate { |
120 mustWrite(fname, buf) | 122 mustWrite(fname, buf) |
121 } else { | 123 } else { |
122 localBuf, err := load(fn
ame) | 124 localBuf, err := load(fn
ame) |
123 So(err, ShouldBeNil) | 125 So(err, ShouldBeNil) |
124 So(fixZeroDuration(strin
g(buf)), ShouldEqual, fixZeroDuration(string(localBuf))) | 126 So(fixZeroDuration(strin
g(buf)), ShouldEqual, fixZeroDuration(string(localBuf))) |
125 } | 127 } |
126 }) | 128 }) |
127 } | 129 } |
128 }) | 130 }) |
129 } | 131 } |
130 }) | 132 }) |
131 } | 133 } |
| 134 |
| 135 // buildbotBuildTestData returns sample test data for build pages. |
| 136 func buildbotBuildTestData() []common.TestBundle { |
| 137 c := memory.Use(context.Background()) |
| 138 c, _ = testclock.UseTime(c, testclock.TestTimeUTC) |
| 139 bundles := []common.TestBundle{} |
| 140 for _, tc := range buildbot.TestCases { |
| 141 build, err := buildbot.DebugBuild(c, "../buildSource/buildbot",
tc.Builder, tc.Build) |
| 142 if err != nil { |
| 143 panic(fmt.Errorf( |
| 144 "Encountered error while building debug/%s/%s.\n
%s", |
| 145 tc.Builder, tc.Build, err)) |
| 146 } |
| 147 bundles = append(bundles, common.TestBundle{ |
| 148 Description: fmt.Sprintf("Debug page: %s/%d", tc.Builder
, tc.Build), |
| 149 Data: templates.Args{ |
| 150 "Build": build, |
| 151 }, |
| 152 }) |
| 153 } |
| 154 return bundles |
| 155 } |
| 156 |
| 157 // buildbotBuilderTestData returns sample test data for builder pages. |
| 158 func buildbotBuilderTestData() []common.TestBundle { |
| 159 l := resp.NewLink("Some current build", "https://some.url/path") |
| 160 return []common.TestBundle{ |
| 161 { |
| 162 Description: "Basic Test no builds", |
| 163 Data: templates.Args{ |
| 164 "Builder": &resp.Builder{ |
| 165 Name: "Sample Builder", |
| 166 }, |
| 167 }, |
| 168 }, |
| 169 { |
| 170 Description: "Basic Test with builds", |
| 171 Data: templates.Args{ |
| 172 "Builder": &resp.Builder{ |
| 173 Name: "Sample Builder", |
| 174 MachinePool: &resp.MachinePool{ |
| 175 Total: 15, |
| 176 Disconnected: 13, |
| 177 Idle: 5, |
| 178 Busy: 8, |
| 179 }, |
| 180 CurrentBuilds: []*resp.BuildSummary{ |
| 181 {Link: l, Revision: "deadbeef"}, |
| 182 }, |
| 183 PendingBuilds: []*resp.BuildSummary{ |
| 184 {Link: l, Revision: "deadbeef"}, |
| 185 }, |
| 186 FinishedBuilds: []*resp.BuildSummary{ |
| 187 {Link: l, Revision: "deadbeef"}, |
| 188 }, |
| 189 }, |
| 190 }, |
| 191 }, |
| 192 } |
| 193 } |
OLD | NEW |