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

chore: remove refs to deprecated io/ioutil #346

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
11 changes: 5 additions & 6 deletions cmd/cpp/functions_framework/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package main

import (
"io/ioutil"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -191,7 +190,7 @@ func TestPopulateMainLayer(t *testing.T) {
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
tmpDir, err := ioutil.TempDir("", tc.name)
tmpDir, err := os.MkdirTemp("", tc.name)
if err != nil {
t.Fatalf("creating temp dir: %v", err)
}
Expand All @@ -213,28 +212,28 @@ func TestPopulateMainLayer(t *testing.T) {

for _, name := range []string{"CMakeLists.txt", "vcpkg.json"} {
path := filepath.Join(converter, name)
if ioutil.WriteFile(path, []byte(converterFileContents), 0644); err != nil {
if os.WriteFile(path, []byte(converterFileContents), 0644); err != nil {
t.Fatalf("writing fake C++ support file (path=%s): %v", path, err)
}
}
for _, name := range tc.sourceFiles {
path := filepath.Join(fakeApp, name)
if ioutil.WriteFile(path, []byte(generatedFileContents), 0644); err != nil {
if os.WriteFile(path, []byte(generatedFileContents), 0644); err != nil {
t.Fatalf("writing test C++ build file (name=%s): %v", name, err)
}
}
if err := createMainCppSupportFiles(ctx, fakeMain, fakeBuildpackRoot); err != nil {
t.Fatalf("creating support files in main layer: %v", err)
}
vcpkgContents, err := ioutil.ReadFile(filepath.Join(fakeMain, "vcpkg.json"))
vcpkgContents, err := os.ReadFile(filepath.Join(fakeMain, "vcpkg.json"))
if err != nil {
t.Fatalf("reading vcpkg.json from main layer: %v", err)
}
if string(vcpkgContents) != tc.vcpkgJSONContents {
t.Errorf("mismatched contents in vcpkg.json, got=%s, want=%s", string(vcpkgContents), tc.vcpkgJSONContents)
}

cmakeContents, err := ioutil.ReadFile(filepath.Join(fakeMain, "CMakeLists.txt"))
cmakeContents, err := os.ReadFile(filepath.Join(fakeMain, "CMakeLists.txt"))
if err != nil {
t.Fatalf("reading CMakeLists.txt from main layer: %v", err)
}
Expand Down
11 changes: 5 additions & 6 deletions cmd/dotnet/publish/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package main

import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -82,14 +81,14 @@ func TestGetAssemblyName(t *testing.T) {
for _, tc := range tcs {
ctx := gcp.NewContext()
t.Run(tc.name, func(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "dotnettest")
tmpDir, err := os.MkdirTemp("", "dotnettest")
if err != nil {
t.Fatalf("creating temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)

filename := filepath.Join(tmpDir, "app.csproj")
if err = ioutil.WriteFile(filename, []byte(tc.data), 0644); err != nil {
if err = os.WriteFile(filename, []byte(tc.data), 0644); err != nil {
t.Fatalf("writing project file: %v", err)
}

Expand Down Expand Up @@ -159,7 +158,7 @@ func TestGetEntrypoint(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx := gcp.NewContext()

tmpDir, err := ioutil.TempDir("", "dotnettest")
tmpDir, err := os.MkdirTemp("", "dotnettest")
if err != nil {
t.Fatalf("creating temp dir: %v", err)
}
Expand All @@ -171,13 +170,13 @@ func TestGetEntrypoint(t *testing.T) {

// Write the expected exe file.
exe := filepath.Join(tmpDir, tc.exe)
if err = ioutil.WriteFile(exe, []byte(""), 0644); err != nil {
if err = os.WriteFile(exe, []byte(""), 0644); err != nil {
t.Fatalf("writing exe file: %v", err)
}

// Write the project file.
proj := filepath.Join(tmpDir, tc.proj)
if err = ioutil.WriteFile(proj, []byte(tc.data), 0644); err != nil {
if err = os.WriteFile(proj, []byte(tc.data), 0644); err != nil {
t.Fatalf("writing proj file: %v", err)
}

Expand Down
5 changes: 2 additions & 3 deletions cmd/go/appengine_gomod/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package main

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -105,7 +104,7 @@ func TestMainPath(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
dir, err := ioutil.TempDir("", "TestMainPath-")
dir, err := os.MkdirTemp("", "TestMainPath-")
if err != nil {
t.Fatalf("Creating temporary directory: %v", err)
}
Expand All @@ -118,7 +117,7 @@ func TestMainPath(t *testing.T) {
ctx := gcp.NewContext(gcp.WithApplicationRoot(dir))

if tc.stagerFileContents != "" {
if err = ioutil.WriteFile(filepath.Join(dir, "_main-package-path"), []byte(tc.stagerFileContents), 0755); err != nil {
if err = os.WriteFile(filepath.Join(dir, "_main-package-path"), []byte(tc.stagerFileContents), 0755); err != nil {
t.Fatalf("Creating file in temporary directory: %v", err)
}
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/go/flex_gomod/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package main

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -91,7 +90,7 @@ func TestMainPath(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
dir, err := ioutil.TempDir("", "TestMainPath-")
dir, err := os.MkdirTemp("", "TestMainPath-")
if err != nil {
t.Fatalf("Creating temporary directory: %v", err)
}
Expand All @@ -104,7 +103,7 @@ func TestMainPath(t *testing.T) {
ctx := gcp.NewContext(gcp.WithApplicationRoot(dir))

if tc.stagerFileContents != "" {
if err = ioutil.WriteFile(filepath.Join(dir, "_main-package-path"), []byte(tc.stagerFileContents), 0755); err != nil {
if err = os.WriteFile(filepath.Join(dir, "_main-package-path"), []byte(tc.stagerFileContents), 0755); err != nil {
t.Fatalf("Creating file in temporary directory: %v", err)
}
}
Expand Down
9 changes: 4 additions & 5 deletions cmd/go/functions_framework/converter/get_package/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package main

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -109,7 +108,7 @@ func init() {

for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
dir, err := ioutil.TempDir("", "golang_bp_test")
dir, err := os.MkdirTemp("", "golang_bp_test")
if err != nil {
t.Fatalf("creating temp dir: %v", err)
}
Expand All @@ -121,7 +120,7 @@ func init() {
}()

for f, c := range tc.files {
if err := ioutil.WriteFile(filepath.Join(dir, f), []byte(c), 0644); err != nil {
if err := os.WriteFile(filepath.Join(dir, f), []byte(c), 0644); err != nil {
t.Fatalf("writing file %s: %v", f, err)
}
}
Expand Down Expand Up @@ -159,7 +158,7 @@ func TestExtractFailures(t *testing.T) {

for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
dir, err := ioutil.TempDir("", "golang_bp_test")
dir, err := os.MkdirTemp("", "golang_bp_test")
if err != nil {
t.Fatalf("creating temp dir: %v", err)
}
Expand All @@ -171,7 +170,7 @@ func TestExtractFailures(t *testing.T) {
}()

for f, c := range tc.files {
if err := ioutil.WriteFile(filepath.Join(dir, f), []byte(c), 0644); err != nil {
if err := os.WriteFile(filepath.Join(dir, f), []byte(c), 0644); err != nil {
t.Fatalf("writing file %s: %v", f, err)
}
}
Expand Down
9 changes: 4 additions & 5 deletions cmd/go/legacy_worker/converter/get_package/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package main

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -44,7 +43,7 @@ func TestExtractPackageNameFromDir(t *testing.T) {

for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
dir, err := ioutil.TempDir("", "golang_bp_test")
dir, err := os.MkdirTemp("", "golang_bp_test")
if err != nil {
t.Fatalf("creating temp dir: %v", err)
}
Expand All @@ -56,7 +55,7 @@ func TestExtractPackageNameFromDir(t *testing.T) {
}()

for f, c := range tc.files {
if err := ioutil.WriteFile(filepath.Join(dir, f), []byte(c), 0644); err != nil {
if err := os.WriteFile(filepath.Join(dir, f), []byte(c), 0644); err != nil {
t.Fatalf("writing file %s: %v", f, err)
}
}
Expand Down Expand Up @@ -98,7 +97,7 @@ func TestExtractPackageNameFromDirErrors(t *testing.T) {

for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
dir, err := ioutil.TempDir("", "golang_bp_test")
dir, err := os.MkdirTemp("", "golang_bp_test")
if err != nil {
t.Fatalf("creating temp dir: %v", err)
}
Expand All @@ -110,7 +109,7 @@ func TestExtractPackageNameFromDirErrors(t *testing.T) {
}()

for f, c := range tc.files {
if err := ioutil.WriteFile(filepath.Join(dir, f), []byte(c), 0644); err != nil {
if err := os.WriteFile(filepath.Join(dir, f), []byte(c), 0644); err != nil {
t.Fatalf("writing file %s: %v", f, err)
}
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/go/legacy_worker/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package main

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -110,7 +109,7 @@ func TestCreateMainGoFile(t *testing.T) {
t.Fatalf("error creating file at path %q from worker template: %s", targetMain, err)
}

b, err := ioutil.ReadFile(targetMain)
b, err := os.ReadFile(targetMain)
if err != nil {
t.Fatalf("error reading file at path %q: %s", targetMain, err)
}
Expand Down Expand Up @@ -151,7 +150,7 @@ replace fnmod => ./serverless_function_source_code`
t.Fatalf("error creating file at path %q from go.mod template: %s", targetGoMod, err)
}

b, err := ioutil.ReadFile(targetGoMod)
b, err := os.ReadFile(targetGoMod)
if err != nil {
t.Fatalf("error reading file at path %q: %s", targetGoMod, err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/java/maven/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -178,7 +177,7 @@ func addJvmConfig(ctx *gcp.Context) error {
return nil
}
jvmOptions := "--add-opens java.base/java.lang=ALL-UNNAMED"
if err := ioutil.WriteFile(configFile, []byte(jvmOptions), 0644); err != nil {
if err := os.WriteFile(configFile, []byte(jvmOptions), 0644); err != nil {
ctx.Logf("Could not create %s, reflection warnings may not be disabled: %v", configFile, err)
}
return nil
Expand Down
3 changes: 1 addition & 2 deletions cmd/java/maven/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"strconv"
"testing"
Expand Down Expand Up @@ -105,7 +104,7 @@ func TestCrLfRewrite(t *testing.T) {

ensureUnixLineEndings(gcp.NewContext(), tmpFile.Name())

newContent, err := ioutil.ReadFile(tmpFile.Name())
newContent, err := os.ReadFile(tmpFile.Name())
if err != nil {
t.Fatal("Error reading updated temporary file", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/java/native_image/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package main
import (
"archive/zip"
"bytes"
"io/ioutil"
"os"
"path"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -194,7 +194,7 @@ func setupTestJar(t *testing.T, mfContent []byte) string {
}

jarPath := filepath.Join(t.TempDir(), "test.jar")
if err := ioutil.WriteFile(jarPath, buff.Bytes(), 0644); err != nil {
if err := os.WriteFile(jarPath, buff.Bytes(), 0644); err != nil {
t.Fatalf("failed to write to file %s: %v", jarPath, err)
}
return jarPath
Expand Down
5 changes: 2 additions & 3 deletions cmd/ruby/appengine/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package main

import (
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -116,7 +115,7 @@ func TestEntrypoint(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
tempDir, err := ioutil.TempDir("", "test-entrypoint-")
tempDir, err := os.MkdirTemp("", "test-entrypoint-")
if err != nil {
t.Fatalf("creating temp dir: %v", err)
}
Expand All @@ -131,7 +130,7 @@ func TestEntrypoint(t *testing.T) {
if err := os.MkdirAll(path.Dir(fn), 0755); err != nil {
t.Fatalf("creating dir %s: %v", path.Dir(fn), err)
}
if err := ioutil.WriteFile(fn, []byte("content"), 0644); err != nil {
if err := os.WriteFile(fn, []byte("content"), 0644); err != nil {
t.Fatalf("writing file %s: %v", fn, err)
}
}
Expand Down
11 changes: 5 additions & 6 deletions cmd/utils/archive_source/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package main

import (
"bytes"
"io/ioutil"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -125,7 +124,7 @@ func TestArchiveSource(t *testing.T) {
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
appDir, err := ioutil.TempDir("", "app")
appDir, err := os.MkdirTemp("", "app")
if err != nil {
t.Fatalf("creating temp dir: %v", err)
}
Expand All @@ -143,7 +142,7 @@ func TestArchiveSource(t *testing.T) {

// File can be a normal file, symlink, or an empty directory.
if f.Content != "" {
if err := ioutil.WriteFile(fn, []byte(f.Content), 0644); err != nil {
if err := os.WriteFile(fn, []byte(f.Content), 0644); err != nil {
t.Fatalf("writing file %s: %v", fn, err)
}
} else if f.SymLink != "" {
Expand All @@ -159,7 +158,7 @@ func TestArchiveSource(t *testing.T) {
}

// Archive the files in the app directory.
srcDir, err := ioutil.TempDir("", "src")
srcDir, err := os.MkdirTemp("", "src")
if err != nil {
t.Fatalf("creating temp dir: %v", err)
}
Expand Down Expand Up @@ -211,11 +210,11 @@ func TestArchiveSource(t *testing.T) {

// Compare file content if they are not directories.
if !afi.IsDir() {
ac, err := ioutil.ReadFile(af)
ac, err := os.ReadFile(af)
if err != nil {
t.Fatalf("reading file %s: %v", af, err)
}
sc, err := ioutil.ReadFile(sf)
sc, err := os.ReadFile(sf)
if err != nil {
t.Fatalf("reading file %s: %v", sf, err)
}
Expand Down
Loading