From 83e5a8ec0ec906a1bdb1001e8712104bc210ffac Mon Sep 17 00:00:00 2001 From: Gemma Hou Date: Wed, 27 Mar 2024 17:44:00 +0000 Subject: [PATCH] GH action --- .../github-actions/ga-object-schema-test.sh | 29 +++++++++++++++++++ tests/e2e/object_test.go | 14 ++++++--- 2 files changed, 39 insertions(+), 4 deletions(-) create mode 100755 scripts/github-actions/ga-object-schema-test.sh diff --git a/scripts/github-actions/ga-object-schema-test.sh b/scripts/github-actions/ga-object-schema-test.sh new file mode 100755 index 0000000000..b0fd15aa59 --- /dev/null +++ b/scripts/github-actions/ga-object-schema-test.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +set -o errexit +set -o nounset +set -o pipefail +REPO_ROOT="$(git rev-parse --show-toplevel)" +source ${REPO_ROOT}/scripts/shared-vars-public.sh +cd ${REPO_ROOT} +source ${REPO_ROOT}/scripts/fetch_ext_bins.sh && \ + fetch_tools && \ + setup_envs + +cd ${REPO_ROOT}/ +echo "Running mock e2e object schema tests..." +E2E_KUBE_TARGET=envtest \ + RUN_E2E=1 E2E_GCP_TARGET=mock \ + go test -test.count=1 -timeout 3600s -v ./tests/e2e -run TestKubeObject/fixtures 2>&1 \ No newline at end of file diff --git a/tests/e2e/object_test.go b/tests/e2e/object_test.go index e3d4431da5..f6da7f77d1 100644 --- a/tests/e2e/object_test.go +++ b/tests/e2e/object_test.go @@ -136,17 +136,23 @@ func compareGoldenObject(path string, got []byte) error { if writeGoldenOutput && os.IsNotExist(err) { // Expected when creating output for the first time if err := os.WriteFile(path, got, 0644); err != nil { - return fmt.Errorf("failed to write golden output %s: %v", path, err) + return fmt.Errorf("failed to write golden output %s: %w", path, err) } fmt.Printf("wrote updated golden output to %s", path) return nil } else { - return fmt.Errorf("failed to read golden file %q: %v", path, err) + return fmt.Errorf("failed to read golden file %q: %w", path, err) } } var wantMap, gotMap map[string]interface{} - yaml.Unmarshal(want, &wantMap) - yaml.Unmarshal(got, &gotMap) + err = yaml.Unmarshal(want, &wantMap) + if err != nil { + return err + } + err = yaml.Unmarshal(got, &gotMap) + if err != nil { + return err + } if ok, err := compareNestedFields(wantMap, gotMap); !ok { return err }