@@ -14,6 +14,7 @@ import (
1414 "github.com/databricks/databricks-sdk-go/service/apps"
1515 "github.com/databricks/databricks-sdk-go/service/catalog"
1616 "github.com/databricks/databricks-sdk-go/service/dashboards"
17+ "github.com/databricks/databricks-sdk-go/service/iam"
1718 "github.com/databricks/databricks-sdk-go/service/jobs"
1819 "github.com/databricks/databricks-sdk-go/service/pipelines"
1920 "github.com/databricks/databricks-sdk-go/service/sql"
@@ -26,19 +27,33 @@ import (
2627// (encoding/json without options parses numbers into float64)
2728// These are also easier to spot / replace in test output compared to numbers with one or few digits.
2829const (
29- TestJobID = 4611686018427387911
30- TestRunID = 2305843009213693969
30+ TestJobID = 4611686018427387911
31+ TestRunID = 2305843009213693969
32+ UserNameTokenPrefix = "dbapi0"
33+ ServicePrincipalTokenPrefix = "dbapi1"
34+ UserID = "1000012345"
3135)
3236
37+ var TestUser = iam.User {
38+ Id : UserID ,
39+ 40+ }
41+
42+ var TestUserSP = iam.User {
43+ Id : UserID ,
44+ UserName : "e649126d-dc78-4e80-9c8d-86e6b3d2ffb3" ,
45+ }
46+
3347type FileEntry struct {
3448 Info workspace.ObjectInfo
3549 Data []byte
3650}
3751
3852// FakeWorkspace holds a state of a workspace for acceptance tests.
3953type FakeWorkspace struct {
40- mu sync.Mutex
41- url string
54+ mu sync.Mutex
55+ url string
56+ isServicePrincipal bool
4257
4358 directories map [string ]bool
4459 files map [string ]FileEntry
@@ -119,9 +134,10 @@ func MapDelete[K comparable, V any](w *FakeWorkspace, collection map[K]V, key K)
119134 return Response {}
120135}
121136
122- func NewFakeWorkspace (url string ) * FakeWorkspace {
137+ func NewFakeWorkspace (url , token string ) * FakeWorkspace {
123138 return & FakeWorkspace {
124- url : url ,
139+ url : url ,
140+ isServicePrincipal : strings .HasPrefix (token , ServicePrincipalTokenPrefix ),
125141 directories : map [string ]bool {
126142 "/Workspace" : true ,
127143 },
@@ -144,6 +160,14 @@ func NewFakeWorkspace(url string) *FakeWorkspace {
144160 }
145161}
146162
163+ func (s * FakeWorkspace ) CurrentUser () iam.User {
164+ if s != nil && s .isServicePrincipal {
165+ return TestUserSP
166+ } else {
167+ return TestUser
168+ }
169+ }
170+
147171func (s * FakeWorkspace ) WorkspaceGetStatus (path string ) Response {
148172 defer s .LockUnlock ()()
149173
0 commit comments