Skip to content

Commit dd9b513

Browse files
committed
extract setSpecDefaults
1 parent bcf108d commit dd9b513

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,21 +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-
}
57-
s.Pipelines[pipelineId] = r
50+
setSpecDefaults(&spec, pipelineId)
5851

5952
return Response{
6053
Body: pipelines.CreatePipelineResponse{
@@ -63,6 +56,16 @@ func (s *FakeWorkspace) PipelineCreate(req Request) Response {
6356
}
6457
}
6558

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

@@ -82,10 +85,7 @@ func (s *FakeWorkspace) PipelineUpdate(req Request, pipelineId string) Response
8285
}
8386
}
8487

85-
spec.Id = pipelineId
86-
if spec.Storage == "" && spec.Catalog == "" {
87-
spec.Storage = "dbfs:/pipelines/" + pipelineId
88-
}
88+
setSpecDefaults(&spec, pipelineId)
8989

9090
item.Spec = &spec
9191
s.Pipelines[pipelineId] = item

0 commit comments

Comments
 (0)