Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-jy committed Sep 27, 2024
1 parent cf175f1 commit cdc9031
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions connection_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ import (
)

const (
snowflake_connectionName = "SNOWFLAKE_DEFAULT_CONNECTION_NAME"
snowflake_home = "SNOWFLAKE_HOME"
snowflakeConnectionName = "SNOWFLAKE_DEFAULT_CONNECTION_NAME"
snowflakeHome = "SNOWFLAKE_HOME"
)

// LoadConnectionConfig returns connection configs loaded from the toml file.
// By default, SNOWFLAKE_HOME(toml file path) is os.snowflake_home/.snowflake
// By default, SNOWFLAKE_HOME(toml file path) is os.snowflakeHome/.snowflake
// and SNOWFLAKE_DEFAULT_CONNECTION_NAME(DSN) is 'default'
func LoadConnectionConfig() (*Config, error) {
cfg := &Config{
Params: make(map[string]*string),
Authenticator: AuthTypeSnowflake, // Default to snowflake
}
dsn := getConnectionDSN(os.Getenv(snowflake_connectionName))
snowflakeConfigDir, err := getTomlFilePath(os.Getenv(snowflake_home))
dsn := getConnectionDSN(os.Getenv(snowflakeConnectionName))
snowflakeConfigDir, err := getTomlFilePath(os.Getenv(snowflakeHome))
if err != nil {
return nil, err
}

Check warning on line 34 in connection_configuration.go

View check run for this annotation

Codecov / codecov/patch

connection_configuration.go#L33-L34

Added lines #L33 - L34 were not covered by tests
Expand Down Expand Up @@ -257,7 +257,7 @@ func readToken(tokenPath string) (string, error) {
tokenPath = "./snowflake/session/token"
}
if !path.IsAbs(tokenPath) {
snowflakeConfigDir, err := getTomlFilePath(os.Getenv(snowflake_home))
snowflakeConfigDir, err := getTomlFilePath(os.Getenv(snowflakeHome))
if err != nil {
return "", err
}

Check warning on line 263 in connection_configuration.go

View check run for this annotation

Codecov / codecov/patch

connection_configuration.go#L262-L263

Added lines #L262 - L263 were not covered by tests
Expand Down
24 changes: 12 additions & 12 deletions connection_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestLoadConnectionConfig_Default(t *testing.T) {
err := os.Chmod("./test_data/connections.toml", 0600)
assertNilF(t, err, "The error occurred because you cannot change the file permission")

os.Setenv(snowflake_home, "./test_data")
os.Setenv(snowflakeHome, "./test_data")

cfg, err := LoadConnectionConfig()
assertNilF(t, err, "The error should not occur")
Expand All @@ -37,8 +37,8 @@ func TestLoadConnectionConfig_OAuth(t *testing.T) {
err := os.Chmod("./test_data/connections.toml", 0600)
assertNilF(t, err, "The error occurred because you cannot change the file permission")

os.Setenv(snowflake_home, "./test_data")
os.Setenv(snowflake_connectionName, "aws-oauth")
os.Setenv(snowflakeHome, "./test_data")
os.Setenv(snowflakeConnectionName, "aws-oauth")

cfg, err := LoadConnectionConfig()
assertNilF(t, err, "The error should not occur")
Expand All @@ -61,16 +61,16 @@ func TestReadTokenValueWithTokenFilePath(t *testing.T) {
err = os.Chmod("./test_data/snowflake/session/token", 0600)
assertNilF(t, err, "The error occurred because you cannot change the file permission")

os.Setenv(snowflake_home, "./test_data")
os.Setenv(snowflake_connectionName, "no-token-path")
os.Setenv(snowflakeHome, "./test_data")
os.Setenv(snowflakeConnectionName, "no-token-path")

cfg, err := LoadConnectionConfig()
assertNilF(t, err, "The error should not occur")
assertEqualF(t, cfg.Authenticator, AuthTypeOAuth)
assertEqualF(t, cfg.Token, "mock_token123456")

os.Setenv(snowflake_home, "./test_data")
os.Setenv(snowflake_connectionName, "read-token")
os.Setenv(snowflakeHome, "./test_data")
os.Setenv(snowflakeConnectionName, "read-token")

cfg, err = LoadConnectionConfig()
assertNilF(t, err, "The error should not occur")
Expand All @@ -82,8 +82,8 @@ func TestLoadConnectionConfigWitNonExistingDSN(t *testing.T) {
err := os.Chmod("./test_data/connections.toml", 0600)
assertNilF(t, err, "The error occurred because you cannot change the file permission")

os.Setenv(snowflake_home, "./test_data")
os.Setenv(snowflake_connectionName, "unavailableDSN")
os.Setenv(snowflakeHome, "./test_data")
os.Setenv(snowflakeConnectionName, "unavailableDSN")

_, err = LoadConnectionConfig()
assertNotNilF(t, err, "The error should occur")
Expand All @@ -97,8 +97,8 @@ func TestLoadConnectionConfigWithTokenFileNotExist(t *testing.T) {
err := os.Chmod("./test_data/connections.toml", 0600)
assertNilF(t, err, "The error occurred because you cannot change the file permission")

os.Setenv(snowflake_home, "./test_data")
os.Setenv(snowflake_connectionName, "aws-oauth-file")
os.Setenv(snowflakeHome, "./test_data")
os.Setenv(snowflakeConnectionName, "aws-oauth-file")

_, err = LoadConnectionConfig()
assertNotNilF(t, err, "The error should occur")
Expand Down Expand Up @@ -248,7 +248,7 @@ func TestGetTomlFilePath(t *testing.T) {
dir, err := getTomlFilePath("")
assertNilF(t, err, "should not have failed")
homeDir, err := os.UserHomeDir()
assertNilF(t, err, "The connection cannot find the user snowflake_home directory")
assertNilF(t, err, "The connection cannot find the user home directory")
assertEqualF(t, dir, path.Join(homeDir, ".snowflake"))

location := "../user//somelocation///b"
Expand Down

0 comments on commit cdc9031

Please sign in to comment.