From 7a99df58ec399d8b7e601e3aeb081ee4567c064a Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Wed, 20 Nov 2024 22:46:07 +0100 Subject: [PATCH] No need for pointers to the lookup structs --- bundle/config/variable/lookup.go | 78 ++++++++++--------- bundle/config/variable/lookup_alert.go | 4 +- bundle/config/variable/lookup_alert_test.go | 6 +- bundle/config/variable/lookup_cluster.go | 4 +- .../config/variable/lookup_cluster_policy.go | 4 +- .../variable/lookup_cluster_policy_test.go | 6 +- bundle/config/variable/lookup_cluster_test.go | 6 +- bundle/config/variable/lookup_dashboard.go | 4 +- .../config/variable/lookup_dashboard_test.go | 6 +- .../config/variable/lookup_instance_pool.go | 4 +- .../variable/lookup_instance_pool_test.go | 6 +- bundle/config/variable/lookup_job.go | 4 +- bundle/config/variable/lookup_job_test.go | 6 +- bundle/config/variable/lookup_metastore.go | 4 +- .../config/variable/lookup_metastore_test.go | 6 +- bundle/config/variable/lookup_pipeline.go | 4 +- .../config/variable/lookup_pipeline_test.go | 6 +- bundle/config/variable/lookup_query.go | 4 +- bundle/config/variable/lookup_query_test.go | 6 +- .../variable/lookup_service_principal.go | 4 +- .../variable/lookup_service_principal_test.go | 6 +- bundle/config/variable/lookup_warehouse.go | 4 +- .../config/variable/lookup_warehouse_test.go | 6 +- 23 files changed, 95 insertions(+), 93 deletions(-) diff --git a/bundle/config/variable/lookup.go b/bundle/config/variable/lookup.go index 9f59103e9..39c1a6e83 100755 --- a/bundle/config/variable/lookup.go +++ b/bundle/config/variable/lookup.go @@ -4,6 +4,8 @@ package variable import ( "context" + "fmt" + "strings" "github.com/databricks/databricks-sdk-go" ) @@ -40,41 +42,41 @@ type Lookup struct { func (l *Lookup) constructResolver() (resolver, error) { -if l.Alert != "" { - return lookupAlert{name: l.Alert}, nil -} -if l.ClusterPolicy != "" { - return lookupClusterPolicy{name: l.ClusterPolicy}, nil -} -if l.Cluster != "" { - return lookupCluster{name: l.Cluster}, nil -} -if l.Dashboard != "" { - return lookupDashboard{name: l.Dashboard}, nil -} -if l.InstancePool != "" { - return lookupInstancePool{name: l.InstancePool}, nil -} -if l.Job != "" { - return lookupJob{name: l.Job}, nil -} -if l.Metastore != "" { - return lookupMetastore{name: l.Metastore}, nil -} -if l.Pipeline != "" { - return lookupPipeline{name: l.Pipeline}, nil -} -if l.Query != "" { - return lookupQuery{name: l.Query}, nil -} -if l.ServicePrincipal != "" { - return lookupServicePrincipal{name: l.ServicePrincipal}, nil -} -if l.Warehouse != "" { - return lookupWarehouse{name: l.Warehouse}, nil -} + if l.Alert != "" { + return lookupAlert{name: l.Alert}, nil + } + if l.ClusterPolicy != "" { + return lookupClusterPolicy{name: l.ClusterPolicy}, nil + } + if l.Cluster != "" { + return lookupCluster{name: l.Cluster}, nil + } + if l.Dashboard != "" { + return lookupDashboard{name: l.Dashboard}, nil + } + if l.InstancePool != "" { + return lookupInstancePool{name: l.InstancePool}, nil + } + if l.Job != "" { + return lookupJob{name: l.Job}, nil + } + if l.Metastore != "" { + return lookupMetastore{name: l.Metastore}, nil + } + if l.Pipeline != "" { + return lookupPipeline{name: l.Pipeline}, nil + } + if l.Query != "" { + return lookupQuery{name: l.Query}, nil + } + if l.ServicePrincipal != "" { + return lookupServicePrincipal{name: l.ServicePrincipal}, nil + } + if l.Warehouse != "" { + return lookupWarehouse{name: l.Warehouse}, nil + } -return nil, fmt.Errorf("no valid lookup fields provided") + return nil, fmt.Errorf("no valid lookup fields provided") } // func LookupFromMap(m map[string]any) *Lookup { @@ -160,10 +162,10 @@ return nil, fmt.Errorf("no valid lookup fields provided") // } func (l *Lookup) String() string { -r, _ := l.constructResolver() -if r != nil { - return r.String() -} + r, _ := l.constructResolver() + if r != nil { + return r.String() + } return "" } diff --git a/bundle/config/variable/lookup_alert.go b/bundle/config/variable/lookup_alert.go index 768e3b736..762e39a9e 100644 --- a/bundle/config/variable/lookup_alert.go +++ b/bundle/config/variable/lookup_alert.go @@ -11,7 +11,7 @@ type lookupAlert struct { name string } -func (l *lookupAlert) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { +func (l lookupAlert) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { entity, err := w.Alerts.GetByDisplayName(ctx, l.name) if err != nil { return "", err @@ -19,6 +19,6 @@ func (l *lookupAlert) Resolve(ctx context.Context, w *databricks.WorkspaceClient return fmt.Sprint(entity.Id), nil } -func (l *lookupAlert) String() string { +func (l lookupAlert) String() string { return fmt.Sprintf("alert: %s", l.name) } diff --git a/bundle/config/variable/lookup_alert_test.go b/bundle/config/variable/lookup_alert_test.go index 14a387824..593bc4a8e 100644 --- a/bundle/config/variable/lookup_alert_test.go +++ b/bundle/config/variable/lookup_alert_test.go @@ -23,7 +23,7 @@ func TestLookupAlert_ResolveSuccess(t *testing.T) { }, nil) ctx := context.Background() - l := &lookupAlert{name: "alert"} + l := lookupAlert{name: "alert"} result, err := l.Resolve(ctx, m.WorkspaceClient) require.NoError(t, err) assert.Equal(t, "1234", result) @@ -38,12 +38,12 @@ func TestLookupAlert_ResolveNotFound(t *testing.T) { Return(nil, &apierr.APIError{StatusCode: 404}) ctx := context.Background() - l := &lookupAlert{name: "alert"} + l := lookupAlert{name: "alert"} _, err := l.Resolve(ctx, m.WorkspaceClient) require.ErrorIs(t, err, apierr.ErrNotFound) } func TestLookupAlert_String(t *testing.T) { - l := &lookupAlert{name: "name"} + l := lookupAlert{name: "name"} assert.Equal(t, "alert: name", l.String()) } diff --git a/bundle/config/variable/lookup_cluster.go b/bundle/config/variable/lookup_cluster.go index 4081491ee..df336d2db 100644 --- a/bundle/config/variable/lookup_cluster.go +++ b/bundle/config/variable/lookup_cluster.go @@ -14,7 +14,7 @@ type lookupCluster struct { // We added a custom resolver for the cluster to add filtering for the cluster source when we list all clusters. // Without the filtering listing could take a very long time (5-10 mins) which leads to lookup timeouts. -func (l *lookupCluster) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { +func (l lookupCluster) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { result, err := w.Clusters.ListAll(ctx, compute.ListClustersRequest{ FilterBy: &compute.ListClustersFilterBy{ ClusterSources: []compute.ClusterSource{compute.ClusterSourceApi, compute.ClusterSourceUi}, @@ -42,6 +42,6 @@ func (l *lookupCluster) Resolve(ctx context.Context, w *databricks.WorkspaceClie return alternatives[0].ClusterId, nil } -func (l *lookupCluster) String() string { +func (l lookupCluster) String() string { return fmt.Sprintf("cluster: %s", l.name) } diff --git a/bundle/config/variable/lookup_cluster_policy.go b/bundle/config/variable/lookup_cluster_policy.go index 54eefd696..324a5cc4f 100644 --- a/bundle/config/variable/lookup_cluster_policy.go +++ b/bundle/config/variable/lookup_cluster_policy.go @@ -11,7 +11,7 @@ type lookupClusterPolicy struct { name string } -func (l *lookupClusterPolicy) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { +func (l lookupClusterPolicy) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { entity, err := w.ClusterPolicies.GetByName(ctx, l.name) if err != nil { return "", err @@ -19,6 +19,6 @@ func (l *lookupClusterPolicy) Resolve(ctx context.Context, w *databricks.Workspa return fmt.Sprint(entity.PolicyId), nil } -func (l *lookupClusterPolicy) String() string { +func (l lookupClusterPolicy) String() string { return fmt.Sprintf("cluster-policy: %s", l.name) } diff --git a/bundle/config/variable/lookup_cluster_policy_test.go b/bundle/config/variable/lookup_cluster_policy_test.go index 379fcff01..b9f7e8580 100644 --- a/bundle/config/variable/lookup_cluster_policy_test.go +++ b/bundle/config/variable/lookup_cluster_policy_test.go @@ -23,7 +23,7 @@ func TestLookupClusterPolicy_ResolveSuccess(t *testing.T) { }, nil) ctx := context.Background() - l := &lookupClusterPolicy{name: "policy"} + l := lookupClusterPolicy{name: "policy"} result, err := l.Resolve(ctx, m.WorkspaceClient) require.NoError(t, err) assert.Equal(t, "1234", result) @@ -38,12 +38,12 @@ func TestLookupClusterPolicy_ResolveNotFound(t *testing.T) { Return(nil, &apierr.APIError{StatusCode: 404}) ctx := context.Background() - l := &lookupClusterPolicy{name: "policy"} + l := lookupClusterPolicy{name: "policy"} _, err := l.Resolve(ctx, m.WorkspaceClient) require.ErrorIs(t, err, apierr.ErrNotFound) } func TestLookupClusterPolicy_String(t *testing.T) { - l := &lookupClusterPolicy{name: "name"} + l := lookupClusterPolicy{name: "name"} assert.Equal(t, "cluster-policy: name", l.String()) } diff --git a/bundle/config/variable/lookup_cluster_test.go b/bundle/config/variable/lookup_cluster_test.go index 5629eacc3..4440dcda1 100644 --- a/bundle/config/variable/lookup_cluster_test.go +++ b/bundle/config/variable/lookup_cluster_test.go @@ -23,7 +23,7 @@ func TestLookupCluster_ResolveSuccess(t *testing.T) { }, nil) ctx := context.Background() - l := &lookupCluster{name: "cluster2"} + l := lookupCluster{name: "cluster2"} result, err := l.Resolve(ctx, m.WorkspaceClient) require.NoError(t, err) assert.Equal(t, "2345", result) @@ -38,13 +38,13 @@ func TestLookupCluster_ResolveNotFound(t *testing.T) { Return([]compute.ClusterDetails{}, nil) ctx := context.Background() - l := &lookupCluster{name: "cluster"} + l := lookupCluster{name: "cluster"} _, err := l.Resolve(ctx, m.WorkspaceClient) require.Error(t, err) assert.Contains(t, err.Error(), "cluster named 'cluster' does not exist") } func TestLookupCluster_String(t *testing.T) { - l := &lookupCluster{name: "name"} + l := lookupCluster{name: "name"} assert.Equal(t, "cluster: name", l.String()) } diff --git a/bundle/config/variable/lookup_dashboard.go b/bundle/config/variable/lookup_dashboard.go index c43e4cc03..604cc900b 100644 --- a/bundle/config/variable/lookup_dashboard.go +++ b/bundle/config/variable/lookup_dashboard.go @@ -11,7 +11,7 @@ type lookupDashboard struct { name string } -func (l *lookupDashboard) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { +func (l lookupDashboard) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { entity, err := w.Dashboards.GetByName(ctx, l.name) if err != nil { return "", err @@ -19,6 +19,6 @@ func (l *lookupDashboard) Resolve(ctx context.Context, w *databricks.WorkspaceCl return fmt.Sprint(entity.Id), nil } -func (l *lookupDashboard) String() string { +func (l lookupDashboard) String() string { return fmt.Sprintf("dashboard: %s", l.name) } diff --git a/bundle/config/variable/lookup_dashboard_test.go b/bundle/config/variable/lookup_dashboard_test.go index 1d9cc2b8a..45babdf95 100644 --- a/bundle/config/variable/lookup_dashboard_test.go +++ b/bundle/config/variable/lookup_dashboard_test.go @@ -23,7 +23,7 @@ func TestLookupDashboard_ResolveSuccess(t *testing.T) { }, nil) ctx := context.Background() - l := &lookupDashboard{name: "dashboard"} + l := lookupDashboard{name: "dashboard"} result, err := l.Resolve(ctx, m.WorkspaceClient) require.NoError(t, err) assert.Equal(t, "1234", result) @@ -38,12 +38,12 @@ func TestLookupDashboard_ResolveNotFound(t *testing.T) { Return(nil, &apierr.APIError{StatusCode: 404}) ctx := context.Background() - l := &lookupDashboard{name: "dashboard"} + l := lookupDashboard{name: "dashboard"} _, err := l.Resolve(ctx, m.WorkspaceClient) require.ErrorIs(t, err, apierr.ErrNotFound) } func TestLookupDashboard_String(t *testing.T) { - l := &lookupDashboard{name: "name"} + l := lookupDashboard{name: "name"} assert.Equal(t, "dashboard: name", l.String()) } diff --git a/bundle/config/variable/lookup_instance_pool.go b/bundle/config/variable/lookup_instance_pool.go index f567d3451..ff9499d88 100644 --- a/bundle/config/variable/lookup_instance_pool.go +++ b/bundle/config/variable/lookup_instance_pool.go @@ -11,7 +11,7 @@ type lookupInstancePool struct { name string } -func (l *lookupInstancePool) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { +func (l lookupInstancePool) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { entity, err := w.InstancePools.GetByInstancePoolName(ctx, l.name) if err != nil { return "", err @@ -19,6 +19,6 @@ func (l *lookupInstancePool) Resolve(ctx context.Context, w *databricks.Workspac return fmt.Sprint(entity.InstancePoolId), nil } -func (l *lookupInstancePool) String() string { +func (l lookupInstancePool) String() string { return fmt.Sprintf("instance-pool: %s", l.name) } diff --git a/bundle/config/variable/lookup_instance_pool_test.go b/bundle/config/variable/lookup_instance_pool_test.go index cafb39323..84f3a3c54 100644 --- a/bundle/config/variable/lookup_instance_pool_test.go +++ b/bundle/config/variable/lookup_instance_pool_test.go @@ -23,7 +23,7 @@ func TestLookupInstancePool_ResolveSuccess(t *testing.T) { }, nil) ctx := context.Background() - l := &lookupInstancePool{name: "instance_pool"} + l := lookupInstancePool{name: "instance_pool"} result, err := l.Resolve(ctx, m.WorkspaceClient) require.NoError(t, err) assert.Equal(t, "5678", result) @@ -38,12 +38,12 @@ func TestLookupInstancePool_ResolveNotFound(t *testing.T) { Return(nil, &apierr.APIError{StatusCode: 404}) ctx := context.Background() - l := &lookupInstancePool{name: "instance_pool"} + l := lookupInstancePool{name: "instance_pool"} _, err := l.Resolve(ctx, m.WorkspaceClient) require.ErrorIs(t, err, apierr.ErrNotFound) } func TestLookupInstancePool_String(t *testing.T) { - l := &lookupInstancePool{name: "name"} + l := lookupInstancePool{name: "name"} assert.Equal(t, "instance-pool: name", l.String()) } diff --git a/bundle/config/variable/lookup_job.go b/bundle/config/variable/lookup_job.go index dbf1e9da9..5893e3f0e 100644 --- a/bundle/config/variable/lookup_job.go +++ b/bundle/config/variable/lookup_job.go @@ -11,7 +11,7 @@ type lookupJob struct { name string } -func (l *lookupJob) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { +func (l lookupJob) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { entity, err := w.Jobs.GetBySettingsName(ctx, l.name) if err != nil { return "", err @@ -19,6 +19,6 @@ func (l *lookupJob) Resolve(ctx context.Context, w *databricks.WorkspaceClient) return fmt.Sprint(entity.JobId), nil } -func (l *lookupJob) String() string { +func (l lookupJob) String() string { return fmt.Sprintf("job: %s", l.name) } diff --git a/bundle/config/variable/lookup_job_test.go b/bundle/config/variable/lookup_job_test.go index 442b4f214..7d371ca6c 100644 --- a/bundle/config/variable/lookup_job_test.go +++ b/bundle/config/variable/lookup_job_test.go @@ -23,7 +23,7 @@ func TestLookupJob_ResolveSuccess(t *testing.T) { }, nil) ctx := context.Background() - l := &lookupJob{name: "job"} + l := lookupJob{name: "job"} result, err := l.Resolve(ctx, m.WorkspaceClient) require.NoError(t, err) assert.Equal(t, "5678", result) @@ -38,12 +38,12 @@ func TestLookupJob_ResolveNotFound(t *testing.T) { Return(nil, &apierr.APIError{StatusCode: 404}) ctx := context.Background() - l := &lookupJob{name: "job"} + l := lookupJob{name: "job"} _, err := l.Resolve(ctx, m.WorkspaceClient) require.ErrorIs(t, err, apierr.ErrNotFound) } func TestLookupJob_String(t *testing.T) { - l := &lookupJob{name: "name"} + l := lookupJob{name: "name"} assert.Equal(t, "job: name", l.String()) } diff --git a/bundle/config/variable/lookup_metastore.go b/bundle/config/variable/lookup_metastore.go index 3be6368d6..96d738793 100644 --- a/bundle/config/variable/lookup_metastore.go +++ b/bundle/config/variable/lookup_metastore.go @@ -11,7 +11,7 @@ type lookupMetastore struct { name string } -func (l *lookupMetastore) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { +func (l lookupMetastore) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { entity, err := w.Metastores.GetByName(ctx, l.name) if err != nil { return "", err @@ -19,6 +19,6 @@ func (l *lookupMetastore) Resolve(ctx context.Context, w *databricks.WorkspaceCl return fmt.Sprint(entity.MetastoreId), nil } -func (l *lookupMetastore) String() string { +func (l lookupMetastore) String() string { return fmt.Sprintf("metastore: %s", l.name) } diff --git a/bundle/config/variable/lookup_metastore_test.go b/bundle/config/variable/lookup_metastore_test.go index b25a647be..69c269021 100644 --- a/bundle/config/variable/lookup_metastore_test.go +++ b/bundle/config/variable/lookup_metastore_test.go @@ -23,7 +23,7 @@ func TestLookupMetastore_ResolveSuccess(t *testing.T) { }, nil) ctx := context.Background() - l := &lookupMetastore{name: "metastore"} + l := lookupMetastore{name: "metastore"} result, err := l.Resolve(ctx, m.WorkspaceClient) require.NoError(t, err) assert.Equal(t, "abcd", result) @@ -38,12 +38,12 @@ func TestLookupMetastore_ResolveNotFound(t *testing.T) { Return(nil, &apierr.APIError{StatusCode: 404}) ctx := context.Background() - l := &lookupMetastore{name: "metastore"} + l := lookupMetastore{name: "metastore"} _, err := l.Resolve(ctx, m.WorkspaceClient) require.ErrorIs(t, err, apierr.ErrNotFound) } func TestLookupMetastore_String(t *testing.T) { - l := &lookupMetastore{name: "name"} + l := lookupMetastore{name: "name"} assert.Equal(t, "metastore: name", l.String()) } diff --git a/bundle/config/variable/lookup_pipeline.go b/bundle/config/variable/lookup_pipeline.go index 1141e2486..0705a6d9c 100644 --- a/bundle/config/variable/lookup_pipeline.go +++ b/bundle/config/variable/lookup_pipeline.go @@ -11,7 +11,7 @@ type lookupPipeline struct { name string } -func (l *lookupPipeline) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { +func (l lookupPipeline) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { entity, err := w.Pipelines.GetByName(ctx, l.name) if err != nil { return "", err @@ -19,6 +19,6 @@ func (l *lookupPipeline) Resolve(ctx context.Context, w *databricks.WorkspaceCli return fmt.Sprint(entity.PipelineId), nil } -func (l *lookupPipeline) String() string { +func (l lookupPipeline) String() string { return fmt.Sprintf("pipeline: %s", l.name) } diff --git a/bundle/config/variable/lookup_pipeline_test.go b/bundle/config/variable/lookup_pipeline_test.go index 0c35b1862..0b6b9b3c3 100644 --- a/bundle/config/variable/lookup_pipeline_test.go +++ b/bundle/config/variable/lookup_pipeline_test.go @@ -23,7 +23,7 @@ func TestLookupPipeline_ResolveSuccess(t *testing.T) { }, nil) ctx := context.Background() - l := &lookupPipeline{name: "pipeline"} + l := lookupPipeline{name: "pipeline"} result, err := l.Resolve(ctx, m.WorkspaceClient) require.NoError(t, err) assert.Equal(t, "abcd", result) @@ -38,12 +38,12 @@ func TestLookupPipeline_ResolveNotFound(t *testing.T) { Return(nil, &apierr.APIError{StatusCode: 404}) ctx := context.Background() - l := &lookupPipeline{name: "pipeline"} + l := lookupPipeline{name: "pipeline"} _, err := l.Resolve(ctx, m.WorkspaceClient) require.ErrorIs(t, err, apierr.ErrNotFound) } func TestLookupPipeline_String(t *testing.T) { - l := &lookupPipeline{name: "name"} + l := lookupPipeline{name: "name"} assert.Equal(t, "pipeline: name", l.String()) } diff --git a/bundle/config/variable/lookup_query.go b/bundle/config/variable/lookup_query.go index cc1d8133f..1bbb55861 100644 --- a/bundle/config/variable/lookup_query.go +++ b/bundle/config/variable/lookup_query.go @@ -11,7 +11,7 @@ type lookupQuery struct { name string } -func (l *lookupQuery) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { +func (l lookupQuery) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { entity, err := w.Queries.GetByDisplayName(ctx, l.name) if err != nil { return "", err @@ -19,6 +19,6 @@ func (l *lookupQuery) Resolve(ctx context.Context, w *databricks.WorkspaceClient return fmt.Sprint(entity.Id), nil } -func (l *lookupQuery) String() string { +func (l lookupQuery) String() string { return fmt.Sprintf("query: %s", l.name) } diff --git a/bundle/config/variable/lookup_query_test.go b/bundle/config/variable/lookup_query_test.go index 7eacd9752..370fa32e1 100644 --- a/bundle/config/variable/lookup_query_test.go +++ b/bundle/config/variable/lookup_query_test.go @@ -23,7 +23,7 @@ func TestLookupQuery_ResolveSuccess(t *testing.T) { }, nil) ctx := context.Background() - l := &lookupQuery{name: "query"} + l := lookupQuery{name: "query"} result, err := l.Resolve(ctx, m.WorkspaceClient) require.NoError(t, err) assert.Equal(t, "1234", result) @@ -38,12 +38,12 @@ func TestLookupQuery_ResolveNotFound(t *testing.T) { Return(nil, &apierr.APIError{StatusCode: 404}) ctx := context.Background() - l := &lookupQuery{name: "query"} + l := lookupQuery{name: "query"} _, err := l.Resolve(ctx, m.WorkspaceClient) require.ErrorIs(t, err, apierr.ErrNotFound) } func TestLookupQuery_String(t *testing.T) { - l := &lookupQuery{name: "name"} + l := lookupQuery{name: "name"} assert.Equal(t, "query: name", l.String()) } diff --git a/bundle/config/variable/lookup_service_principal.go b/bundle/config/variable/lookup_service_principal.go index c9d4d3768..0ee2281ea 100644 --- a/bundle/config/variable/lookup_service_principal.go +++ b/bundle/config/variable/lookup_service_principal.go @@ -11,7 +11,7 @@ type lookupServicePrincipal struct { name string } -func (l *lookupServicePrincipal) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { +func (l lookupServicePrincipal) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { entity, err := w.ServicePrincipals.GetByDisplayName(ctx, l.name) if err != nil { return "", err @@ -19,6 +19,6 @@ func (l *lookupServicePrincipal) Resolve(ctx context.Context, w *databricks.Work return fmt.Sprint(entity.ApplicationId), nil } -func (l *lookupServicePrincipal) String() string { +func (l lookupServicePrincipal) String() string { return fmt.Sprintf("service-principal: %s", l.name) } diff --git a/bundle/config/variable/lookup_service_principal_test.go b/bundle/config/variable/lookup_service_principal_test.go index 6e8b34a44..992d31f61 100644 --- a/bundle/config/variable/lookup_service_principal_test.go +++ b/bundle/config/variable/lookup_service_principal_test.go @@ -23,7 +23,7 @@ func TestLookupServicePrincipal_ResolveSuccess(t *testing.T) { }, nil) ctx := context.Background() - l := &lookupServicePrincipal{name: "service-principal"} + l := lookupServicePrincipal{name: "service-principal"} result, err := l.Resolve(ctx, m.WorkspaceClient) require.NoError(t, err) assert.Equal(t, "5678", result) @@ -38,12 +38,12 @@ func TestLookupServicePrincipal_ResolveNotFound(t *testing.T) { Return(nil, &apierr.APIError{StatusCode: 404}) ctx := context.Background() - l := &lookupServicePrincipal{name: "service-principal"} + l := lookupServicePrincipal{name: "service-principal"} _, err := l.Resolve(ctx, m.WorkspaceClient) require.ErrorIs(t, err, apierr.ErrNotFound) } func TestLookupServicePrincipal_String(t *testing.T) { - l := &lookupServicePrincipal{name: "name"} + l := lookupServicePrincipal{name: "name"} assert.Equal(t, "service-principal: name", l.String()) } diff --git a/bundle/config/variable/lookup_warehouse.go b/bundle/config/variable/lookup_warehouse.go index 90199ec61..c194e5cd2 100644 --- a/bundle/config/variable/lookup_warehouse.go +++ b/bundle/config/variable/lookup_warehouse.go @@ -11,7 +11,7 @@ type lookupWarehouse struct { name string } -func (l *lookupWarehouse) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { +func (l lookupWarehouse) Resolve(ctx context.Context, w *databricks.WorkspaceClient) (string, error) { entity, err := w.Warehouses.GetByName(ctx, l.name) if err != nil { return "", err @@ -19,6 +19,6 @@ func (l *lookupWarehouse) Resolve(ctx context.Context, w *databricks.WorkspaceCl return fmt.Sprint(entity.Id), nil } -func (l *lookupWarehouse) String() string { +func (l lookupWarehouse) String() string { return fmt.Sprintf("warehouse: %s", l.name) } diff --git a/bundle/config/variable/lookup_warehouse_test.go b/bundle/config/variable/lookup_warehouse_test.go index 20a535cc9..086d8383a 100644 --- a/bundle/config/variable/lookup_warehouse_test.go +++ b/bundle/config/variable/lookup_warehouse_test.go @@ -23,7 +23,7 @@ func TestLookupWarehouse_ResolveSuccess(t *testing.T) { }, nil) ctx := context.Background() - l := &lookupWarehouse{name: "warehouse"} + l := lookupWarehouse{name: "warehouse"} result, err := l.Resolve(ctx, m.WorkspaceClient) require.NoError(t, err) assert.Equal(t, "abcd", result) @@ -38,12 +38,12 @@ func TestLookupWarehouse_ResolveNotFound(t *testing.T) { Return(nil, &apierr.APIError{StatusCode: 404}) ctx := context.Background() - l := &lookupWarehouse{name: "warehouse"} + l := lookupWarehouse{name: "warehouse"} _, err := l.Resolve(ctx, m.WorkspaceClient) require.ErrorIs(t, err, apierr.ErrNotFound) } func TestLookupWarehouse_String(t *testing.T) { - l := &lookupWarehouse{name: "name"} + l := lookupWarehouse{name: "name"} assert.Equal(t, "warehouse: name", l.String()) }