Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Go Tests for V2 #392

Merged
merged 3 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions .github/workflows/go-getter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ jobs:
- 1.17
- 1.18
- 1.19
directory:
- s3
- gcs
- .
permissions:
id-token: write
contents: read
Expand Down Expand Up @@ -80,6 +84,7 @@ jobs:
diff tmpdir/go.mod go.mod

- name: Run Go tests
working-directory: ${{ matrix.directory }}
run: |
PACKAGE_NAMES=$(go list ./...)
echo "Running $(echo $PACKAGE_NAMES | wc -w) packages"
Expand All @@ -101,6 +106,10 @@ jobs:
- 1.17
- 1.18
- 1.19
directory:
- s3
- gcs
- .
permissions:
id-token: write
contents: read
Expand All @@ -112,7 +121,7 @@ jobs:
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v3

Expand All @@ -127,11 +136,11 @@ jobs:
${{ runner.os }}-go-
- name: Download go modules
run: go mod download

- name: Install gotestsum
shell: bash
run: go install gotest.tools/[email protected]

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
Expand All @@ -146,7 +155,7 @@ jobs:
workload_identity_provider: 'projects/328212837253/locations/global/workloadIdentityPools/hc-go-getter-test/providers/github-hc-go-getter-test'
service_account: hc-go-getter-test@hc-e56c0f7c21c448d2be9e7696073.iam.gserviceaccount.com
audience: https://github.com/hashicorp

- name: Run Go cmd
run: |
cd cmd/go-getter
Expand All @@ -155,6 +164,7 @@ jobs:

- name: Run Go tests
shell: bash
working-directory: ${{ matrix.directory }}
run: |
PACKAGE_NAMES=$(go list ./...)
echo "Running $(echo $PACKAGE_NAMES | wc -w) packages"
Expand All @@ -167,7 +177,7 @@ jobs:
with:
name: windows test results
path: ${{ env.TEST_RESULTS_PATH }}

go-smb-tests:
runs-on: ubuntu-latest
strategy:
Expand All @@ -184,7 +194,7 @@ jobs:
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v3

Expand All @@ -200,4 +210,4 @@ jobs:
docker-compose up -d

- name: Run SMB getter tests
run: docker exec -i gogetter bash -c "env ACC_SMB_TEST=1 go test -v ./... -run=TestSmb_"
run: docker exec -i gogetter bash -c "env ACC_SMB_TEST=1 go test -v ./... -run=TestSmb_"
4 changes: 1 addition & 3 deletions cmd/go-getter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ replace (
)

require (
github.com/cheggaaa/pb v1.0.28
github.com/fatih/color v1.9.0 // indirect
github.com/cheggaaa/pb v1.0.29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing. I have this change in the 1.18 PR.

github.com/hashicorp/go-getter/gcs/v2 v2.1.0
github.com/hashicorp/go-getter/s3/v2 v2.1.0
github.com/hashicorp/go-getter/v2 v2.1.0
github.com/mattn/go-runewidth v0.0.8 // indirect
gopkg.in/cheggaaa/pb.v1 v1.0.28 // indirect
)
756 changes: 716 additions & 40 deletions cmd/go-getter/go.sum

Large diffs are not rendered by default.

43 changes: 11 additions & 32 deletions gcs/get_gcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,21 @@ import (
urlhelper "github.com/hashicorp/go-getter/v2/helper/url"
)

// initGCPCredentials writes a temporary GCS credentials file if necessary and
// returns the path and a function to clean it up. allAuthenticatedUsers can
// access go-getter-test with read only access.
func initGCPCredentials(t *testing.T) func() {
if gc := os.Getenv("GOOGLE_CREDENTIALS"); gc != "" &&
os.Getenv("GOOGLE_APPLICATION_CREDENTIALS") == "" {
file, cleanup := testing_helper.TempFileWithContent(t, gc)
os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", file)
return func() {
os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", "")
cleanup()
}
}
return func() {}
}
// Note for external contributors: In order to run the GCS test suite, you will only be able to be run these tests
// in GitHub Actions when you open a PR.

func TestGetter_impl(t *testing.T) {
var _ getter.Getter = new(Getter)
}

