Skip to content

Commit e25ffbc

Browse files
refactor: combine GetVersion and RuntimeVersion (#4475)
Based on post-merge feedback here: #4450 (comment)
1 parent 83caacf commit e25ffbc

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

bundle/config/mutator/configure_wsfs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (m *configureWSFS) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagno
4343
// Writing notebooks via FUSE is only supported for serverless client version 2+.
4444
// Since we could only test v2.5, since the platform only allows selecting v2 (which is v2.5 internally),
4545
// we restrict FUSE to only be used for v2.5+.
46-
v := dbr.GetVersion(ctx)
46+
v := dbr.RuntimeVersion(ctx)
4747
if v.Type == dbr.ClusterTypeServerless && (v.Major > 2 || (v.Major == 2 && v.Minor >= 5)) {
4848
return nil
4949
}

cmd/root/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ Stack Trace:
190190
Version: build.GetInfo().Version,
191191
Command: commandStr,
192192
OperatingSystem: runtime.GOOS,
193-
DbrVersion: dbr.RuntimeVersion(ctx),
193+
DbrVersion: dbr.RuntimeVersion(ctx).String(),
194194
ExecutionTimeMs: time.Since(startTime).Milliseconds(),
195195
ExitCode: int64(exitCode),
196196
})

libs/dbr/context.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ type Version struct {
4747
Raw string
4848
}
4949

50+
func (v Version) String() string {
51+
return v.Raw
52+
}
53+
5054
// ParseVersion parses a DBR version string and returns structured version info.
5155
// Examples:
5256
// - "16.3" -> Interactive, Major=16, Minor=3
@@ -122,17 +126,13 @@ func RunsOnRuntime(ctx context.Context) bool {
122126
return v.(Environment).IsDbr
123127
}
124128

125-
func RuntimeVersion(ctx context.Context) string {
129+
// RuntimeVersion returns the parsed runtime version from the context.
130+
// It expects a context returned by [DetectRuntime] or [MockRuntime].
131+
func RuntimeVersion(ctx context.Context) Version {
126132
v := ctx.Value(dbrKey)
127133
if v == nil {
128134
panic("dbr.RuntimeVersion called without calling dbr.DetectRuntime first")
129135
}
130136

131-
return v.(Environment).Version
132-
}
133-
134-
// GetVersion returns the parsed runtime version from the context.
135-
// It expects a context returned by [DetectRuntime] or [MockRuntime].
136-
func GetVersion(ctx context.Context) Version {
137-
return ParseVersion(RuntimeVersion(ctx))
137+
return ParseVersion(v.(Environment).Version)
138138
}

libs/dbr/context_test.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ func TestContext_RunsOnRuntimeWithMock(t *testing.T) {
8181

8282
func TestContext_RuntimeVersionWithMock(t *testing.T) {
8383
ctx := context.Background()
84-
assert.Equal(t, "15.4", RuntimeVersion(MockRuntime(ctx, Environment{IsDbr: true, Version: "15.4"})))
85-
assert.Empty(t, RuntimeVersion(MockRuntime(ctx, Environment{})))
84+
assert.Equal(t, "15.4", RuntimeVersion(MockRuntime(ctx, Environment{IsDbr: true, Version: "15.4"})).String())
85+
assert.Empty(t, RuntimeVersion(MockRuntime(ctx, Environment{})).String())
8686
}
8787

8888
func TestParseVersion_Serverless(t *testing.T) {
@@ -153,19 +153,30 @@ func TestClusterType_String(t *testing.T) {
153153
assert.Equal(t, "unknown", ClusterTypeUnknown.String())
154154
}
155155

156-
func TestContext_GetVersion(t *testing.T) {
156+
func TestVersion_String(t *testing.T) {
157+
v := ParseVersion("16.3")
158+
assert.Equal(t, "16.3", v.String())
159+
160+
v = ParseVersion("client.4.9")
161+
assert.Equal(t, "client.4.9", v.String())
162+
163+
v = ParseVersion("")
164+
assert.Equal(t, "", v.String())
165+
}
166+
167+
func TestContext_RuntimeVersionParsed(t *testing.T) {
157168
ctx := context.Background()
158169

159170
// Test serverless version
160171
serverlessCtx := MockRuntime(ctx, Environment{IsDbr: true, Version: "client.4.9"})
161-
v := GetVersion(serverlessCtx)
172+
v := RuntimeVersion(serverlessCtx)
162173
assert.Equal(t, ClusterTypeServerless, v.Type)
163174
assert.Equal(t, 4, v.Major)
164175
assert.Equal(t, 9, v.Minor)
165176

166177
// Test interactive version
167178
interactiveCtx := MockRuntime(ctx, Environment{IsDbr: true, Version: "17.3"})
168-
v = GetVersion(interactiveCtx)
179+
v = RuntimeVersion(interactiveCtx)
169180
assert.Equal(t, ClusterTypeInteractive, v.Type)
170181
assert.Equal(t, 17, v.Major)
171182
assert.Equal(t, 3, v.Minor)

0 commit comments

Comments
 (0)