Skip to content

Commit

Permalink
Run pre-push
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-asawicki committed Nov 27, 2024
1 parent 816eaf9 commit 9111355
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/acceptance/helpers/config_toml_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

// FullTomlConfigForServiceUser is a temporary function used to test provider configuration
// TODO [SNOW-1827309]: use toml marshalling from "github.com/pelletier/go-toml/v2"
// TODO [SNOW-1827309]: use toml marshaling from "github.com/pelletier/go-toml/v2"
// TODO [SNOW-1827309]: add builders for our toml config struct
func FullTomlConfigForServiceUser(t *testing.T, profile string, userId sdk.AccountObjectIdentifier, roleId sdk.AccountObjectIdentifier, warehouseId sdk.AccountObjectIdentifier, accountIdentifier sdk.AccountIdentifier, privateKey string) string {
t.Helper()
Expand Down
8 changes: 8 additions & 0 deletions pkg/acceptance/helpers/tmp_toml_setup_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,50 @@ import (
// TODO [SNOW-1827324]: add TestClient ref to each specific client, so that we enhance specific client and not the base one

func (c *TestClient) TempTomlConfigForServiceUser(t *testing.T, serviceUser *TmpServiceUser) *TmpTomlConfig {
t.Helper()
return c.StoreTempTomlConfig(t, func(profile string) string {
return TomlConfigForServiceUser(t, profile, serviceUser.UserId, serviceUser.RoleId, serviceUser.WarehouseId, serviceUser.AccountId, serviceUser.PrivateKey)
})
}

func (c *TestClient) TempTomlConfigForServiceUserWithEncryptedKey(t *testing.T, serviceUser *TmpServiceUser) *TmpTomlConfig {
t.Helper()
return c.StoreTempTomlConfig(t, func(profile string) string {
return TomlConfigForServiceUserWithEncryptedKey(t, profile, serviceUser.UserId, serviceUser.RoleId, serviceUser.WarehouseId, serviceUser.AccountId, serviceUser.EncryptedPrivateKey, serviceUser.Pass)
})
}

func (c *TestClient) TempIncorrectTomlConfigForServiceUser(t *testing.T, serviceUser *TmpServiceUser) *TmpTomlConfig {
t.Helper()
return c.StoreTempTomlConfig(t, func(profile string) string {
return TomlIncorrectConfigForServiceUser(t, profile, serviceUser.AccountId)
})
}

func (c *TestClient) TempIncorrectTomlConfigForServiceUserWithEncryptedKey(t *testing.T, serviceUser *TmpServiceUser) *TmpTomlConfig {
t.Helper()
return c.StoreTempTomlConfig(t, func(profile string) string {
return TomlConfigForServiceUserWithEncryptedKey(t, profile, serviceUser.UserId, serviceUser.RoleId, serviceUser.WarehouseId, serviceUser.AccountId, serviceUser.EncryptedPrivateKey, "incorrect pass")
})
}

func (c *TestClient) TempTomlConfigForLegacyServiceUser(t *testing.T, legacyServiceUser *TmpLegacyServiceUser) *TmpTomlConfig {
t.Helper()
return c.StoreTempTomlConfig(t, func(profile string) string {
return TomlConfigForLegacyServiceUser(t, profile, legacyServiceUser.UserId, legacyServiceUser.RoleId, legacyServiceUser.WarehouseId, legacyServiceUser.AccountId, legacyServiceUser.Pass)
})
}

func (c *TestClient) TempIncorrectTomlConfigForLegacyServiceUser(t *testing.T, legacyServiceUser *TmpLegacyServiceUser) *TmpTomlConfig {
t.Helper()
return c.StoreTempTomlConfig(t, func(profile string) string {
return TomlConfigForLegacyServiceUser(t, profile, legacyServiceUser.UserId, legacyServiceUser.RoleId, legacyServiceUser.WarehouseId, legacyServiceUser.AccountId, "incorrect pass")
})
}

func (c *TestClient) StoreTempTomlConfig(t *testing.T, tomlProvider func(string) string) *TmpTomlConfig {
t.Helper()

profile := random.AlphaN(6)
toml := tomlProvider(profile)
configPath := testhelpers.TestFile(t, random.AlphaN(10), []byte(toml))
Expand Down
6 changes: 6 additions & 0 deletions pkg/acceptance/helpers/tmp_user_setup_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
// TODO [SNOW-1827324]: consider using these in other places where user is set up

func (c *TestClient) SetUpTemporaryLegacyServiceUser(t *testing.T) *TmpLegacyServiceUser {
t.Helper()

pass := random.Password()
tmpUser := c.setUpTmpUserWithBasicAccess(t, func(userId sdk.AccountObjectIdentifier) (*sdk.User, func()) {
return c.User.CreateUserWithOptions(t, userId, &sdk.CreateUserOptions{ObjectProperties: &sdk.UserObjectProperties{
Expand All @@ -26,6 +28,8 @@ func (c *TestClient) SetUpTemporaryLegacyServiceUser(t *testing.T) *TmpLegacySer
}

func (c *TestClient) SetUpTemporaryServiceUser(t *testing.T) *TmpServiceUser {
t.Helper()

pass := random.Password()
privateKey, encryptedKey, publicKey, _ := random.GenerateRSAKeyPair(t, pass)
tmpUser := c.setUpTmpUserWithBasicAccess(t, func(userId sdk.AccountObjectIdentifier) (*sdk.User, func()) {
Expand All @@ -45,6 +49,8 @@ func (c *TestClient) SetUpTemporaryServiceUser(t *testing.T) *TmpServiceUser {
}

func (c *TestClient) setUpTmpUserWithBasicAccess(t *testing.T, userCreator func(userId sdk.AccountObjectIdentifier) (*sdk.User, func())) TmpUser {
t.Helper()

warehouseId := c.Ids.SnowflakeWarehouseId()
accountId := c.Context.CurrentAccountId(t)

Expand Down
12 changes: 6 additions & 6 deletions pkg/provider/provider_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,14 @@ func TestAcc_Provider_tomlConfig(t *testing.T) {
Config: providerConfig(tmpServiceUserConfig.Profile),
Check: func(s *terraform.State) error {
config := acc.TestAccProvider.Meta().(*internalprovider.Context).Client.GetConfig()
//assert.Equal(t, account, config.Account)
// assert.Equal(t, account, config.Account)
assert.Equal(t, tmpServiceUser.UserId.Name(), config.User)
assert.Equal(t, tmpServiceUser.WarehouseId.Name(), config.Warehouse)
assert.Equal(t, tmpServiceUser.RoleId.Name(), config.Role)
assert.Equal(t, gosnowflake.ConfigBoolTrue, config.ValidateDefaultParameters)
assert.Equal(t, net.ParseIP("1.2.3.4"), config.ClientIP)
assert.Equal(t, "https", config.Protocol)
//assert.Equal(t, fmt.Sprintf("%s.snowflakecomputing.com", account), config.Host)
// assert.Equal(t, fmt.Sprintf("%s.snowflakecomputing.com", account), config.Host)
assert.Equal(t, 443, config.Port)
assert.Equal(t, gosnowflake.AuthTypeJwt, config.Authenticator)
assert.Equal(t, false, config.PasscodeInPassword)
Expand Down Expand Up @@ -339,14 +339,14 @@ func TestAcc_Provider_envConfig(t *testing.T) {
Check: func(s *terraform.State) error {
config := acc.TestAccProvider.Meta().(*internalprovider.Context).Client.GetConfig()

//assert.Equal(t, account, config.Account)
// assert.Equal(t, account, config.Account)
assert.Equal(t, tmpServiceUser.UserId.Name(), config.User)
assert.Equal(t, tmpServiceUser.WarehouseId.Name(), config.Warehouse)
assert.Equal(t, tmpServiceUser.RoleId.Name(), config.Role)
assert.Equal(t, gosnowflake.ConfigBoolTrue, config.ValidateDefaultParameters)
assert.Equal(t, net.ParseIP("2.2.2.2"), config.ClientIP)
assert.Equal(t, "https", config.Protocol)
//assert.Equal(t, fmt.Sprintf("%s.snowflakecomputing.com", account), config.Host)
// assert.Equal(t, fmt.Sprintf("%s.snowflakecomputing.com", account), config.Host)
assert.Equal(t, 443, config.Port)
assert.Equal(t, gosnowflake.AuthTypeJwt, config.Authenticator)
assert.Equal(t, false, config.PasscodeInPassword)
Expand Down Expand Up @@ -451,14 +451,14 @@ func TestAcc_Provider_tfConfig(t *testing.T) {
Check: func(s *terraform.State) error {
config := acc.TestAccProvider.Meta().(*internalprovider.Context).Client.GetConfig()

//assert.Equal(t, account, config.Account)
// assert.Equal(t, account, config.Account)
assert.Equal(t, tmpServiceUser.UserId.Name(), config.User)
assert.Equal(t, tmpServiceUser.WarehouseId.Name(), config.Warehouse)
assert.Equal(t, tmpServiceUser.RoleId.Name(), config.Role)
assert.Equal(t, gosnowflake.ConfigBoolTrue, config.ValidateDefaultParameters)
assert.Equal(t, net.ParseIP("3.3.3.3"), config.ClientIP)
assert.Equal(t, "https", config.Protocol)
//assert.Equal(t, fmt.Sprintf("%s.snowflakecomputing.com", account), config.Host)
// assert.Equal(t, fmt.Sprintf("%s.snowflakecomputing.com", account), config.Host)
assert.Equal(t, 443, config.Port)
assert.Equal(t, gosnowflake.AuthTypeJwt, config.Authenticator)
assert.Equal(t, false, config.PasscodeInPassword)
Expand Down
2 changes: 1 addition & 1 deletion pkg/sdk/testint/client_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

// TODO [SNOW-1827310]: use generated config for these tests
func TestClient_NewClient(t *testing.T) {
func TestInt_Client_NewClient(t *testing.T) {
t.Run("with default config", func(t *testing.T) {
config := sdk.DefaultConfig()
_, err := sdk.NewClient(config)
Expand Down

0 comments on commit 9111355

Please sign in to comment.