Skip to content

Commit

Permalink
Ensure test coverage for lio use cases (#105)
Browse files Browse the repository at this point in the history
* Ensure test coverage for lio use cases

* Remove deprecated golang code
  • Loading branch information
ajroetker authored Sep 27, 2023
1 parent 26225d7 commit 94a4634
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 28 deletions.
3 changes: 1 addition & 2 deletions google/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package google

import (
"fmt"
"io/ioutil"
"net/http"
"os"

Expand Down Expand Up @@ -78,7 +77,7 @@ func BuildGoogleJWTTransporter(jwtConf *cloudstorage.JwtConf) (GoogleOAuthClient

// BuildGoogleFileJWTTransporter creates a Google Storage Client using a JWT file for the jwt config.
func BuildGoogleFileJWTTransporter(keyPath string, scope string) (GoogleOAuthClient, error) {
jsonKey, err := ioutil.ReadFile(os.ExpandEnv(keyPath))
jsonKey, err := os.ReadFile(os.ExpandEnv(keyPath))
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions google/storeutils/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package storeutils

import (
"bytes"
"io/ioutil"
"io"

"cloud.google.com/go/storage"
"golang.org/x/net/context"
Expand All @@ -24,7 +24,7 @@ func GetObjectWithContext(ctx context.Context, gc *storage.Client, bucket, name
}
return nil, err
}
by, err := ioutil.ReadAll(rc)
by, err := io.ReadAll(rc)
if err != nil {
return nil, err
}
Expand Down
40 changes: 16 additions & 24 deletions testutils/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"context"
"flag"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -50,7 +50,7 @@ func Setup() {
if logger != nil {
// don't re-setup
} else {
if (verbose != nil && *verbose == true) || os.Getenv("VERBOSELOGS") != "" {
if (verbose != nil && *verbose) || os.Getenv("VERBOSELOGS") != "" {
gou.SetupLogging("debug")
gou.SetColorOutput()
} else {
Expand Down Expand Up @@ -192,11 +192,16 @@ func BasicRW(t *testing.T, store cloudstorage.Store) {
require.Equal(t, "prefix/test.csv", obj2.String())

f2, err := obj2.Open(cloudstorage.ReadOnly)
defer f2.Close()
defer func() {
err := f2.Close()
if err != nil {
t.Errorf("error closing file: %v", err)
}
}()
require.NoError(t, err)
require.Equal(t, fmt.Sprintf("%p", f2), fmt.Sprintf("%p", obj2.File()))

bytes, err := ioutil.ReadAll(f2)
bytes, err := io.ReadAll(f2)
require.NoError(t, err)

require.Equal(t, testcsv, string(bytes))
Expand Down Expand Up @@ -248,7 +253,7 @@ func createFile(t *testing.T, store cloudstorage.Store, name, data string) cloud
f2, err := obj2.Open(cloudstorage.ReadWrite)
require.NoError(t, err)

bytes, err := ioutil.ReadAll(f2)
bytes, err := io.ReadAll(f2)
require.NoError(t, err)

require.Equal(t, data, string(bytes))
Expand Down Expand Up @@ -336,7 +341,7 @@ func ensureContents(t *testing.T, store cloudstorage.Store, name, data, msg stri
require.Equalf(t, nil, err, msg, caller)
require.Equalf(t, fmt.Sprintf("%p", f), fmt.Sprintf("%p", obj.File()), msg, caller)

bytes, err := ioutil.ReadAll(f)
bytes, err := io.ReadAll(f)
require.Equalf(t, nil, err, msg, caller)
require.Equalf(t, data, string(bytes), msg, caller)
}
Expand Down Expand Up @@ -429,7 +434,7 @@ func Append(t *testing.T, store cloudstorage.Store) {

// DANGER HERE BE DRAGONS. This didn't used to be here
// so would our app have to implement this behavior?
_, err = f2.Seek(0, os.SEEK_END)
_, err = f2.Seek(0, io.SeekEnd)
require.NoError(t, err)

w2 := bufio.NewWriter(f2)
Expand Down Expand Up @@ -458,7 +463,7 @@ func Append(t *testing.T, store cloudstorage.Store) {
f3, err := obj3.Open(cloudstorage.ReadOnly)
require.NoError(t, err)

bytes, err := ioutil.ReadAll(f3)
bytes, err := io.ReadAll(f3)
require.NoError(t, err)

require.Equal(t, testcsv+morerows, string(bytes), "not the rows we expected.")
Expand All @@ -481,19 +486,6 @@ func Append(t *testing.T, store cloudstorage.Store) {
require.NoError(t, err)
}

func dumpfile(msg, file string) {
f, err := os.OpenFile(file, os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
panic(err.Error())
}
defer f.Close()
by, err := ioutil.ReadAll(f)
if err != nil {
panic(err.Error())
}
gou.Infof("dumpfile %s %s\n%s", msg, file, string(by))
}

func ListObjsAndFolders(t *testing.T, store cloudstorage.Store) {

Clearstore(t, store)
Expand Down Expand Up @@ -707,7 +699,7 @@ func Truncate(t *testing.T, store cloudstorage.Store) {
f3, err := obj3.Open(cloudstorage.ReadOnly)
require.NoError(t, err)

bytes, err := ioutil.ReadAll(f3)
bytes, err := io.ReadAll(f3)
require.NoError(t, err)

require.Equal(t, newtestcsv, string(bytes), "not the rows we expected.")
Expand Down Expand Up @@ -749,7 +741,7 @@ func NewObjectWithExisting(t *testing.T, store cloudstorage.Store) {
f3, err := obj3.Open(cloudstorage.ReadOnly)
require.NoError(t, err)

bytes, err := ioutil.ReadAll(f3)
bytes, err := io.ReadAll(f3)
require.NoError(t, err)

require.Equal(t, testcsv, string(bytes))
Expand Down Expand Up @@ -894,7 +886,7 @@ func MultipleRW(t *testing.T, store cloudstorage.Store, conf *cloudstorage.Confi

require.NoError(t, err)
require.Equal(t, fmt.Sprintf("%p", f2), fmt.Sprintf("%p", obj2.File()))
bytes, err := ioutil.ReadAll(f2)
bytes, err := io.ReadAll(f2)
require.NoError(t, err)
require.Nil(t, f2.Close())

Expand Down

0 comments on commit 94a4634

Please sign in to comment.