Skip to content

Commit 4432d62

Browse files
authored
acc: Improve dashboards testserver; enable detect-change test on local (#3136)
## Changes - Improve dashboards in test server to better match real ones. - Improve testserver's file system to track metadata. - Enable TEST_DEFAULT_WAREHOUSE_ID in local tests. - Enable dashboard/detect-change test to run locally in addition to cloud. ## Why Running tests on local server gives faster feedback.
1 parent 4f398fd commit 4432d62

File tree

5 files changed

+42
-14
lines changed

5 files changed

+42
-14
lines changed

acceptance/acceptance_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,14 @@ func testAccept(t *testing.T, inprocessMode bool, singleTest string) int {
189189

190190
if cloudEnv == "" {
191191
internal.StartDefaultServer(t)
192+
if os.Getenv("TEST_DEFAULT_WAREHOUSE_ID") == "" {
193+
t.Setenv("TEST_DEFAULT_WAREHOUSE_ID", "8ec9edc1-db0c-40df-af8d-7580020fe61e")
194+
}
195+
}
196+
197+
testDefaultWarehouseId := os.Getenv("TEST_DEFAULT_WAREHOUSE_ID")
198+
if testDefaultWarehouseId != "" {
199+
repls.Set(testDefaultWarehouseId, "[TEST_DEFAULT_WAREHOUSE_ID]")
192200
}
193201

194202
terraformrcPath := filepath.Join(buildDir, ".terraformrc")

acceptance/bundle/deploy/dashboard/detect-change/test.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Local = false
1+
Local = true
22
Cloud = true
33

44
Ignore = [

acceptance/bundle/generate/dashboard-inplace/output.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Deployment complete!
1313
>>> [CLI] lakeview update [DASHBOARD_ID] --serialized-dashboard {"a":"b"}
1414
{
1515
"etag":"[UUID]",
16+
"lifecycle_state":"ACTIVE",
1617
"serialized_dashboard":"{\"a\":\"b\"}"
1718
}
1819

libs/testserver/dashboards.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"strings"
66

77
"github.com/databricks/databricks-sdk-go/service/dashboards"
8+
"github.com/databricks/databricks-sdk-go/service/workspace"
89
"github.com/google/uuid"
910
)
1011

@@ -48,6 +49,13 @@ func (s *FakeWorkspace) DashboardCreate(req Request) Response {
4849
}
4950

5051
s.Dashboards[dashboard.DashboardId] = dashboard
52+
s.files[dashboard.Path] = FileEntry{
53+
Info: workspace.ObjectInfo{
54+
ObjectType: "DASHBOARD",
55+
Path: dashboard.Path,
56+
},
57+
Data: []byte(dashboard.SerializedDashboard),
58+
}
5159

5260
return Response{
5361
Body: dashboards.Dashboard{
@@ -70,6 +78,9 @@ func (s *FakeWorkspace) DashboardUpdate(req Request) Response {
7078
// Update the etag for the dashboard.
7179
dashboard.Etag = uuid.New().String()
7280

81+
// All dashboards are active by default:
82+
dashboard.LifecycleState = dashboards.LifecycleStateActive
83+
7384
dashboardId := req.Vars["dashboard_id"]
7485
s.Dashboards[dashboardId] = dashboard
7586

libs/testserver/fake_workspace.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,18 @@ const (
2828
TestRunID = 2305843009213693969
2929
)
3030

31+
type FileEntry struct {
32+
Info workspace.ObjectInfo
33+
Data []byte
34+
}
35+
3136
// FakeWorkspace holds a state of a workspace for acceptance tests.
3237
type FakeWorkspace struct {
3338
mu sync.Mutex
3439
url string
3540

3641
directories map[string]bool
37-
files map[string][]byte
42+
files map[string]FileEntry
3843
// normally, ids are not sequential, but we make them sequential for deterministic diff
3944
nextJobId int64
4045
nextJobRunId int64
@@ -109,7 +114,7 @@ func NewFakeWorkspace(url string) *FakeWorkspace {
109114
directories: map[string]bool{
110115
"/Workspace": true,
111116
},
112-
files: map[string][]byte{},
117+
files: make(map[string]FileEntry),
113118
Jobs: map[int64]jobs.Job{},
114119
JobRuns: map[int64]jobs.Run{},
115120
nextJobId: TestJobID,
@@ -132,13 +137,9 @@ func (s *FakeWorkspace) WorkspaceGetStatus(path string) Response {
132137
Path: path,
133138
},
134139
}
135-
} else if _, ok := s.files[path]; ok {
140+
} else if entry, ok := s.files[path]; ok {
136141
return Response{
137-
Body: &workspace.ObjectInfo{
138-
ObjectType: "FILE",
139-
Path: path,
140-
Language: "SCALA",
141-
},
142+
Body: entry.Info,
142143
}
143144
} else {
144145
return Response{
@@ -155,17 +156,17 @@ func (s *FakeWorkspace) WorkspaceMkdirs(request workspace.Mkdirs) {
155156

156157
func (s *FakeWorkspace) WorkspaceExport(path string) []byte {
157158
defer s.LockUnlock()()
158-
return s.files[path]
159+
return s.files[path].Data
159160
}
160161

161162
func (s *FakeWorkspace) WorkspaceDelete(path string, recursive bool) {
162163
defer s.LockUnlock()()
163164
if !recursive {
164-
s.files[path] = nil
165+
delete(s.files, path)
165166
} else {
166167
for key := range s.files {
167168
if strings.HasPrefix(key, path) {
168-
s.files[key] = nil
169+
delete(s.files, key)
169170
}
170171
}
171172
}
@@ -178,7 +179,14 @@ func (s *FakeWorkspace) WorkspaceFilesImportFile(filePath string, body []byte) {
178179

179180
defer s.LockUnlock()()
180181

181-
s.files[filePath] = body
182+
s.files[filePath] = FileEntry{
183+
Info: workspace.ObjectInfo{
184+
ObjectType: "FILE",
185+
Path: filePath,
186+
Language: "SCALA",
187+
},
188+
Data: body,
189+
}
182190

183191
// Add all directories in the path to the directories map
184192
for dir := path.Dir(filePath); dir != "/"; dir = path.Dir(dir) {
@@ -193,7 +201,7 @@ func (s *FakeWorkspace) WorkspaceFilesExportFile(path string) []byte {
193201

194202
defer s.LockUnlock()()
195203

196-
return s.files[path]
204+
return s.files[path].Data
197205
}
198206

199207
func (s *FakeWorkspace) JobsCreate(request jobs.CreateJob) Response {

0 commit comments

Comments
 (0)