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

Unified Diff: milo/job_source/swarming/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/swarming/buildLog_test.go ('k') | milo/job_source/swarming/buildinfo.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: milo/job_source/swarming/build_test.go
diff --git a/milo/job_source/swarming/build_test.go b/milo/job_source/swarming/build_test.go
deleted file mode 100644
index 0d4ddbf8fd0fce49b5df0e229cdb4db1aec1dc0a..0000000000000000000000000000000000000000
--- a/milo/job_source/swarming/build_test.go
+++ /dev/null
@@ -1,122 +0,0 @@
-// Copyright 2015 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 swarming
-
-import (
- "encoding/json"
- "flag"
- "fmt"
- "io/ioutil"
- "path/filepath"
- "testing"
- "time"
-
- "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"
-
- "github.com/luci/gae/impl/memory"
-
- "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 := filepath.Join("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) {
- t.Parallel()
-
- if *generate {
- c := context.Background()
- // This is one hour after the start timestamp in the sample test data.
- c, _ = testclock.UseTime(c, time.Date(2016, time.March, 14, 11, 0, 0, 0, time.UTC))
- c = memory.UseWithAppID(c, "dev~luci-milo")
- c = testconfig.WithCommonClient(c, memcfg.New(aclConfgs))
- c = auth.WithState(c, &authtest.FakeState{
- Identity: "user:alicebob@google.com",
- IdentityGroups: []string{"all", "googlers"},
- })
-
- for _, tc := range getTestCases(".") {
- bl := buildLoader{
- logDogClientFunc: logDogClientFunc(tc),
- }
- svc := debugSwarmingService{tc}
-
- fmt.Printf("Generating expectations for %s\n", tc)
-
- build, err := bl.swarmingBuildImpl(c, svc, "foo", tc.name)
- if err != nil {
- panic(fmt.Errorf("Could not run swarmingBuildImpl for %s: %s", tc, err))
- }
- buildJSON, err := json.MarshalIndent(build, "", " ")
- if err != nil {
- panic(fmt.Errorf("Could not JSON marshal %s: %s", tc.name, err))
- }
- filename := filepath.Join("expectations", tc.name+".json")
- err = ioutil.WriteFile(filename, []byte(buildJSON), 0644)
- if err != nil {
- panic(fmt.Errorf("Encountered error while trying to write to %s: %s", filename, err))
- }
- }
- return
- }
-
- Convey(`A test Environment`, t, func() {
- c := context.Background()
- // This is one hour after the start timestamp in the sample test data.
- c, _ = testclock.UseTime(c, time.Date(2016, time.March, 14, 11, 0, 0, 0, time.UTC))
- c = memory.UseWithAppID(c, "dev~luci-milo")
- c = testconfig.WithCommonClient(c, memcfg.New(aclConfgs))
- c = auth.WithState(c, &authtest.FakeState{
- Identity: "user:alicebob@google.com",
- IdentityGroups: []string{"all", "googlers"},
- })
-
- for _, tc := range getTestCases(".") {
- Convey(fmt.Sprintf("Test Case: %s", tc.name), func() {
- bl := buildLoader{
- logDogClientFunc: logDogClientFunc(tc),
- }
- svc := debugSwarmingService{tc}
-
- // Special case: The build-internal test case to check that ACLs should fail.
- if tc.name == "build-internal" {
- Convey("Should fail", func() {
- c := auth.WithState(c, &authtest.FakeState{
- Identity: identity.AnonymousIdentity,
- IdentityGroups: []string{"all"},
- })
- _, err := bl.swarmingBuildImpl(c, svc, "foo", tc.name)
- So(err.Error(), ShouldResemble, "Not a Milo Job or access denied")
- })
- }
-
- build, err := bl.swarmingBuildImpl(c, svc, "foo", tc.name)
- So(err, ShouldBeNil)
- So(build, shouldMatchExpectationsFor, tc.name+".json")
- })
- }
- })
-}
« no previous file with comments | « milo/job_source/swarming/buildLog_test.go ('k') | milo/job_source/swarming/buildinfo.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698