-
Notifications
You must be signed in to change notification settings - Fork 401
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Internal] Support adding context in resources and data sources (#4085)
## Changes <!-- Summary of your changes that are easy to understand --> Set `resource` and `data` context for each resource in their respective CRUD operations. Two methods are defined to make setting resources / datasources as default easier: `GetDatabricksProductionName` and `GetDatabricksStagingName`. Note: Library update isn't supported and hence we shouldn't inject useragent there. Every resource has: ````` ctx = pluginfwcommon.SetResourceNameInContext(ctx, resourceName) w, diags := r.Client.GetWorkspaceClient() resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { return } ````` We could avoid the repetition by creating a common base struct but since this is going to be autogenerated soon, I think it's fine to have these as is due to return statements / clarity of reading the code. ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> Unit tests - [ ] `make test` run locally - [ ] relevant change in `docs/` folder - [ ] covered with integration tests in `internal/acceptance` - [ ] relevant acceptance tests are passing - [ ] using Go SDK
- Loading branch information
Showing
8 changed files
with
97 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package common | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetDatabricksStagingName(t *testing.T) { | ||
resourceName := "test" | ||
expected := "databricks_test_pluginframework" | ||
result := GetDatabricksStagingName(resourceName) | ||
assert.Equal(t, expected, result, "GetDatabricksStagingName should return the expected staging name") | ||
} | ||
|
||
func TestGetDatabricksProductionName(t *testing.T) { | ||
resourceName := "test" | ||
expected := "databricks_test" | ||
result := GetDatabricksProductionName(resourceName) | ||
assert.Equal(t, expected, result, "GetDatabricksProductionName should return the expected production name") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package common | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/databricks/databricks-sdk-go/useragent" | ||
) | ||
|
||
func SetResourceNameInContext(ctx context.Context, resourceName string) context.Context { | ||
return useragent.InContext(ctx, "resource", resourceName) | ||
} | ||
|
||
func SetDataSourceNameInContext(ctx context.Context, dataSourceName string) context.Context { | ||
return useragent.InContext(ctx, "data", dataSourceName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package common | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/databricks/databricks-sdk-go/useragent" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSetResourceNameInContext(t *testing.T) { | ||
ctx := context.Background() | ||
resourceKey := "resource" | ||
resourceName := "test-resource" | ||
actualContext := SetResourceNameInContext(ctx, resourceName) | ||
expectedContext := useragent.InContext(ctx, resourceKey, resourceName) | ||
assert.Equal(t, expectedContext, actualContext) | ||
} | ||
|
||
func TestSetDataSourceNameInContext(t *testing.T) { | ||
ctx := context.Background() | ||
dataSourceKey := "data" | ||
dataSourceName := "test-datasource" | ||
actualContext := SetDataSourceNameInContext(ctx, dataSourceName) | ||
expectedContext := useragent.InContext(ctx, dataSourceKey, dataSourceName) | ||
assert.Equal(t, expectedContext, actualContext) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters