Skip to content

Commit 51ab137

Browse files
committed
extract setSpecDefaults
1 parent bcf108d commit 51ab137

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

libs/testserver/pipelines.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,14 @@ func (s *FakeWorkspace) PipelineCreate(req Request) Response {
4040
r.Spec = &spec
4141

4242
pipelineId := uuid.New().String()
43-
spec.Id = pipelineId
4443
r.PipelineId = pipelineId
4544
r.CreatorUserName = "tester@databricks.com"
4645
r.LastModified = time.Now().UnixMilli()
4746
r.Name = r.Spec.Name
4847
r.RunAsUserName = "tester@databricks.com"
4948
r.State = "IDLE"
5049

51-
// If the pipeline definition does not specify a catalog, it switches to Hive metastore mode
52-
// and if the storage location is not specified, API automatically generates a storage location
53-
// (ref: https://docs.databricks.com/gcp/en/dlt/hive-metastore#specify-a-storage-location)
54-
if spec.Storage == "" && spec.Catalog == "" {
55-
spec.Storage = "dbfs:/pipelines/" + pipelineId
56-
}
50+
setSpecDefaults(&spec, pipelineId)
5751
s.Pipelines[pipelineId] = r
5852

5953
return Response{
@@ -63,6 +57,16 @@ func (s *FakeWorkspace) PipelineCreate(req Request) Response {
6357
}
6458
}
6559

60+
func setSpecDefaults(spec *pipelines.PipelineSpec, pipelineId string) {
61+
spec.Id = pipelineId
62+
// If the pipeline definition does not specify a catalog, it switches to Hive metastore mode
63+
// and if the storage location is not specified, API automatically generates a storage location
64+
// (ref: https://docs.databricks.com/gcp/en/dlt/hive-metastore#specify-a-storage-location)
65+
if spec.Storage == "" && spec.Catalog == "" {
66+
spec.Storage = "dbfs:/pipelines/" + pipelineId
67+
}
68+
}
69+
6670
func (s *FakeWorkspace) PipelineUpdate(req Request, pipelineId string) Response {
6771
defer s.LockUnlock()()
6872

@@ -82,12 +86,8 @@ func (s *FakeWorkspace) PipelineUpdate(req Request, pipelineId string) Response
8286
}
8387
}
8488

85-
spec.Id = pipelineId
86-
if spec.Storage == "" && spec.Catalog == "" {
87-
spec.Storage = "dbfs:/pipelines/" + pipelineId
88-
}
89-
9089
item.Spec = &spec
90+
setSpecDefaults(&spec, pipelineId)
9191
s.Pipelines[pipelineId] = item
9292

9393
return Response{

0 commit comments

Comments
 (0)