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

Unified Diff: milo/job_source/buildbot/build_test.go

Issue 2948143003: [milo] job_source -> build_source. (Closed)
Patch Set: fix tests Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « milo/job_source/buildbot/build.go ('k') | milo/job_source/buildbot/builder.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: milo/job_source/buildbot/build_test.go
diff --git a/milo/job_source/buildbot/build_test.go b/milo/job_source/buildbot/build_test.go
deleted file mode 100644
index d1a2a7fc35bbec64267c8998a332be4799640a66..0000000000000000000000000000000000000000
--- a/milo/job_source/buildbot/build_test.go
+++ /dev/null
@@ -1,113 +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 buildbot
-
-import (
- "encoding/json"
- "flag"
- "fmt"
- "io/ioutil"
- "path"
- "strings"
- "testing"
-
- "github.com/luci/gae/impl/memory"
- ds "github.com/luci/gae/service/datastore"
- "github.com/luci/luci-go/common/clock/testclock"
- memcfg "github.com/luci/luci-go/common/config/impl/memory"
- "github.com/luci/luci-go/luci_config/server/cfgclient/backend/testconfig"
- "github.com/luci/luci-go/server/auth"
- "github.com/luci/luci-go/server/auth/authtest"
- "github.com/luci/luci-go/server/auth/identity"
-
- "golang.org/x/net/context"
-
- . "github.com/smartystreets/goconvey/convey"
-)
-
-var generate = flag.Bool("test.generate", false, "Generate expectations instead of running tests.")
-
-func load(name string) ([]byte, error) {
- filename := strings.Join([]string{"expectations", name}, "/")
- return ioutil.ReadFile(filename)
-}
-
-func shouldMatchExpectationsFor(actualContents interface{}, expectedFilename ...interface{}) string {
- refBuild, err := load(expectedFilename[0].(string))
- if err != nil {
- return fmt.Sprintf("Could not load %s: %s", expectedFilename[0], err.Error())
- }
- actualBuild, err := json.MarshalIndent(actualContents, "", " ")
- return ShouldEqual(string(actualBuild), string(refBuild))
-
-}
-
-func TestBuild(t *testing.T) {
- c := memory.UseWithAppID(context.Background(), "dev~luci-milo")
- c, _ = testclock.UseTime(c, testclock.TestTimeUTC)
-
- if *generate {
- for _, tc := range TestCases {
- fmt.Printf("Generating expectations for %s/%s\n", tc.Builder, tc.Build)
- build, err := DebugBuild(c, ".", tc.Builder, tc.Build)
- if err != nil {
- panic(fmt.Errorf("Could not run build() for %s/%s: %s", tc.Builder, tc.Build, err))
- }
- buildJSON, err := json.MarshalIndent(build, "", " ")
- if err != nil {
- panic(fmt.Errorf("Could not JSON marshal %s/%s: %s", tc.Builder, tc.Build, err))
- }
- fname := fmt.Sprintf("%s.%d.build.json", tc.Builder, tc.Build)
- fpath := path.Join("expectations", fname)
- err = ioutil.WriteFile(fpath, []byte(buildJSON), 0644)
- if err != nil {
- panic(fmt.Errorf("Encountered error while trying to write to %s: %s", fpath, err))
- }
- }
- return
- }
-
- Convey(`A test Environment`, t, func() {
- c = testconfig.WithCommonClient(c, memcfg.New(bbAclConfigs))
- c = auth.WithState(c, &authtest.FakeState{
- Identity: identity.AnonymousIdentity,
- IdentityGroups: []string{"all"},
- })
-
- for _, tc := range TestCases {
- Convey(fmt.Sprintf("Test Case: %s/%s", tc.Builder, tc.Build), func() {
- build, err := DebugBuild(c, ".", tc.Builder, tc.Build)
- So(err, ShouldBeNil)
- fname := fmt.Sprintf("%s.%d.build.json", tc.Builder, tc.Build)
- So(build, shouldMatchExpectationsFor, fname)
- })
- }
-
- Convey(`Disallow anonomyous users from accessing internal builds`, func() {
- ds.Put(c, &buildbotBuild{
- Master: "fake",
- Buildername: "fake",
- Number: 1,
- Internal: true,
- })
- _, err := getBuild(c, "fake", "fake", 1)
- So(err, ShouldResemble, errNotAuth)
- })
- })
-}
-
-var internalConfig = `
-buildbot: {
- internal_reader: "googlers"
- public_subscription: "projects/luci-milo/subscriptions/buildbot-public"
- internal_subscription: "projects/luci-milo/subscriptions/buildbot-private"
-}
-`
-
-var bbAclConfigs = map[string]memcfg.ConfigSet{
- "services/luci-milo": {
- "settings.cfg": internalConfig,
- },
-}
« no previous file with comments | « milo/job_source/buildbot/build.go ('k') | milo/job_source/buildbot/builder.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698