Skip to content

Commit

Permalink
review 1
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pcyrek committed Dec 13, 2024
1 parent 3053d2d commit 0c6d4b9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func getConfigFromEnv() (*Config, error) {
})
}

func getConfig(authMethod AuthType) (*Config, error) {
func getAuthTestsConfig(authMethod AuthType) (*Config, error) {
cfg, err := getConfigFromEnv()
if err != nil {
return nil, err
Expand Down
33 changes: 18 additions & 15 deletions auth_with_external_browser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestExternalBrowserSuccessful(t *testing.T) {

func TestExternalBrowserFailed(t *testing.T) {
cfg := setupExternalBrowserTest(t)
cfg.ExternalBrowserTimeout = time.Duration(10000) * time.Millisecond
cfg.ExternalBrowserTimeout = time.Duration(10) * time.Second
var wg sync.WaitGroup
wg.Add(2)
go func() {
Expand All @@ -51,7 +51,7 @@ func TestExternalBrowserFailed(t *testing.T) {

func TestExternalBrowserTimeout(t *testing.T) {
cfg := setupExternalBrowserTest(t)
cfg.ExternalBrowserTimeout = time.Duration(1000) * time.Millisecond
cfg.ExternalBrowserTimeout = time.Duration(1) * time.Second
var wg sync.WaitGroup
wg.Add(2)
go func() {
Expand All @@ -71,14 +71,13 @@ func TestExternalBrowserTimeout(t *testing.T) {

func TestExternalBrowserMismatchUser(t *testing.T) {
cfg := setupExternalBrowserTest(t)
correctUsername := cfg.User
cfg.User = "fakeAccount"
wrongUsername := "fakeAccount"
var wg sync.WaitGroup

wg.Add(2)
go func() {
defer wg.Done()
provideCredentials(externalBrowserType.Success, correctUsername, cfg.Password)
provideCredentials(externalBrowserType.Success, wrongUsername, cfg.Password)
}()
go func() {
defer wg.Done()
Expand All @@ -96,7 +95,7 @@ func TestExternalBrowserMismatchUser(t *testing.T) {
func TestClientStoreCredentials(t *testing.T) {
cfg := setupExternalBrowserTest(t)
cfg.ClientStoreTemporaryCredential = 1
cfg.ExternalBrowserTimeout = time.Duration(10000) * time.Millisecond
cfg.ExternalBrowserTimeout = time.Duration(10) * time.Second

t.Run("Obtains the ID token from the server and saves it on the local storage", func(t *testing.T) {
cleanupBrowserProcesses()
Expand Down Expand Up @@ -138,13 +137,13 @@ func TestClientStoreCredentials(t *testing.T) {
})
}

type Mode struct {
type ExternalBrowserProcess struct {
Success string
Fail string
Timeout string
}

var externalBrowserType = Mode{
var externalBrowserType = ExternalBrowserProcess{
Success: "success",
Fail: "fail",
Timeout: "timeout",
Expand All @@ -158,33 +157,37 @@ func cleanupBrowserProcesses() {
}
}

func provideCredentials(mode string, user string, password string) {
func provideCredentials(ExternalBrowserProcess string, user string, password string) {
const provideBrowserCredentialsPath = "/externalbrowser/provideBrowserCredentials.js"
_, err := exec.Command("node", provideBrowserCredentialsPath, mode, user, password).Output()
_, err := exec.Command("node", provideBrowserCredentialsPath, ExternalBrowserProcess, user, password).Output()
if err != nil {
log.Fatalf("failed to execute command: %v", err)
}
}

func connectToSnowflake(cfg *Config, query string, exceptionHandler bool) (rows *sql.Rows, err error) {
func connectToSnowflake(cfg *Config, query string, isCatchException bool) (rows *sql.Rows, err error) {
parseFlags()
dsn, err := DSN(cfg)
if err != nil {
log.Fatalf("failed to create DSN from Config: %v, err: %v", cfg, err)
}
rows, err = executeQuery(query, dsn)
if exceptionHandler && err != nil {
if isCatchException && err != nil {
log.Fatalf("failed to run a query. %v, err: %v", rows, err)
} else if err != nil {
return rows, err
}
defer rows.Close()
var v int
if !rows.Next() {
fmt.Printf("There were no results for query: %v \n", query)
return rows, err
}
for rows.Next() {
err := rows.Scan(&v)
if exceptionHandler && err != nil {
if isCatchException && err != nil {
log.Fatalf("failed to get result. err: %v", err)
} else if exceptionHandler {
} else if isCatchException {
fmt.Printf("Congrats! You have successfully run '%v' with Snowflake DB! \n", query)
}
}
Expand All @@ -197,7 +200,7 @@ func setupExternalBrowserTest(t *testing.T) *Config {
t.Skip("Running only on Docker container")
}
cleanupBrowserProcesses()
cfg, err := getConfig(AuthTypeExternalBrowser)
cfg, err := getAuthTestsConfig(AuthTypeExternalBrowser)
if err != nil {
t.Fatalf("failed to get config: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions auth_with_oauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func setupOauthTest(t *testing.T) *Config {
}
skipOnJenkins(t, "Running only on Docker container")

cfg, err := getConfig(AuthTypeOAuth)
cfg, err := getAuthTestsConfig(AuthTypeOAuth)
if err != nil {
t.Fatalf("failed to get config: %v", err)
}
Expand Down Expand Up @@ -82,7 +82,7 @@ func getToken(cfg *Config) (string, error) {

var response Response
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
panic(err)
return "", fmt.Errorf("failed to decode response: %v", err)
}

return response.Token, err
Expand Down
2 changes: 1 addition & 1 deletion auth_with_okta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func setupOktaTest(t *testing.T) *Config {
return nil
}

cfg, err := getConfig(AuthTypeOkta)
cfg, err := getAuthTestsConfig(AuthTypeOkta)
if err != nil {
t.Fatalf("failed to get config: %v", err)
}
Expand Down

0 comments on commit 0c6d4b9

Please sign in to comment.