|
1 | 1 | package getter
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "io/ioutil" |
4 | 5 | "net/url"
|
5 | 6 | "os"
|
6 | 7 | "path/filepath"
|
@@ -88,6 +89,47 @@ func TestGCSGetter_GetFile(t *testing.T) {
|
88 | 89 | assertContents(t, dst, "# Main\n")
|
89 | 90 | }
|
90 | 91 |
|
| 92 | +func TestGCSGetter_GetGenerationFile(t *testing.T) { |
| 93 | + defer initGCPCredentials(t)() |
| 94 | + |
| 95 | + g := new(GCSGetter) |
| 96 | + dst := tempTestFile(t) |
| 97 | + defer os.RemoveAll(filepath.Dir(dst)) |
| 98 | + |
| 99 | + // Download |
| 100 | + err := g.GetFile( |
| 101 | + dst, testURL("https://www.googleapis.com/storage/v1/go-getter-testcase-data/DO_NOT_DELETE/generation_test.txt#1614317688843055")) |
| 102 | + if err != nil { |
| 103 | + t.Fatalf("err: %s", err) |
| 104 | + } |
| 105 | + |
| 106 | + // Verify the main file exists |
| 107 | + content, err := ioutil.ReadFile(dst) |
| 108 | + if err != nil { |
| 109 | + t.Fatalf("err: %s", err) |
| 110 | + } |
| 111 | + if string(content) != "a" { |
| 112 | + t.Fatalf("expected file contents from generation to be `a` but got `%s`", content) |
| 113 | + } |
| 114 | + |
| 115 | + // Download |
| 116 | + err = g.GetFile( |
| 117 | + dst, testURL("https://www.googleapis.com/storage/v1/go-getter-testcase-data/DO_NOT_DELETE/generation_test.txt#1614317705239142")) |
| 118 | + if err != nil { |
| 119 | + t.Fatalf("err: %s", err) |
| 120 | + } |
| 121 | + |
| 122 | + // Verify the main file exists |
| 123 | + content, err = ioutil.ReadFile(dst) |
| 124 | + if err != nil { |
| 125 | + t.Fatalf("err: %s", err) |
| 126 | + } |
| 127 | + if string(content) != "b" { |
| 128 | + t.Fatalf("expected file contents from generation to be `a` but got `%s`", content) |
| 129 | + } |
| 130 | + |
| 131 | +} |
| 132 | + |
91 | 133 | func TestGCSGetter_GetFile_notfound(t *testing.T) {
|
92 | 134 | g := new(GCSGetter)
|
93 | 135 | dst := tempTestFile(t)
|
@@ -180,7 +222,7 @@ func TestGCSGetter_Url(t *testing.T) {
|
180 | 222 | t.Fatalf("expected forced protocol to be gcs")
|
181 | 223 | }
|
182 | 224 |
|
183 |
| - bucket, path, err := g.parseURL(u) |
| 225 | + bucket, path, _, err := g.parseURL(u) |
184 | 226 |
|
185 | 227 | if err != nil {
|
186 | 228 | t.Fatalf("err: %s", err)
|
|
0 commit comments