Skip to content

Commit

Permalink
skip test on macOS
Browse files Browse the repository at this point in the history
remove ioutils
  • Loading branch information
SimbaGithub authored and sfc-gh-ext-simba-lb committed Nov 2, 2022
1 parent 7a15d1a commit db46032
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 35 deletions.
5 changes: 2 additions & 3 deletions secure_storage_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package gosnowflake

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -223,7 +222,7 @@ func readTemporaryCacheFile() map[string]string {
logger.Debug("Cache file doesn't exist. Skipping reading credential file.")
return nil
}
jsonData, err := ioutil.ReadFile(credCache)
jsonData, err := os.ReadFile(credCache)
if err != nil {
logger.Debugf("Failed to read credential file: %v", err)
return nil
Expand Down Expand Up @@ -268,7 +267,7 @@ func writeTemporaryCacheFile(input []byte) {
}
defer os.RemoveAll(credCacheLockFileName)

if err = ioutil.WriteFile(credCache, input, 0644); err != nil {
if err = os.WriteFile(credCache, input, 0644); err != nil {
logger.Debugf("Failed to write the cache file. File: %v err: %v.", credCache, err)
}
}
Expand Down
73 changes: 41 additions & 32 deletions secure_storage_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,54 @@
package gosnowflake

import (
"runtime"
"testing"
)

func TestSetAndGetCredentialMfa(t *testing.T) {
fakeMfaToken := "fakeMfaToken"
expectedMfaToken := "fakeMfaToken"
sc := getDefaultSnowflakeConn()
sc.cfg.Host = "testhost"
setCredential(sc, mfaToken, fakeMfaToken)
getCredential(sc, mfaToken)

if sc.cfg.MfaToken != expectedMfaToken {
t.Fatalf("Expected mfa token %v but got %v", expectedMfaToken, sc.cfg.MfaToken)
}

// delete credential and check it no longer exists
deleteCredential(sc, mfaToken)
getCredential(sc, mfaToken)
if sc.cfg.MfaToken != "" {
t.Fatalf("Expected mfa token to be empty but got %v", sc.cfg.MfaToken)
if runtime.GOOS == "darwin" {
t.Skip("MacOS requires keychain password to be manually entered.")
} else {
fakeMfaToken := "fakeMfaToken"
expectedMfaToken := "fakeMfaToken"
sc := getDefaultSnowflakeConn()
sc.cfg.Host = "testhost"
setCredential(sc, mfaToken, fakeMfaToken)
getCredential(sc, mfaToken)

if sc.cfg.MfaToken != expectedMfaToken {
t.Fatalf("Expected mfa token %v but got %v", expectedMfaToken, sc.cfg.MfaToken)
}

// delete credential and check it no longer exists
deleteCredential(sc, mfaToken)
getCredential(sc, mfaToken)
if sc.cfg.MfaToken != "" {
t.Fatalf("Expected mfa token to be empty but got %v", sc.cfg.MfaToken)
}
}
}

func TestSetAndGetCredentialIdToken(t *testing.T) {
fakeIDToken := "fakeIDToken"
expectedIDToken := "fakeIDToken"
sc := getDefaultSnowflakeConn()
sc.cfg.Host = "testhost"
setCredential(sc, idToken, fakeIDToken)
getCredential(sc, idToken)

if sc.cfg.IDToken != expectedIDToken {
t.Fatalf("Expected id token %v but got %v", expectedIDToken, sc.cfg.IDToken)
}

// delete credential and check it no longer exists
deleteCredential(sc, idToken)
getCredential(sc, idToken)
if sc.cfg.IDToken != "" {
t.Fatalf("Expected id token to be empty but got %v", sc.cfg.IDToken)
if runtime.GOOS == "darwin" {
t.Skip("MacOS requires keychain password to be manually entered.")
} else {
fakeIDToken := "fakeIDToken"
expectedIDToken := "fakeIDToken"
sc := getDefaultSnowflakeConn()
sc.cfg.Host = "testhost"
setCredential(sc, idToken, fakeIDToken)
getCredential(sc, idToken)

if sc.cfg.IDToken != expectedIDToken {
t.Fatalf("Expected id token %v but got %v", expectedIDToken, sc.cfg.IDToken)
}

// delete credential and check it no longer exists
deleteCredential(sc, idToken)
getCredential(sc, idToken)
if sc.cfg.IDToken != "" {
t.Fatalf("Expected id token to be empty but got %v", sc.cfg.IDToken)
}
}
}

0 comments on commit db46032

Please sign in to comment.