From a1620c93c4127843fbbc75b4515404d8fa417777 Mon Sep 17 00:00:00 2001 From: Jason Hall Date: Sat, 16 Jul 2022 02:26:24 -0400 Subject: [PATCH] Prepare tests for impending knative/pkg version bump https://github.com/knative/pkg/pull/2548 changes pkg/changeset.Get to read VCS information from information embedded by the Go compiler into built binaries, instead of relying on the convention that a kodata/HEAD symlink exists pointing to the repo's .git/HEAD, and a kodata/refs points to .git/refs. This fails in tests though, since tests don't stamp this information into the binary where it can be read. This change removes our tests' usage of changeset.Get and instead replaces those fake commit SHAs with more obviously placeholder values. It doesn't seem that the tests cared that it was an actual SHA, let along the actual current SHA, they just needed any value that looked like a SHA. --- pkg/pod/pod_test.go | 10 ++-------- pkg/reconciler/taskrun/taskrun_test.go | 9 ++------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/pkg/pod/pod_test.go b/pkg/pod/pod_test.go index 4a1c1e0c0d5..7bc11d6c721 100644 --- a/pkg/pod/pod_test.go +++ b/pkg/pod/pod_test.go @@ -41,7 +41,6 @@ import ( "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" fakek8s "k8s.io/client-go/kubernetes/fake" - "knative.dev/pkg/changeset" logtesting "knative.dev/pkg/logging/testing" "knative.dev/pkg/system" @@ -63,8 +62,6 @@ var ( defaultActiveDeadlineSeconds = int64(config.DefaultTimeoutMinutes * 60 * deadlineFactor) - fakeVersion string - resourceQuantityCmp = cmp.Comparer(func(x, y resource.Quantity) bool { return x.Cmp(y) == 0 }) @@ -72,13 +69,10 @@ var ( volumeMountSort = cmpopts.SortSlices(func(i, j corev1.VolumeMount) bool { return i.Name < j.Name }) ) +const fakeVersion = "0000000000000000000000000000000000000000" + func init() { os.Setenv("KO_DATA_PATH", "./testdata/") - commit, err := changeset.Get() - if err != nil { - panic(err) - } - fakeVersion = commit } func TestPodBuild(t *testing.T) { diff --git a/pkg/reconciler/taskrun/taskrun_test.go b/pkg/reconciler/taskrun/taskrun_test.go index 2870e0d235b..3e21cc42239 100644 --- a/pkg/reconciler/taskrun/taskrun_test.go +++ b/pkg/reconciler/taskrun/taskrun_test.go @@ -61,7 +61,6 @@ import ( ktesting "k8s.io/client-go/testing" "k8s.io/client-go/tools/record" "knative.dev/pkg/apis" - "knative.dev/pkg/changeset" cminformer "knative.dev/pkg/configmap/informer" "knative.dev/pkg/controller" "knative.dev/pkg/kmeta" @@ -398,12 +397,13 @@ var ( }, } - fakeVersion string gitResourceSecurityContext = &corev1.SecurityContext{ RunAsUser: ptr.Int64(0), } ) +const fakeVersion string = "0000000000000000000000000000000000000000" + func placeToolsInitContainer(steps []string) corev1.Container { return corev1.Container{ Command: append([]string{"/ko-app/entrypoint", "init", "/ko-app/entrypoint", entrypointLocation}, steps...), @@ -442,11 +442,6 @@ func createServiceAccount(t *testing.T, assets test.Assets, name string, namespa func init() { os.Setenv("KO_DATA_PATH", "./testdata/") - commit, err := changeset.Get() - if err != nil { - panic(err) - } - fakeVersion = commit } func getRunName(tr *v1beta1.TaskRun) string {