func TestGetter(t *testing.T) {
defer initGCPCredentials(t)()

g := new(Getter)
dst := testing_helper.TempDir(t)
ctx := context.Background()

req := &getter.Request{
Src: "www.googleapis.com/storage/v1/go-getter-test/go-getter/folder",
Src: "www.googleapis.com/storage/v1/hc-go-getter-test/go-getter/folder",
Dst: dst,
}

Expand All @@ -63,14 +49,13 @@ func TestGetter(t *testing.T) {
}

func TestGetter_subdir(t *testing.T) {
defer initGCPCredentials(t)()

g := new(Getter)
dst := testing_helper.TempDir(t)
ctx := context.Background()

req := &getter.Request{
Src: "www.googleapis.com/storage/v1/go-getter-test/go-getter/folder/subfolder",
Src: "www.googleapis.com/storage/v1/hc-go-getter-test/go-getter/folder/subfolder",
Dst: dst,
}

Expand All @@ -92,15 +77,14 @@ func TestGetter_subdir(t *testing.T) {
}

func TestGetter_GetFile(t *testing.T) {
defer initGCPCredentials(t)()

g := new(Getter)
dst := testing_helper.TempTestFile(t)
defer os.RemoveAll(filepath.Dir(dst))
ctx := context.Background()

req := &getter.Request{
Src: "www.googleapis.com/storage/v1/go-getter-test/go-getter/folder/main.tf",
Src: "www.googleapis.com/storage/v1/hc-go-getter-test/go-getter/folder/main.tf",
Dst: dst,
GetMode: getter.ModeFile,
}
Expand Down Expand Up @@ -129,7 +113,7 @@ func TestGetter_GetFile_notfound(t *testing.T) {
ctx := context.Background()

req := &getter.Request{
Src: "https://www.googleapis.com/storage/v1/go-getter-test/go-getter/folder/404.tf",
Src: "https://www.googleapis.com/storage/v1/hc-go-getter-test/go-getter/folder/404.tf",
Dst: dst,
}

Expand All @@ -145,14 +129,13 @@ func TestGetter_GetFile_notfound(t *testing.T) {
}

func TestGetter_Mode_dir(t *testing.T) {
defer initGCPCredentials(t)()

g := new(Getter)
ctx := context.Background()

// Check client mode on a key prefix with only a single key.
mode, err := g.Mode(ctx,
urlhelper.MustParse("https://www.googleapis.com/storage/v1/go-getter-test/go-getter/folder/subfolder"))
urlhelper.MustParse("https://www.googleapis.com/storage/v1/hc-go-getter-test/go-getter/folder/subfolder"))
if err != nil {
t.Fatalf("err: %s", err)
}
Expand All @@ -162,14 +145,13 @@ func TestGetter_Mode_dir(t *testing.T) {
}

func TestGetter_Mode_file(t *testing.T) {
defer initGCPCredentials(t)()

g := new(Getter)
ctx := context.Background()

// Check client mode on a key prefix which contains sub-keys.
mode, err := g.Mode(ctx,
urlhelper.MustParse("https://www.googleapis.com/storage/v1/go-getter-test/go-getter/folder/subfolder/sub.tf"))
urlhelper.MustParse("https://www.googleapis.com/storage/v1/hc-go-getter-test/go-getter/folder/subfolder/sub.tf"))
if err != nil {
t.Fatalf("err: %s", err)
}
Expand All @@ -179,15 +161,13 @@ func TestGetter_Mode_file(t *testing.T) {
}

func TestGetter_Mode_notfound(t *testing.T) {
defer initGCPCredentials(t)()

g := new(Getter)
ctx := context.Background()

// Check the client mode when a non-existent key is looked up. This does not
// return an error, but rather should just return the file mode.
mode, err := g.Mode(ctx,
urlhelper.MustParse("https://www.googleapis.com/storage/v1/go-getter-test/go-getter/foobar"))
urlhelper.MustParse("https://www.googleapis.com/storage/v1/hc-go-getter-test/go-getter/foobar"))
if err != nil {
t.Fatalf("err: %s", err)
}
Expand All @@ -197,7 +177,6 @@ func TestGetter_Mode_notfound(t *testing.T) {
}

func TestGetter_Url(t *testing.T) {
defer initGCPCredentials(t)()

var gcstests = []struct {
name string
Expand All @@ -207,8 +186,8 @@ func TestGetter_Url(t *testing.T) {
}{
{
name: "test1",
url: "https://www.googleapis.com/storage/v1/go-getter-test/go-getter/foo/null.zip",
bucket: "go-getter-test",
url: "https://www.googleapis.com/storage/v1/hc-go-getter-test/go-getter/foo/null.zip",
bucket: "hc-go-getter-test",
path: "go-getter/foo/null.zip",
},
}
Expand Down
16 changes: 14 additions & 2 deletions gcs/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@ go 1.14
replace github.com/hashicorp/go-getter/v2 => ../

require (
cloud.google.com/go/storage v1.6.0
cloud.google.com/go/compute v1.12.1 // indirect
cloud.google.com/go/compute/metadata v0.1.1 // indirect
cloud.google.com/go/storage v1.27.0
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-getter/v2 v2.1.0
google.golang.org/api v0.21.0
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
golang.org/x/oauth2 v0.1.0 // indirect
google.golang.org/api v0.101.0
google.golang.org/genproto v0.0.0-20221027153422-115e99e71e1c // indirect
)
Loading