| OLD | NEW |
| 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" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 // This is one hour after the start timestamp in the sample test
data. | 52 // This is one hour after the start timestamp in the sample test
data. |
| 53 c, _ = testclock.UseTime(c, time.Date(2016, time.March, 14, 11,
0, 0, 0, time.UTC)) | 53 c, _ = testclock.UseTime(c, time.Date(2016, time.March, 14, 11,
0, 0, 0, time.UTC)) |
| 54 c = memory.UseWithAppID(c, "dev~luci-milo") | 54 c = memory.UseWithAppID(c, "dev~luci-milo") |
| 55 c = testconfig.WithCommonClient(c, memcfg.New(aclConfgs)) | 55 c = testconfig.WithCommonClient(c, memcfg.New(aclConfgs)) |
| 56 c = auth.WithState(c, &authtest.FakeState{ | 56 c = auth.WithState(c, &authtest.FakeState{ |
| 57 Identity: "user:alicebob@google.com", | 57 Identity: "user:alicebob@google.com", |
| 58 IdentityGroups: []string{"all", "googlers"}, | 58 IdentityGroups: []string{"all", "googlers"}, |
| 59 }) | 59 }) |
| 60 | 60 |
| 61 for _, tc := range getTestCases(".") { | 61 for _, tc := range getTestCases(".") { |
| 62 » » » bl := buildLoader{ | 62 » » » bl := BuildLoader{ |
| 63 logDogClientFunc: logDogClientFunc(tc), | 63 logDogClientFunc: logDogClientFunc(tc), |
| 64 } | 64 } |
| 65 svc := debugSwarmingService{tc} | 65 svc := debugSwarmingService{tc} |
| 66 | 66 |
| 67 fmt.Printf("Generating expectations for %s\n", tc) | 67 fmt.Printf("Generating expectations for %s\n", tc) |
| 68 | 68 |
| 69 » » » build, err := bl.swarmingBuildImpl(c, svc, "foo", tc.nam
e) | 69 » » » build, err := bl.SwarmingBuildImpl(c, svc, "foo", tc.nam
e) |
| 70 if err != nil { | 70 if err != nil { |
| 71 panic(fmt.Errorf("Could not run swarmingBuildImp
l for %s: %s", tc, err)) | 71 panic(fmt.Errorf("Could not run swarmingBuildImp
l for %s: %s", tc, err)) |
| 72 } | 72 } |
| 73 buildJSON, err := json.MarshalIndent(build, "", " ") | 73 buildJSON, err := json.MarshalIndent(build, "", " ") |
| 74 if err != nil { | 74 if err != nil { |
| 75 panic(fmt.Errorf("Could not JSON marshal %s: %s"
, tc.name, err)) | 75 panic(fmt.Errorf("Could not JSON marshal %s: %s"
, tc.name, err)) |
| 76 } | 76 } |
| 77 filename := filepath.Join("expectations", tc.name+".json
") | 77 filename := filepath.Join("expectations", tc.name+".json
") |
| 78 err = ioutil.WriteFile(filename, []byte(buildJSON), 0644
) | 78 err = ioutil.WriteFile(filename, []byte(buildJSON), 0644
) |
| 79 if err != nil { | 79 if err != nil { |
| 80 panic(fmt.Errorf("Encountered error while trying
to write to %s: %s", filename, err)) | 80 panic(fmt.Errorf("Encountered error while trying
to write to %s: %s", filename, err)) |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 return | 83 return |
| 84 } | 84 } |
| 85 | 85 |
| 86 Convey(`A test Environment`, t, func() { | 86 Convey(`A test Environment`, t, func() { |
| 87 c := context.Background() | 87 c := context.Background() |
| 88 // This is one hour after the start timestamp in the sample test
data. | 88 // This is one hour after the start timestamp in the sample test
data. |
| 89 c, _ = testclock.UseTime(c, time.Date(2016, time.March, 14, 11,
0, 0, 0, time.UTC)) | 89 c, _ = testclock.UseTime(c, time.Date(2016, time.March, 14, 11,
0, 0, 0, time.UTC)) |
| 90 c = memory.UseWithAppID(c, "dev~luci-milo") | 90 c = memory.UseWithAppID(c, "dev~luci-milo") |
| 91 c = testconfig.WithCommonClient(c, memcfg.New(aclConfgs)) | 91 c = testconfig.WithCommonClient(c, memcfg.New(aclConfgs)) |
| 92 c = auth.WithState(c, &authtest.FakeState{ | 92 c = auth.WithState(c, &authtest.FakeState{ |
| 93 Identity: "user:alicebob@google.com", | 93 Identity: "user:alicebob@google.com", |
| 94 IdentityGroups: []string{"all", "googlers"}, | 94 IdentityGroups: []string{"all", "googlers"}, |
| 95 }) | 95 }) |
| 96 | 96 |
| 97 for _, tc := range getTestCases(".") { | 97 for _, tc := range getTestCases(".") { |
| 98 Convey(fmt.Sprintf("Test Case: %s", tc.name), func() { | 98 Convey(fmt.Sprintf("Test Case: %s", tc.name), func() { |
| 99 » » » » bl := buildLoader{ | 99 » » » » bl := BuildLoader{ |
| 100 logDogClientFunc: logDogClientFunc(tc), | 100 logDogClientFunc: logDogClientFunc(tc), |
| 101 } | 101 } |
| 102 svc := debugSwarmingService{tc} | 102 svc := debugSwarmingService{tc} |
| 103 | 103 |
| 104 // Special case: The build-internal test case to
check that ACLs should fail. | 104 // Special case: The build-internal test case to
check that ACLs should fail. |
| 105 if tc.name == "build-internal" { | 105 if tc.name == "build-internal" { |
| 106 Convey("Should fail", func() { | 106 Convey("Should fail", func() { |
| 107 c := auth.WithState(c, &authtest
.FakeState{ | 107 c := auth.WithState(c, &authtest
.FakeState{ |
| 108 Identity: identity
.AnonymousIdentity, | 108 Identity: identity
.AnonymousIdentity, |
| 109 IdentityGroups: []string
{"all"}, | 109 IdentityGroups: []string
{"all"}, |
| 110 }) | 110 }) |
| 111 » » » » » » _, err := bl.swarmingBuildImpl(c
, svc, "foo", tc.name) | 111 » » » » » » _, err := bl.SwarmingBuildImpl(c
, svc, "foo", tc.name) |
| 112 So(err.Error(), ShouldResemble,
"Not a Milo Job or access denied") | 112 So(err.Error(), ShouldResemble,
"Not a Milo Job or access denied") |
| 113 }) | 113 }) |
| 114 } | 114 } |
| 115 | 115 |
| 116 » » » » build, err := bl.swarmingBuildImpl(c, svc, "foo"
, tc.name) | 116 » » » » build, err := bl.SwarmingBuildImpl(c, svc, "foo"
, tc.name) |
| 117 So(err, ShouldBeNil) | 117 So(err, ShouldBeNil) |
| 118 So(build, shouldMatchExpectationsFor, tc.name+".
json") | 118 So(build, shouldMatchExpectationsFor, tc.name+".
json") |
| 119 }) | 119 }) |
| 120 } | 120 } |
| 121 }) | 121 }) |
| 122 } | 122 } |
| OLD | NEW |