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

Side by Side Diff: milo/appengine/swarming/build_test.go

Issue 2818563002: Milo: ACLs for internal swarm jobs (Closed)
Patch Set: Review Created 3 years, 8 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
« no previous file with comments | « milo/appengine/swarming/build.go ('k') | milo/appengine/swarming/buildinfo.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 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 swarming 5 package swarming
6 6
7 import ( 7 import (
8 "encoding/json" 8 "encoding/json"
9 "flag" 9 "flag"
10 "fmt" 10 "fmt"
11 "io/ioutil" 11 "io/ioutil"
12 "path/filepath" 12 "path/filepath"
13 "testing" 13 "testing"
14 "time" 14 "time"
15 15
16 "github.com/luci/luci-go/common/clock/testclock" 16 "github.com/luci/luci-go/common/clock/testclock"
17 memcfg "github.com/luci/luci-go/common/config/impl/memory"
18 "github.com/luci/luci-go/luci_config/server/cfgclient/backend/testconfig "
19 "github.com/luci/luci-go/server/auth"
20 "github.com/luci/luci-go/server/auth/authtest"
21 "github.com/luci/luci-go/server/auth/identity"
17 22
18 "github.com/luci/gae/impl/memory" 23 "github.com/luci/gae/impl/memory"
19 24
20 "golang.org/x/net/context" 25 "golang.org/x/net/context"
21 26
22 . "github.com/smartystreets/goconvey/convey" 27 . "github.com/smartystreets/goconvey/convey"
23 ) 28 )
24 29
25 var generate = flag.Bool("test.generate", false, "Generate expectations instead of running tests.") 30 var generate = flag.Bool("test.generate", false, "Generate expectations instead of running tests.")
26 31
(...skipping 11 matching lines...) Expand all
38 return ShouldEqual(string(actualBuild), string(refBuild)) 43 return ShouldEqual(string(actualBuild), string(refBuild))
39 44
40 } 45 }
41 46
42 func TestBuild(t *testing.T) { 47 func TestBuild(t *testing.T) {
43 t.Parallel() 48 t.Parallel()
44 49
45 if *generate { 50 if *generate {
46 c := context.Background() 51 c := context.Background()
47 c, _ = testclock.UseTime(c, time.Date(2016, time.March, 14, 11, 0, 0, 0, time.UTC)) 52 c, _ = testclock.UseTime(c, time.Date(2016, time.March, 14, 11, 0, 0, 0, time.UTC))
48 » » c = memory.Use(c) 53 » » c = memory.UseWithAppID(c, "dev~luci-milo")
54 » » c = testconfig.WithCommonClient(c, memcfg.New(aclConfgs))
55 » » c = auth.WithState(c, &authtest.FakeState{
56 » » » Identity: "user:alicebob@google.com",
57 » » » IdentityGroups: []string{"all", "googlers"},
58 » » })
49 59
50 for _, tc := range getTestCases() { 60 for _, tc := range getTestCases() {
51 bl := buildLoader{ 61 bl := buildLoader{
52 logDogClientFunc: logDogClientFunc(tc), 62 logDogClientFunc: logDogClientFunc(tc),
53 } 63 }
54 svc := debugSwarmingService{tc} 64 svc := debugSwarmingService{tc}
55 65
56 fmt.Printf("Generating expectations for %s\n", tc) 66 fmt.Printf("Generating expectations for %s\n", tc)
57 67
58 build, err := bl.swarmingBuildImpl(c, svc, "foo", tc.nam e) 68 build, err := bl.swarmingBuildImpl(c, svc, "foo", tc.nam e)
59 if err != nil { 69 if err != nil {
60 panic(fmt.Errorf("Could not run swarmingBuildImp l for %s: %s", tc, err)) 70 panic(fmt.Errorf("Could not run swarmingBuildImp l for %s: %s", tc, err))
61 } 71 }
62 buildJSON, err := json.MarshalIndent(build, "", " ") 72 buildJSON, err := json.MarshalIndent(build, "", " ")
63 if err != nil { 73 if err != nil {
64 panic(fmt.Errorf("Could not JSON marshal %s: %s" , tc.name, err)) 74 panic(fmt.Errorf("Could not JSON marshal %s: %s" , tc.name, err))
65 } 75 }
66 filename := filepath.Join("expectations", tc.name+".json ") 76 filename := filepath.Join("expectations", tc.name+".json ")
67 err = ioutil.WriteFile(filename, []byte(buildJSON), 0644 ) 77 err = ioutil.WriteFile(filename, []byte(buildJSON), 0644 )
68 if err != nil { 78 if err != nil {
69 panic(fmt.Errorf("Encountered error while trying to write to %s: %s", filename, err)) 79 panic(fmt.Errorf("Encountered error while trying to write to %s: %s", filename, err))
70 } 80 }
71 } 81 }
72 return 82 return
73 } 83 }
74 84
75 Convey(`A test Environment`, t, func() { 85 Convey(`A test Environment`, t, func() {
76 c := context.Background() 86 c := context.Background()
77 c, _ = testclock.UseTime(c, time.Date(2016, time.March, 14, 11, 0, 0, 0, time.UTC)) 87 c, _ = testclock.UseTime(c, time.Date(2016, time.March, 14, 11, 0, 0, 0, time.UTC))
78 » » c = memory.Use(c) 88 » » c = memory.UseWithAppID(c, "dev~luci-milo")
89 » » c = testconfig.WithCommonClient(c, memcfg.New(aclConfgs))
90 » » c = auth.WithState(c, &authtest.FakeState{
91 » » » Identity: "user:alicebob@google.com",
92 » » » IdentityGroups: []string{"all", "googlers"},
93 » » })
79 94
80 for _, tc := range getTestCases() { 95 for _, tc := range getTestCases() {
81 Convey(fmt.Sprintf("Test Case: %s", tc.name), func() { 96 Convey(fmt.Sprintf("Test Case: %s", tc.name), func() {
82 bl := buildLoader{ 97 bl := buildLoader{
83 logDogClientFunc: logDogClientFunc(tc), 98 logDogClientFunc: logDogClientFunc(tc),
84 } 99 }
85 svc := debugSwarmingService{tc} 100 svc := debugSwarmingService{tc}
86 101
102 // Special case: The build-internal test case to check that ACLs should fail.
103 if tc.name == "build-internal" {
104 Convey("Should fail", func() {
105 c := auth.WithState(c, &authtest .FakeState{
106 Identity: identity .AnonymousIdentity,
107 IdentityGroups: []string {"all"},
108 })
109 _, err := bl.swarmingBuildImpl(c , svc, "foo", tc.name)
110 So(err.Error(), ShouldResemble, "Not a Milo Job or access denied")
111 })
112 }
113
87 build, err := bl.swarmingBuildImpl(c, svc, "foo" , tc.name) 114 build, err := bl.swarmingBuildImpl(c, svc, "foo" , tc.name)
88 So(err, ShouldBeNil) 115 So(err, ShouldBeNil)
89 So(build, shouldMatchExpectationsFor, tc.name+". json") 116 So(build, shouldMatchExpectationsFor, tc.name+". json")
90 }) 117 })
91 } 118 }
92 }) 119 })
93 } 120 }
OLDNEW
« no previous file with comments | « milo/appengine/swarming/build.go ('k') | milo/appengine/swarming/buildinfo.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698