-
Notifications
You must be signed in to change notification settings - Fork 244
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
Fix Go Tests for V2 #392
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,10 @@ jobs: | |
- 1.17 | ||
- 1.18 | ||
- 1.19 | ||
directory: | ||
- s3 | ||
- gcs | ||
- . | ||
permissions: | ||
id-token: write | ||
contents: read | ||
|
@@ -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" | ||
|
@@ -101,6 +106,10 @@ jobs: | |
- 1.17 | ||
- 1.18 | ||
- 1.19 | ||
directory: | ||
- s3 | ||
- gcs | ||
- . | ||
permissions: | ||
id-token: write | ||
contents: read | ||
|
@@ -112,7 +121,7 @@ jobs: | |
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
|
@@ -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: | ||
|
@@ -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 | ||
|
@@ -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" | ||
|
@@ -167,7 +177,7 @@ jobs: | |
with: | ||
name: windows test results | ||
path: ${{ env.TEST_RESULTS_PATH }} | ||
|
||
go-smb-tests: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
|
@@ -184,7 +194,7 @@ jobs: | |
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
|
@@ -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_" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
// 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, | ||
} | ||
|
||
|
@@ -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, | ||
} | ||
|
||
|
@@ -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, | ||
} | ||
|
@@ -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, | ||
} | ||
|
||
|
@@ -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) | ||
} | ||
|
@@ -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) | ||
} | ||
|
@@ -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) | ||
} | ||
|
@@ -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 | ||
|
@@ -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", | ||
}, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.