Skip to content

Commit

Permalink
cover missing test areas
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-lb committed Aug 2, 2023
1 parent 5e1158c commit aade3ae
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
3 changes: 3 additions & 0 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ func determineAuthenticatorType(cfg *Config, value string) error {
} else if upperCaseValue == AuthTypeUsernamePasswordMFA.String() {
cfg.Authenticator = AuthTypeUsernamePasswordMFA
return nil
} else if upperCaseValue == AuthTypeTokenAccessor.String() {
cfg.Authenticator = AuthTypeTokenAccessor
return nil
} else {
// possibly Okta case
oktaURLString, err := url.QueryUnescape(lowerCaseValue)
Expand Down
9 changes: 9 additions & 0 deletions dsn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,15 @@ func TestDSN(t *testing.T) {
},
dsn: "u:p@a.b.c.snowflakecomputing.com:443?ocspFailOpen=true&region=b.c&token=t&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "a.b.c",
Authenticator: AuthTypeTokenAccessor,
},
dsn: "u:p@a.b.c.snowflakecomputing.com:443?authenticator=tokenaccessor&ocspFailOpen=true&region=b.c&validateDefaultParameters=true",
},
}
for _, test := range testcases {
dsn, err := DSN(test.cfg)
Expand Down
30 changes: 30 additions & 0 deletions file_transfer_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
package gosnowflake

import (
"bytes"
"context"
"errors"
"fmt"
"io"
"net/url"
"os"
"path"
Expand Down Expand Up @@ -597,3 +599,31 @@ func TestUploadWhenFilesystemReadOnlyError(t *testing.T) {
t.Fatalf("should error when creating the temporary directory. Instead errored with: %v", err)
}
}

func TestUnitUpdateProgess(t *testing.T) {
var b bytes.Buffer
buf := io.Writer(&b)
buf.Write([]byte("testing"))

spp := &snowflakeProgressPercentage{
filename: "test.txt",
fileSize: float64(1500),
outputStream: &buf,
showProgressBar: true,
done: false,
}

spp.call(0)
if spp.done != false {
t.Fatal("should not be done.")
}

if spp.seenSoFar != 0 {
t.Fatalf("expected seenSoFar to be 0 but was %v", spp.seenSoFar)
}

spp.call(1516)
if spp.done != true {
t.Fatal("should be done after updating progess")
}
}
24 changes: 24 additions & 0 deletions heartbeat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,27 @@ func TestUnitPostHeartbeat(t *testing.T) {
t.Fatalf("unexpected error code. expected: %v, got: %v", ErrFailedToHeartbeat, driverErr.Number)
}
}

func TestStopHeartbeat(t *testing.T) {
createDSNWithClientSessionKeepAlive()
ctx := context.Background()
config, err := ParseDSN(dsn)
if err != nil {
t.Error(err)
}
driver := SnowflakeDriver{}
sc, err := driver.OpenWithConfig(ctx, *config) // starts heartbeat
if err != nil {
t.Error(err)
}
conn := sc.(*snowflakeConn)
if !conn.isClientSessionKeepAliveEnabled() {
t.Fatal("client session keep alive is not enabled")
}

conn.rest.HeartBeat.stop()
_, ok := <-conn.rest.HeartBeat.shutdownChan
if ok {
t.Fatal("channel should be closed")
}
}
File renamed without changes.

0 comments on commit aade3ae

Please sign in to comment.