Skip to content

Commit

Permalink
SNOW-540086: Missing critical areas for code coverage (#873)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-lb authored Aug 4, 2023
1 parent 09e2e45 commit ad2d6fe
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 6 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:[email protected]:443?ocspFailOpen=true&region=b.c&token=t&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "a.b.c",
Authenticator: AuthTypeTokenAccessor,
},
dsn: "u:[email protected]:443?authenticator=tokenaccessor&ocspFailOpen=true&region=b.c&validateDefaultParameters=true",
},
}
for _, test := range testcases {
dsn, err := DSN(test.cfg)
Expand Down
8 changes: 4 additions & 4 deletions file_transfer_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -1156,21 +1156,21 @@ type snowflakeProgressPercentage struct {
func (spp *snowflakeProgressPercentage) call(bytesAmount int64) {
if spp.outputStream != nil {
spp.seenSoFar += bytesAmount
percentage := percent(spp.seenSoFar, spp.fileSize)
percentage := spp.percent(spp.seenSoFar, spp.fileSize)
if !spp.done {
spp.done = updateProgress(spp.filename, spp.startTime, spp.fileSize, percentage, spp.outputStream, spp.showProgressBar)
spp.done = spp.updateProgress(spp.filename, spp.startTime, spp.fileSize, percentage, spp.outputStream, spp.showProgressBar)
}
}
}

func percent(seenSoFar int64, size float64) float64 {
func (spp *snowflakeProgressPercentage) percent(seenSoFar int64, size float64) float64 {
if float64(seenSoFar) >= size || size <= 0 {
return 1.0
}
return float64(seenSoFar) / size
}

func updateProgress(filename string, startTime time.Time, totalSize float64, progress float64, outputStream *io.Writer, showProgressBar bool) bool {
func (spp *snowflakeProgressPercentage) updateProgress(filename string, startTime time.Time, totalSize float64, progress float64, outputStream *io.Writer, showProgressBar bool) bool {
barLength := 10
totalSize /= mb
status := ""
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")
}
}
2 changes: 2 additions & 0 deletions test_util.go → mock_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"testing"
)

/** This file contains helper functions for tests only. **/

func resetHTTPMocks(t *testing.T) {
_, err := http.Post("http://localhost:12345/reset", "text/plain", nil)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions put_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ func TestPercentage(t *testing.T) {
{14, 28, 0.5},
}
for _, test := range testcases {
if percent(test.seen, test.size) != test.expected {
spp := snowflakeProgressPercentage{}
if spp.percent(test.seen, test.size) != test.expected {
t.Fatalf("percentage conversion failed. %v/%v, expected: %v, got: %v",
test.seen, test.size, test.expected, percent(test.seen, test.size))
test.seen, test.size, test.expected, spp.percent(test.seen, test.size))
}
}
}
Expand Down

0 comments on commit ad2d6fe

Please sign in to comment.