Skip to content

Commit 19cba73

Browse files
Merge pull request GoogleCloudPlatform#2510 from gemmahou/fixit-group
fixit: Run presubmit fixtures tests by services
2 parents 62b29c0 + 8ff1651 commit 19cba73

File tree

6 files changed

+129
-12
lines changed

6 files changed

+129
-12
lines changed

.github/workflows/presubmit.yaml

+38-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
- uses: actions/setup-go@v4
7474
with:
7575
go-version-file: 'go.mod'
76-
- name: "Run mock tests"
76+
- name: "Run mock samples tests"
7777
run: |
7878
./scripts/github-actions/tests-e2e-samples
7979
env:
@@ -91,7 +91,7 @@ jobs:
9191
- uses: actions/setup-go@v4
9292
with:
9393
go-version-file: 'go.mod'
94-
- name: "Run mock tests"
94+
- name: "Run mock fixtures tests"
9595
run: |
9696
./scripts/github-actions/tests-e2e-fixtures
9797
env:
@@ -101,6 +101,42 @@ jobs:
101101
with:
102102
name: artifacts
103103
path: /tmp/artifacts/
104+
tests-e2e-fixtures-compute:
105+
runs-on: ubuntu-latest
106+
timeout-minutes: 60
107+
steps:
108+
- uses: actions/checkout@v3
109+
- uses: actions/setup-go@v4
110+
with:
111+
go-version-file: 'go.mod'
112+
- name: "Run mock fixtures tests for compute service"
113+
run: |
114+
./scripts/github-actions/tests-e2e-fixtures-compute
115+
env:
116+
ARTIFACTS: /tmp/artifacts
117+
- name: "Upload artifacts"
118+
uses: actions/upload-artifact@v3
119+
with:
120+
name: artifacts
121+
path: /tmp/artifacts/
122+
tests-e2e-fixtures-gkehub:
123+
runs-on: ubuntu-latest
124+
timeout-minutes: 60
125+
steps:
126+
- uses: actions/checkout@v3
127+
- uses: actions/setup-go@v4
128+
with:
129+
go-version-file: 'go.mod'
130+
- name: "Run mock fixtures tests for gkehub service"
131+
run: |
132+
./scripts/github-actions/tests-e2e-fixtures-gkehub
133+
env:
134+
ARTIFACTS: /tmp/artifacts
135+
- name: "Upload artifacts"
136+
uses: actions/upload-artifact@v3
137+
with:
138+
name: artifacts
139+
path: /tmp/artifacts/
104140
pause-tests:
105141
runs-on: ubuntu-22.04
106142
timeout-minutes: 60

