Skip to content

Commit d9c501c

Browse files
Sophie WigmoreForestEckhardt
Sophie Wigmore
authored andcommitted
Updates decompression logic
- vacation is about to remove the TarGzipArchive in favor of wrapped compression type into archive type. I have moved from specifying the type of archive to using to generic archive type (long overdue hooray!) - I removed the ioutil library as it is deprecated Signed-off-by: Forest Eckhardt <[email protected]>
1 parent 7b23af5 commit d9c501c

9 files changed

+91
-96
lines changed

cache_manager_test.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package freezer_test
33
import (
44
"bytes"
55
"encoding/gob"
6-
"io/ioutil"
76
"os"
87
"path/filepath"
98
"testing"
@@ -25,7 +24,7 @@ func testCacheManager(t *testing.T, context spec.G, it spec.S) {
2524

2625
it.Before(func() {
2726
var err error
28-
cacheDir, err = ioutil.TempDir("", "cache")
27+
cacheDir, err = os.MkdirTemp("", "cache")
2928
Expect(err).ToNot(HaveOccurred())
3029

3130
cacheManager = freezer.NewCacheManager(cacheDir)
@@ -46,7 +45,7 @@ func testCacheManager(t *testing.T, context spec.G, it spec.S) {
4645
err := gob.NewEncoder(b).Encode(&inputMap)
4746
Expect(err).ToNot(HaveOccurred())
4847

49-
Expect(ioutil.WriteFile(filepath.Join(cacheDir, "buildpacks-cache.db"), b.Bytes(), os.ModePerm))
48+
Expect(os.WriteFile(filepath.Join(cacheDir, "buildpacks-cache.db"), b.Bytes(), os.ModePerm))
5049
})
5150

5251
it("returns the cache map stored in the buildpacks-cache.db folder", func() {
@@ -84,7 +83,7 @@ func testCacheManager(t *testing.T, context spec.G, it spec.S) {
8483

8584
context("unable to open the buildpack-cache.db", func() {
8685
it.Before(func() {
87-
Expect(ioutil.WriteFile(filepath.Join(cacheDir, "buildpacks-cache.db"), []byte{}, 0000))
86+
Expect(os.WriteFile(filepath.Join(cacheDir, "buildpacks-cache.db"), []byte{}, 0000))
8887
})
8988
it("returns an error", func() {
9089
err := cacheManager.Open()
@@ -94,7 +93,7 @@ func testCacheManager(t *testing.T, context spec.G, it spec.S) {
9493

9594
context("unable to open the buildpack-cache.db", func() {
9695
it.Before(func() {
97-
Expect(ioutil.WriteFile(filepath.Join(cacheDir, "buildpacks-cache.db"), []byte(`%%%`), os.ModePerm))
96+
Expect(os.WriteFile(filepath.Join(cacheDir, "buildpacks-cache.db"), []byte(`%%%`), os.ModePerm))
9897
})
9998
it("returns an error", func() {
10099
err := cacheManager.Open()
@@ -142,7 +141,7 @@ func testCacheManager(t *testing.T, context spec.G, it spec.S) {
142141
context("when the key exists", func() {
143142
context("and the file in uri exists", func() {
144143
it.Before(func() {
145-
Expect(ioutil.WriteFile(uri, []byte(`some-content`), 0644)).To(Succeed())
144+
Expect(os.WriteFile(uri, []byte(`some-content`), 0644)).To(Succeed())
146145
})
147146

148147
it("returns the entry and ok", func() {
@@ -175,7 +174,7 @@ func testCacheManager(t *testing.T, context spec.G, it spec.S) {
175174
context("failure cases", func() {
176175
context("the cached file is cannot be stated", func() {
177176
it.Before(func() {
178-
Expect(ioutil.WriteFile(uri, []byte(`some-content`), 0644)).To(Succeed())
177+
Expect(os.WriteFile(uri, []byte(`some-content`), 0644)).To(Succeed())
179178

180179
Expect(os.Chmod(cacheDir, 0000)).To(Succeed())
181180
})
@@ -201,7 +200,7 @@ func testCacheManager(t *testing.T, context spec.G, it spec.S) {
201200

202201
uri = filepath.Join(cacheDir, "some-file")
203202

204-
Expect(ioutil.WriteFile(uri, []byte(`some content`), 0644)).To(Succeed())
203+
Expect(os.WriteFile(uri, []byte(`some content`), 0644)).To(Succeed())
205204

206205
cacheManager.Cache = freezer.CacheDB{"some-buildpack": freezer.CacheEntry{Version: "1.2.3", URI: uri}}
207206
})

file_system_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package freezer_test
22

33
import (
4-
"io/ioutil"
54
"os"
65
"testing"
76

@@ -15,7 +14,7 @@ func testFileSystem(t *testing.T, context spec.G, it spec.S) {
1514

1615
context("TempDir", func() {
1716
it("returns the value given from the TempDir function", func() {
18-
filename, err := ioutil.TempDir("", "tempDir")
17+
filename, err := os.MkdirTemp("", "tempDir")
1918
defer os.RemoveAll(filename)
2019

2120
fileSystem := freezer.NewFileSystem(func(string, string) (string, error) {

github/release_service_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package github_test
22

33
import (
44
"fmt"
5-
"io/ioutil"
5+
"io"
66
"net/http"
77
"net/http/httptest"
88
"net/http/httputil"
@@ -178,7 +178,7 @@ func testReleaseService(t *testing.T, context spec.G, it spec.S) {
178178
})
179179
Expect(err).ToNot(HaveOccurred())
180180

181-
content, err := ioutil.ReadAll(response)
181+
content, err := io.ReadAll(response)
182182
Expect(err).ToNot(HaveOccurred())
183183
Expect(string(content)).To(Equal("some-asset"))
184184

@@ -214,7 +214,7 @@ func testReleaseService(t *testing.T, context spec.G, it spec.S) {
214214
})
215215
Expect(err).ToNot(HaveOccurred())
216216

217-
content, err := ioutil.ReadAll(response)
217+
content, err := io.ReadAll(response)
218218
Expect(err).ToNot(HaveOccurred())
219219
Expect(string(content)).To(Equal("some-asset"))
220220

@@ -287,7 +287,7 @@ func testReleaseService(t *testing.T, context spec.G, it spec.S) {
287287
response, err := service.GetReleaseTarball(fmt.Sprintf("%s/some-tarball-url", api.URL))
288288
Expect(err).ToNot(HaveOccurred())
289289

290-
content, err := ioutil.ReadAll(response)
290+
content, err := io.ReadAll(response)
291291
Expect(err).ToNot(HaveOccurred())
292292
Expect(string(content)).To(Equal("some-tarball"))
293293

@@ -321,7 +321,7 @@ func testReleaseService(t *testing.T, context spec.G, it spec.S) {
321321
response, err := service.GetReleaseTarball(fmt.Sprintf("%s/some-tarball-url", api.URL))
322322
Expect(err).ToNot(HaveOccurred())
323323

324-
content, err := ioutil.ReadAll(response)
324+
content, err := io.ReadAll(response)
325325
Expect(err).ToNot(HaveOccurred())
326326
Expect(string(content)).To(Equal("some-tarball"))
327327

go.mod

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
module github.com/ForestEckhardt/freezer
22

3-
go 1.13
3+
go 1.16
44

55
require (
66
github.com/oklog/ulid v1.3.1
7-
github.com/onsi/gomega v1.10.4
8-
github.com/paketo-buildpacks/occam v0.0.22
9-
github.com/paketo-buildpacks/packit v0.5.0
7+
github.com/onsi/gomega v1.17.0
8+
github.com/paketo-buildpacks/occam v0.2.0
9+
github.com/paketo-buildpacks/packit v1.3.1
1010
github.com/sclevine/spec v1.4.0
11+
golang.org/x/net v0.0.0-20211201190559-0a0e4e1bb54c // indirect
12+
golang.org/x/text v0.3.7 // indirect
1113
)

0 commit comments

Comments
 (0)