wip finer grained server regex

This commit is contained in:
Shreyas Goenka 2025-01-24 14:03:15 +01:00
parent 09791fc16a
commit e22b015434
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
2 changed files with 27 additions and 1 deletions

View File

@ -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 {

View File

@ -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]")