Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmay-db committed Aug 26, 2024
1 parent feee667 commit d4a9ac6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
20 changes: 10 additions & 10 deletions internal/providers/common/tests/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func TestConfig_PatFromDatabricksCfg(t *testing.T) {
providerFixture{
// loading with DEFAULT profile in databrickscfs
env: map[string]string{
"HOME": "../../../common/testdata",
"HOME": getTestDataPath(),
},
assertHost: "https://dbc-XXXXXXXX-YYYY.cloud.databricks.com",
assertAuth: "pat",
Expand All @@ -191,7 +191,7 @@ func TestConfig_PatFromDatabricksCfg_NohostProfile(t *testing.T) {
providerFixture{
// loading with nohost profile in databrickscfs
env: map[string]string{
"HOME": "../../../common/testdata",
"HOME": getTestDataPath(),
"DATABRICKS_CONFIG_PROFILE": "nohost",
},
assertError: common.NoAuth +
Expand All @@ -204,7 +204,7 @@ func TestConfig_ConfigProfileAndToken(t *testing.T) {
env: map[string]string{
"DATABRICKS_TOKEN": "x",
"DATABRICKS_CONFIG_PROFILE": "nohost",
"HOME": "../../../common/testdata",
"HOME": getTestDataPath(),
},
assertError: common.NoAuth +
". Config: token=***, profile=nohost. Env: DATABRICKS_TOKEN, DATABRICKS_CONFIG_PROFILE",
Expand All @@ -216,7 +216,7 @@ func TestConfig_ConfigProfileAndPassword(t *testing.T) {
env: map[string]string{
"DATABRICKS_USERNAME": "x",
"DATABRICKS_CONFIG_PROFILE": "nohost",
"HOME": "../../../common/testdata",
"HOME": getTestDataPath(),
},
assertError: "validate: more than one authorization method configured: basic and pat. " +
"Config: token=***, username=x, profile=nohost. Env: DATABRICKS_USERNAME, DATABRICKS_CONFIG_PROFILE",
Expand All @@ -226,7 +226,7 @@ func TestConfig_ConfigProfileAndPassword(t *testing.T) {
var azResourceID = "/subscriptions/a/resourceGroups/b/providers/Microsoft.Databricks/workspaces/c"

func TestConfig_AzureCliHost(t *testing.T) {
p, _ := filepath.Abs("../../../common/testdata")
p, _ := filepath.Abs(getTestDataPath())
providerFixture{
// this test will skip ensureWorkspaceUrl
host: "x",
Expand All @@ -244,7 +244,7 @@ func TestConfig_AzureCliHost(t *testing.T) {
}

func TestConfig_AzureCliHost_Fail(t *testing.T) {
p, _ := filepath.Abs("../../../common/testdata")
p, _ := filepath.Abs(getTestDataPath())
providerFixture{
azureResourceID: azResourceID,
env: map[string]string{
Expand All @@ -270,7 +270,7 @@ func TestConfig_AzureCliHost_AzNotInstalled(t *testing.T) {
}

func TestConfig_AzureCliHost_PatConflict(t *testing.T) {
p, _ := filepath.Abs("../../../common/testdata")
p, _ := filepath.Abs(getTestDataPath())
providerFixture{
azureResourceID: azResourceID,
token: "x",
Expand All @@ -284,7 +284,7 @@ func TestConfig_AzureCliHost_PatConflict(t *testing.T) {
}

func TestConfig_AzureCliHostAndResourceID(t *testing.T) {
p, _ := filepath.Abs("../../../common/testdata")
p, _ := filepath.Abs(getTestDataPath())
providerFixture{
// omit request to management endpoint to get workspace properties
azureResourceID: azResourceID,
Expand All @@ -302,7 +302,7 @@ func TestConfig_AzureCliHostAndResourceID(t *testing.T) {
}

func TestConfig_AzureAndPasswordConflict(t *testing.T) {
p, _ := filepath.Abs("../../../common/testdata")
p, _ := filepath.Abs(getTestDataPath())
providerFixture{
host: "x",
azureResourceID: azResourceID,
Expand All @@ -319,7 +319,7 @@ func TestConfig_AzureAndPasswordConflict(t *testing.T) {
func TestConfig_CorruptConfig(t *testing.T) {
providerFixture{
env: map[string]string{
"HOME": "../../../common/testdata/corrupt",
"HOME": getTestDataPath() + "/corrupt",
},
assertError: common.NoAuth,
}.apply(t)
Expand Down
4 changes: 4 additions & 0 deletions internal/providers/common/tests/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ type providerFixture struct {
assertAzure bool
}

func getTestDataPath() string {
return "../../../../common/testdata"
}

func (pf providerFixture) rawConfig() map[string]string {
rawConfig := map[string]string{}
if pf.host != "" {
Expand Down

0 comments on commit d4a9ac6

Please sign in to comment.