Skip to content

Commit

Permalink
errorhandling
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pcyrek committed Dec 18, 2024
1 parent d2f480b commit a52cb60
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 4 additions & 2 deletions auth_with_external_browser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ func TestClientStoreCredentials(t *testing.T) {
cleanupBrowserProcesses(t)
cfg.ClientStoreTemporaryCredential = 1
db := getDbHandlerFromConfig(t, cfg)
conn, _ := db.Conn(context.Background())
_, err := conn.QueryContext(context.Background(), "SELECT 1")
conn, err := db.Conn(context.Background())
assertNilE(t, err, fmt.Sprintf("Failed to connect to Snowflake. err: %v", err))
_, err = conn.QueryContext(context.Background(), "SELECT 1")
assertNilE(t, err, fmt.Sprintf("Failed to run a query. err: %v", err))
})

Expand Down Expand Up @@ -164,6 +165,7 @@ func connectToSnowflake(t *testing.T, cfg *Config) (err error) {
}

defer rows.Close()

assertTrueE(t, rows.Next(), "failed to get result", "There were no results for query: ")

return err
Expand Down
13 changes: 8 additions & 5 deletions auth_with_oauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (

func TestOauthSuccessful(t *testing.T) {
cfg := setupOauthTest(t)
token, _ := getOauthTestToken(t, cfg)
token, err := getOauthTestToken(t, cfg)
assertNilE(t, err, fmt.Sprintf("failed to get token. err: %v", err))
cfg.Token = token
err := connectToSnowflake(t, cfg)
err = connectToSnowflake(t, cfg)
assertNilE(t, err, fmt.Sprintf("failed to connect. err: %v", err))
}

Expand All @@ -31,11 +32,12 @@ func TestOauthInvalidToken(t *testing.T) {

func TestOauthMismatchedUser(t *testing.T) {
cfg := setupOauthTest(t)
token, _ := getOauthTestToken(t, cfg)
token, err := getOauthTestToken(t, cfg)
assertNilE(t, err, fmt.Sprintf("failed to get token. err: %v", err))
cfg.Token = token
cfg.User = "fakeaccount"

err := connectToSnowflake(t, cfg)
err = connectToSnowflake(t, cfg)

var snowflakeErr *SnowflakeError
assertTrueF(t, errors.As(err, &snowflakeErr))
Expand Down Expand Up @@ -66,7 +68,8 @@ func getOauthTestToken(t *testing.T, cfg *Config) (string, error) {

inputData := formData(cfg)

req, _ := http.NewRequest("POST", authURL, strings.NewReader(inputData.Encode()))
req, err := http.NewRequest("POST", authURL, strings.NewReader(inputData.Encode()))
assertNilF(t, err, fmt.Sprintf("Request failed %v", err))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8")
req.SetBasicAuth(oauthClientID, oauthClientSecret)
resp, err := client.Do(req)
Expand Down

0 comments on commit a52cb60

Please sign in to comment.