scripts/github-actions/tests-e2e-fixtures

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export KUBEBUILDER_ASSETS=$(go run sigs.k8s.io/controller-runtime/tools/setup-en
2929

3030
echo "Running fixtures in tests/e2e..."
3131

32+
export SKIP_TEST_APIGROUP="compute.cnrm.cloud.google.com,gkehub.cnrm.cloud.google.com"
33+
3234
RUN_E2E=1 \
3335
GOLDEN_OBJECT_CHECKS=1 \
3436
GOLDEN_REQUEST_CHECKS=1 \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
# Copyright 2023 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -o errexit
17+
set -o nounset
18+
set -o pipefail
19+
20+
REPO_ROOT="$(git rev-parse --show-toplevel)"
21+
22+
cd ${REPO_ROOT}/
23+
24+
echo "Downloading envtest assets..."
25+
export KUBEBUILDER_ASSETS=$(go run sigs.k8s.io/controller-runtime/tools/setup-envtest@latest use -p path)
26+
27+
echo "Running compute fixtures in tests/e2e..."
28+
29+
RUN_E2E=1 \
30+
GOLDEN_OBJECT_CHECKS=1 \
31+
GOLDEN_REQUEST_CHECKS=1 \
32+
E2E_KUBE_TARGET=envtest \
33+
E2E_GCP_TARGET=mock \
34+
ONLY_TEST_APIGROUP="compute.cnrm.cloud.google.com" \
35+
go test -test.count=1 -timeout 3600s -v ./tests/e2e -run TestAllInSeries/fixtures
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
# Copyright 2023 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -o errexit
17+
set -o nounset
18+
set -o pipefail
19+
20+
REPO_ROOT="$(git rev-parse --show-toplevel)"
21+
22+
cd ${REPO_ROOT}/
23+
24+
echo "Downloading envtest assets..."
25+
export KUBEBUILDER_ASSETS=$(go run sigs.k8s.io/controller-runtime/tools/setup-envtest@latest use -p path)
26+
27+
echo "Running gkehub fixtures in tests/e2e for gkehub..."
28+
29+
RUN_E2E=1 \
30+
GOLDEN_OBJECT_CHECKS=1 \
31+
GOLDEN_REQUEST_CHECKS=1 \
32+
E2E_KUBE_TARGET=envtest \
33+
E2E_GCP_TARGET=mock \
34+
ONLY_TEST_APIGROUP="gkehub.cnrm.cloud.google.com" \
35+
go test -test.count=1 -timeout 3600s -v ./tests/e2e -run TestAllInSeries/fixtures

scripts/github-actions/tests-e2e-scenarios.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ cd ${REPO_ROOT}/
2424
echo "Downloading envtest assets..."
2525
export KUBEBUILDER_ASSETS=$(go run sigs.k8s.io/controller-runtime/tools/setup-envtest@latest use -p path)
2626

27-
echo "Running scenarios tests for LoggingLogMetric direct reconciliation..."
27+
echo "Running scenarios tests..."
2828
GOLDEN_REQUEST_CHECKS=1 E2E_KUBE_TARGET=envtest E2E_GCP_TARGET=mock RUN_E2E=1 \
2929
go test -test.count=1 -timeout 360s -v ./tests/e2e -run TestE2EScript/scenarios/fields

tests/e2e/unified_test.go

+18-9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ import (
3131
"testing"
3232
"time"
3333

34+
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/util/slice"
35+
"k8s.io/klog/v2"
36+
3437
"github.com/GoogleCloudPlatform/k8s-config-connector/config/tests/samples/create"
3538
opcorev1beta1 "github.com/GoogleCloudPlatform/k8s-config-connector/operator/pkg/apis/core/v1beta1"
3639
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/test"
@@ -146,8 +149,21 @@ func testFixturesInSeries(ctx context.Context, t *testing.T, testPause bool, can
146149
fixtures := resourcefixture.Load(t)
147150
for _, fixture := range fixtures {
148151
fixture := fixture
152+
group := fixture.GVK.Group
153+
if s := os.Getenv("SKIP_TEST_APIGROUP"); s != "" {
154+
skippedGroups := strings.Split(s, ",")
155+
if slice.StringSliceContains(skippedGroups, group) {
156+
klog.Infof("skipping test %s because group %q matched entries in SKIP_TEST_APIGROUP=%s", fixture.Name, group, s)
157+
continue
158+
}
159+
}
160+
if s := os.Getenv("ONLY_TEST_APIGROUP"); s != "" {
161+
if group != s {
162+
klog.Infof("skipping test %s because group %q did not match ONLY_TEST_APIGROUP=%s", fixture.Name, group, s)
163+
continue
164+
}
165+
}
149166
// TODO(b/259496928): Randomize the resource names for parallel execution when/if needed.
150-
151167
t.Run(fixture.Name, func(t *testing.T) {
152168
ctx := addTestTimeout(ctx, t, subtestTimeout)
153169

@@ -192,20 +208,13 @@ func runScenario(ctx context.Context, t *testing.T, testPause bool, fixture reso
192208

193209
// Quickly load the fixture with a dummy project, just to see if we should skip it
194210
{
195-
primaryObject, opt := loadFixture(testgcp.GCPProject{ProjectID: "test-skip", ProjectNumber: 123456789}, uniqueID)
211+
_, opt := loadFixture(testgcp.GCPProject{ProjectID: "test-skip", ProjectNumber: 123456789}, uniqueID)
196212
create.MaybeSkip(t, fixture.Name, opt.Create)
197213
if testPause && containsCCOrCCC(opt.Create) {
198214
t.Skipf("test case %q contains ConfigConnector or ConfigConnectorContext object(s): "+
199215
"pause test should not run against test cases already contain ConfigConnector "+
200216
"or ConfigConnectorContext objects", fixture.Name)
201217
}
202-
203-
if s := os.Getenv("ONLY_TEST_APIGROUP"); s != "" {
204-
group := primaryObject.GroupVersionKind().Group
205-
if group != s {
206-
t.Skipf("skipping test because group %q did not match ONLY_TEST_APIGROUP=%s", group, s)
207-
}
208-
}
209218
}
210219

211220
// Create test harness

0 commit comments

Comments
 (0)