Skip to content

Commit

Permalink
improving test coverage & emit user/sp for repos
Browse files Browse the repository at this point in the history
  • Loading branch information
alexott committed Jan 2, 2023
1 parent ac3f1fa commit 2fbc1f7
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
47 changes: 46 additions & 1 deletion exporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,51 @@ func TestImportingDLTPipelines(t *testing.T) {
},
},
},
{
Method: "GET",
Resource: "/api/2.0/permissions/repos/123",
Response: getJSONObject("test-data/get-repo-permissions.json"),
},
{
Method: "GET",
Resource: "/api/2.0/workspace/get-status?path=%2FRepos%2Fuser%40domain.com%2Frepo",
Response: workspace.ObjectStatus{
ObjectID: 123,
ObjectType: "REPO",
Path: "/Repos/user@domain.com/repo",
},
},
{
Method: "GET",
Resource: "/api/2.0/repos/123",
Response: repos.ReposInformation{
ID: 123,
Url: "https://github.com/user/test.git",
Provider: "gitHub",
Path: "/Repos/user@domain.com/repo",
HeadCommitID: "1124323423abc23424",
Branch: "releases",
},
ReuseRequest: true,
},
{
Method: "GET",
Resource: "/api/2.0/preview/scim/v2/Users?filter=userName%20eq%20%27user%40domain.com%27",
Response: scim.UserList{
Resources: []scim.User{
{ID: "123", DisplayName: "user@domain.com", UserName: "user@domain.com"},
},
StartIndex: 1,
TotalResults: 1,
ItemsPerPage: 1,
},
ReuseRequest: true,
},
{
Method: "GET",
Resource: "/api/2.0/preview/scim/v2/Users/123",
Response: scim.User{ID: "123", DisplayName: "user@domain.com", UserName: "user@domain.com"},
},
{
Method: "GET",
Resource: "/api/2.0/pipelines/123",
Expand Down Expand Up @@ -1573,7 +1618,7 @@ func TestImportingDLTPipelines(t *testing.T) {
ic := newImportContext(client)
ic.Directory = tmpDir
ic.listing = "dlt"
ic.services = "dlt,access,notebooks"
ic.services = "dlt,access,notebooks,users,repos"

err := ic.Run()
assert.NoError(t, err)
Expand Down
12 changes: 12 additions & 0 deletions exporter/importables.go
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ var resourcesMap map[string]importable = map[string]importable{
return nil
},
Import: func(ic *importContext, r *resource) error {
ic.emitUserOrServicePrincipalForPath(r.Data.Get("path").(string), "/Repos")
if ic.meAdmin {
ic.Emit(&resource{
Resource: "databricks_permissions",
Expand All @@ -996,6 +997,17 @@ var resourcesMap map[string]importable = map[string]importable{
}
return nil
},
ShouldOmitField: func(ic *importContext, pathString string, as *schema.Schema, d *schema.ResourceData) bool {
if pathString == "path" {
return false
}
return defaultShouldOmitFieldFunc(ic, pathString, as, d)
},

Depends: []reference{
{Path: "path", Resource: "databricks_user", Match: "repos", MatchType: "prefix"},
{Path: "path", Resource: "databricks_service_principal", Match: "repos", MatchType: "prefix"},
},
},
"databricks_workspace_conf": {
Service: "workspace",
Expand Down
5 changes: 5 additions & 0 deletions exporter/test-data/get-dlt-pipeline.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
"notebook": {
"path": "/Users/user@domain.com/Test DLT"
}
},
{
"notebook": {
"path": "/Repos/user@domain.com/repo/Test DLT"
}
}
],
"name": "Test DLT",
Expand Down

0 comments on commit 2fbc1f7

Please sign in to comment.