Index: milo/appengine/frontend/main_test.go |
diff --git a/milo/appengine/frontend/main_test.go b/milo/appengine/frontend/main_test.go |
deleted file mode 100644 |
index 8e635161c18c488186620870d01dacdc9eb144c7..0000000000000000000000000000000000000000 |
--- a/milo/appengine/frontend/main_test.go |
+++ /dev/null |
@@ -1,121 +0,0 @@ |
-// Copyright 2016 The LUCI Authors. All rights reserved. |
-// Use of this source code is governed under the Apache License, Version 2.0 |
-// that can be found in the LICENSE file. |
- |
-package frontend |
- |
-import ( |
- "flag" |
- "fmt" |
- "io/ioutil" |
- "net/http" |
- "net/url" |
- "path/filepath" |
- "regexp" |
- "strings" |
- "testing" |
- "time" |
- |
- "golang.org/x/net/context" |
- |
- "github.com/luci/gae/impl/memory" |
- "github.com/luci/luci-go/common/clock/testclock" |
- "github.com/luci/luci-go/milo/appengine/common" |
- "github.com/luci/luci-go/milo/appengine/job_source/swarming" |
- "github.com/luci/luci-go/server/auth" |
- "github.com/luci/luci-go/server/auth/authtest" |
- "github.com/luci/luci-go/server/auth/identity" |
- "github.com/luci/luci-go/server/settings" |
- "github.com/luci/luci-go/server/templates" |
- |
- . "github.com/smartystreets/goconvey/convey" |
-) |
- |
-type testPackage struct { |
- Data func() []common.TestBundle |
- DisplayName string |
- TemplateName string |
-} |
- |
-var ( |
- allPackages = []testPackage{ |
- {buildbotBuildTestData, "buildbot.build", "build.html"}, |
- {buildbotBuilderTestData, "buildbot.builder", "builder.html"}, |
- {func() []common.TestBundle { |
- return swarming.BuildTestData("../job_source/swarming") |
- }, "swarming.build", "build.html"}, |
- {swarming.LogTestData, "swarming.log", "log.html"}, |
- {frontpageTestData, "frontpage", "frontpage.html"}, |
- } |
-) |
- |
-var generate = flag.Bool( |
- "test.generate", false, "Generate expectations instead of running tests.") |
- |
-func expectFileName(name string) string { |
- name = strings.Replace(name, " ", "_", -1) |
- name = strings.Replace(name, "/", "_", -1) |
- name = strings.Replace(name, ":", "-", -1) |
- return filepath.Join("expectations", name) |
-} |
- |
-func load(name string) ([]byte, error) { |
- filename := expectFileName(name) |
- return ioutil.ReadFile(filename) |
-} |
- |
-// mustWrite Writes a buffer into an expectation file. Should always work or |
-// panic. This is fine because this only runs when -generate is passed in, |
-// not during tests. |
-func mustWrite(name string, buf []byte) { |
- filename := expectFileName(name) |
- err := ioutil.WriteFile(filename, buf, 0644) |
- if err != nil { |
- panic(err) |
- } |
-} |
- |
-type analyticsSettings struct { |
- AnalyticsID string `json:"analytics_id"` |
-} |
- |
-func TestPages(t *testing.T) { |
- fixZeroDurationRE := regexp.MustCompile(`(Running for:|waiting) 0s?`) |
- fixZeroDuration := func(text string) string { |
- return fixZeroDurationRE.ReplaceAllLiteralString(text, "[ZERO DURATION]") |
- } |
- |
- Convey("Testing basic rendering.", t, func() { |
- c := context.Background() |
- c = memory.Use(c) |
- c = common.WithRequest(c, &http.Request{URL: &url.URL{Path: "/foobar"}}) |
- c, _ = testclock.UseTime(c, testclock.TestTimeUTC) |
- c = auth.WithState(c, &authtest.FakeState{Identity: identity.AnonymousIdentity}) |
- c = settings.Use(c, settings.New(&settings.MemoryStorage{Expiration: time.Second})) |
- err := settings.Set(c, "analytics", &analyticsSettings{"UA-12345-01"}, "", "") |
- So(err, ShouldBeNil) |
- c = templates.Use(c, common.GetTemplateBundle("templates")) |
- for _, p := range allPackages { |
- Convey(fmt.Sprintf("Testing handler %q", p.DisplayName), func() { |
- for _, b := range p.Data() { |
- Convey(fmt.Sprintf("Testing: %q", b.Description), func() { |
- args := b.Data |
- // This is not a path, but a file key, should always be "/". |
- tmplName := "pages/" + p.TemplateName |
- buf, err := templates.Render(c, tmplName, args) |
- So(err, ShouldBeNil) |
- fname := fmt.Sprintf( |
- "%s-%s.html", p.DisplayName, b.Description) |
- if *generate { |
- mustWrite(fname, buf) |
- } else { |
- localBuf, err := load(fname) |
- So(err, ShouldBeNil) |
- So(fixZeroDuration(string(buf)), ShouldEqual, fixZeroDuration(string(localBuf))) |
- } |
- }) |
- } |
- }) |
- } |
- }) |
-} |