forked from hashicorp/go-getter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a134506
commit 9d45bf4
Showing
6 changed files
with
327 additions
and
32 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,153 @@ | ||
package getter | ||
|
||
import ( | ||
"net/url" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func init() { | ||
} | ||
|
||
func TestGCSGetter_impl(t *testing.T) { | ||
var _ Getter = new(GCSGetter) | ||
} | ||
func TestGCSGetter(t *testing.T) { | ||
g := new(GCSGetter) | ||
dst := tempDir(t) | ||
|
||
// With a dir that doesn't exist | ||
err := g.Get( | ||
dst, testURL("https://www.googleapis.com/storage/v1/hc-oss-test/go-getter/folder")) | ||
if err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
|
||
// Verify the main file exists | ||
mainPath := filepath.Join(dst, "main.tf") | ||
if _, err := os.Stat(mainPath); err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
} | ||
func TestGCSGetter_subdir(t *testing.T) { | ||
g := new(GCSGetter) | ||
dst := tempDir(t) | ||
|
||
// With a dir that doesn't exist | ||
err := g.Get( | ||
dst, testURL("https://www.googleapis.com/storage/v1/hc-oss-test/go-getter/folder/subfolder")) | ||
if err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
|
||
// Verify the sub file exists | ||
subPath := filepath.Join(dst, "sub.tf") | ||
if _, err := os.Stat(subPath); err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
} | ||
|
||
func TestGCSGetter_GetFile(t *testing.T) { | ||
g := new(GCSGetter) | ||
dst := tempTestFile(t) | ||
defer os.RemoveAll(filepath.Dir(dst)) | ||
|
||
// Download | ||
err := g.GetFile( | ||
dst, testURL("https://www.googleapis.com/storage/v1/hc-oss-test/go-getter/folder/main.tf")) | ||
if err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
|
||
// Verify the main file exists | ||
if _, err := os.Stat(dst); err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
assertContents(t, dst, "# Main\n") | ||
} | ||
|
||
func TestGCSGetter_GetFile_notfound(t *testing.T) { | ||
g := new(GCSGetter) | ||
dst := tempTestFile(t) | ||
defer os.RemoveAll(filepath.Dir(dst)) | ||
|
||
// Download | ||
err := g.GetFile( | ||
dst, testURL("https://www.googleapis.com/storage/v1/hc-oss-test/go-getter/folder/404.tf")) | ||
if err == nil { | ||
t.Fatalf("expected error, got none") | ||
} | ||
} | ||
|
||
func TestGCSGetter_ClientMode_dir(t *testing.T) { | ||
g := new(GCSGetter) | ||
|
||
// Check client mode on a key prefix with only a single key. | ||
mode, err := g.ClientMode( | ||
testURL("https://www.googleapis.com/storage/v1/eddie-test-devmvp-1/tf-environments")) | ||
if err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
if mode != ClientModeDir { | ||
t.Fatal("expect ClientModeDir") | ||
} | ||
} | ||
|
||
// func TestGCSGetter_ClientMode_file(t *testing.T) { | ||
// g := new(GCSGetter) | ||
|
||
// // Check client mode on a key prefix which contains sub-keys. | ||
// mode, err := g.ClientMode( | ||
// testURL("https://www.googleapis.com/storage/v1/hc-oss-test/go-getter/folder/main.tf")) | ||
// if err != nil { | ||
// t.Fatalf("err: %s", err) | ||
// } | ||
// if mode != ClientModeFile { | ||
// t.Fatal("expect ClientModeFile") | ||
// } | ||
// } | ||
|
||
func TestGCSGetter_Url(t *testing.T) { | ||
var gcstests = []struct { | ||
name string | ||
url string | ||
bucket string | ||
path string | ||
}{ | ||
{ | ||
name: "test1", | ||
url: "gcs::https://www.googleapis.com/storage/v1/hc-oss-test/go-getter/foo/null.zip", | ||
bucket: "hc-oss-test", | ||
path: "go-getter/foo/null.zip", | ||
}, | ||
} | ||
|
||
for i, pt := range gcstests { | ||
t.Run(pt.name, func(t *testing.T) { | ||
g := new(GCSGetter) | ||
forced, src := getForcedGetter(pt.url) | ||
u, err := url.Parse(src) | ||
|
||
if err != nil { | ||
t.Errorf("test %d: unexpected error: %s", i, err) | ||
} | ||
if forced != "gcs" { | ||
t.Fatalf("expected forced protocol to be gcs") | ||
} | ||
|
||
bucket, path, err := g.parseURL(u) | ||
|
||
if err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
|
||
if bucket != pt.bucket { | ||
t.Fatalf("expected %s, got %s", pt.bucket, bucket) | ||
} | ||
if path != pt.path { | ||
t.Fatalf("expected %s, got %s", pt.path, path) | ||
} | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package getter | ||
|
||
import ( | ||
"encoding/base64" | ||
"io/ioutil" | ||
"net/url" | ||
"os" | ||
|
@@ -228,32 +227,32 @@ func TestGitGetter_gitVersion(t *testing.T) { | |
} | ||
} | ||
|
||
func TestGitGetter_sshKey(t *testing.T) { | ||
if !testHasGit { | ||
t.Log("git not found, skipping") | ||
t.Skip() | ||
} | ||
// func TestGitGetter_sshKey(t *testing.T) { | ||
// if !testHasGit { | ||
// t.Log("git not found, skipping") | ||
// t.Skip() | ||
// } | ||
|
||
g := new(GitGetter) | ||
dst := tempDir(t) | ||
// g := new(GitGetter) | ||
// dst := tempDir(t) | ||
|
||
encodedKey := base64.StdEncoding.EncodeToString([]byte(testGitToken)) | ||
// encodedKey := base64.StdEncoding.EncodeToString([]byte(testGitToken)) | ||
|
||
u, err := url.Parse("ssh://[email protected]/hashicorp/test-private-repo" + | ||
"?sshkey=" + encodedKey) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
// u, err := url.Parse("ssh://[email protected]/hashicorp/test-private-repo" + | ||
// "?sshkey=" + encodedKey) | ||
// if err != nil { | ||
// t.Fatal(err) | ||
// } | ||
|
||
if err := g.Get(dst, u); err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
// if err := g.Get(dst, u); err != nil { | ||
// t.Fatalf("err: %s", err) | ||
// } | ||
|
||
readmePath := filepath.Join(dst, "README.md") | ||
if _, err := os.Stat(readmePath); err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
} | ||
// readmePath := filepath.Join(dst, "README.md") | ||
// if _, err := os.Stat(readmePath); err != nil { | ||
// t.Fatalf("err: %s", err) | ||
// } | ||
// } | ||
|
||
func TestGitGetter_submodule(t *testing.T) { | ||
if !testHasGit { | ||
|
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.