From e22b01543454b0cbbf2b612d0967056a8b34c975 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Fri, 24 Jan 2025 14:03:15 +0100 Subject: [PATCH] wip finer grained server regex --- internal/testserver/server.go | 3 ++- libs/testdiff/replacement.go | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/internal/testserver/server.go b/internal/testserver/server.go index fa80cbe4a..d160f400b 100644 --- a/internal/testserver/server.go +++ b/internal/testserver/server.go @@ -58,7 +58,8 @@ func NewFromConfig(t testutil.TestingT, path string) *Server { ctx, replacements := testdiff.WithReplacementsMap(context.Background()) testdiff.PrepareReplacementOS(t, replacements) testdiff.PrepareReplacementsUUID(t, replacements) - testdiff.PrepareReplacementsSemver(t, replacements) + testdiff.PrepareReplacementVersions(t, replacements) + // testdiff.PrepareReplacementsSemver(t, replacements) server := New(ctx, t) for _, apiSpec := range apiSpecs { diff --git a/libs/testdiff/replacement.go b/libs/testdiff/replacement.go index 82dc8bb89..8b75c70b3 100644 --- a/libs/testdiff/replacement.go +++ b/libs/testdiff/replacement.go @@ -9,10 +9,13 @@ import ( "slices" "strings" + "github.com/databricks/cli/internal/build" "github.com/databricks/cli/internal/testutil" "github.com/databricks/cli/libs/iamutil" "github.com/databricks/databricks-sdk-go" "github.com/databricks/databricks-sdk-go/service/iam" + "github.com/databricks/databricks-sdk-go/version" + "golang.org/x/mod/semver" ) const ( @@ -198,6 +201,28 @@ func PrepareReplacementsTemporaryDirectory(t testutil.TestingT, r *ReplacementsC r.append(privatePathRegex, "/tmp/.../$3") } +// cli/0.0.0-dev databricks-sdk-go/0.55.0 go/1.23.4 os/darwin cmd/jobs_create cmd-exec-id/2222ca79-6a7e-4e8a-9e89-73392f8a2f09 auth/pat + +func PrepareReplacementVersions(t testutil.TestingT, r *ReplacementsContext) { + t.Helper() + r.Set(version.Version, "$GO_SDK_VERSION") + + buildInfo := build.GetInfo() + // test build versions can contain build metadata in their semver. Add a regex to match that. + // TODO: This does not work. Fix it. + cliVersionRegex := regexp.MustCompile(buildInfo.Version + `(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?`) + r.append(cliVersionRegex, "$CLI_VERSION") + + r.Set(goVersion(), "$GO_VERSION") +} + +func goVersion() string { + gv := runtime.Version() + ssv := strings.ReplaceAll(gv, "go", "v") + sv := semver.Canonical(ssv) + return strings.TrimPrefix(sv, "v") +} + func PrepareReplacementsSemver(t testutil.TestingT, r *ReplacementsContext) { t.Helper() r.append(semverRegex, "[SEMVER]")