databricks-cli/cmd/auth/logout_test.go

63 lines
1.6 KiB
Go
Raw Normal View History

2024-08-25 21:53:44 +00:00
package auth
import (
"context"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
2024-09-01 22:15:48 +00:00
"github.com/databricks/cli/libs/auth"
2024-08-25 21:53:44 +00:00
"github.com/databricks/cli/libs/databrickscfg"
"github.com/databricks/databricks-sdk-go/config"
)
2024-09-01 22:15:48 +00:00
func TestLogout_setHostAndAccountIdFromProfile(t *testing.T) {
ctx := context.Background()
path := filepath.Join(t.TempDir(), "databrickscfg")
err := databrickscfg.SaveToProfile(ctx, &config.Config{
ConfigFile: path,
Profile: "abc",
Host: "https://foo",
Token: "xyz",
})
require.NoError(t, err)
iniFile, err := config.LoadFile(path)
require.NoError(t, err)
2024-09-23 18:37:53 +00:00
logout := &logoutSession{
profile: "abc",
file: *iniFile,
persistentAuth: &auth.PersistentAuth{},
2024-09-01 22:15:48 +00:00
}
err = logout.setHostAndAccountIdFromProfile()
assert.NoError(t, err)
2024-09-23 18:37:53 +00:00
assert.Equal(t, logout.persistentAuth.Host, "https://foo")
assert.Empty(t, logout.persistentAuth.AccountID)
2024-09-01 22:15:48 +00:00
}
func TestLogout_getConfigSectionMap(t *testing.T) {
ctx := context.Background()
path := filepath.Join(t.TempDir(), "databrickscfg")
err := databrickscfg.SaveToProfile(ctx, &config.Config{
ConfigFile: path,
Profile: "abc",
Host: "https://foo",
Token: "xyz",
})
require.NoError(t, err)
iniFile, err := config.LoadFile(path)
require.NoError(t, err)
2024-09-23 18:37:53 +00:00
logout := &logoutSession{
profile: "abc",
file: *iniFile,
persistentAuth: &auth.PersistentAuth{},
2024-09-01 22:15:48 +00:00
}
configSectionMap, err := logout.getConfigSectionMap()
assert.NoError(t, err)
assert.Equal(t, configSectionMap["host"], "https://foo")
assert.Equal(t, configSectionMap["token"], "xyz")
}