From 4eade1c1fb80b564b9eeb1576b6a65dbce11b41f Mon Sep 17 00:00:00 2001 From: Bryce Lampe Date: Wed, 4 Dec 2024 21:07:50 -0800 Subject: [PATCH] Ensure module versions match the downloaded API's minor (#3349) --- provider/pkg/version/version_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/provider/pkg/version/version_test.go b/provider/pkg/version/version_test.go index 9f4e2469d5..2994c42709 100644 --- a/provider/pkg/version/version_test.go +++ b/provider/pkg/version/version_test.go @@ -1,11 +1,38 @@ package version import ( + "fmt" + "os" + "regexp" "testing" + "github.com/blang/semver" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestUserAgent(t *testing.T) { assert.Regexp(t, "^pulumi-kubernetes/dev (.*/.*) client-go/unknown$", UserAgent) } + +func TestKubernetesMinorVersion(t *testing.T) { + + re, err := regexp.Compile(`KUBE_VERSION\s+\?=\s+v(?P.*)`) + require.NoError(t, err) + + mf, err := os.ReadFile("../../../Makefile") + require.NoError(t, err) + + matches := re.FindStringSubmatch(string(mf)) + require.Len(t, matches, 2) + + version, err := semver.ParseTolerant(matches[1]) + require.NoError(t, err) + + mod, err := os.ReadFile("../../go.mod") + require.NoError(t, err) + + want := fmt.Sprintf("k8s.io/api v0.%d", version.Minor) + + assert.Contains(t, string(mod), want, "KUBE_VERSION=v%s doesn't match go.mod's minor version", version) +}