Skip to content

Commit

Permalink
Prepare tests for impending knative/pkg version bump
Browse files Browse the repository at this point in the history
knative/pkg#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.
  • Loading branch information
imjasonh authored and tekton-robot committed Jul 21, 2022
1 parent 85d5344 commit a1620c9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
10 changes: 2 additions & 8 deletions pkg/pod/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -63,22 +62,17 @@ var (

defaultActiveDeadlineSeconds = int64(config.DefaultTimeoutMinutes * 60 * deadlineFactor)

fakeVersion string

resourceQuantityCmp = cmp.Comparer(func(x, y resource.Quantity) bool {
return x.Cmp(y) == 0
})
volumeSort = cmpopts.SortSlices(func(i, j corev1.Volume) bool { return i.Name < j.Name })
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) {
Expand Down
9 changes: 2 additions & 7 deletions pkg/reconciler/taskrun/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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...),
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a1620c9

Please sign in to comment.