Skip to content

Commit

Permalink
Migrate code to 1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
mortent committed Aug 8, 2022
1 parent 8bd678d commit c39f492
Show file tree
Hide file tree
Showing 70 changed files with 249 additions and 290 deletions.
6 changes: 3 additions & 3 deletions internal/builtins/pkg_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package builtins

import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"testing"

Expand Down Expand Up @@ -52,10 +52,10 @@ func TestPkgContextGenerator(t *testing.T) {
pkgCtxGenerator := &PackageContextGenerator{}
out := &bytes.Buffer{}

in, err := ioutil.ReadFile(filepath.Join("testdata", test.dir, "in.yaml"))
in, err := os.ReadFile(filepath.Join("testdata", test.dir, "in.yaml"))
assert.NoError(t, err)

exp, err := ioutil.ReadFile(filepath.Join("testdata", test.dir, "out.yaml"))
exp, err := os.ReadFile(filepath.Join("testdata", test.dir, "out.yaml"))
assert.NoError(t, err)

err = pkgCtxGenerator.Run(bytes.NewReader(in), out)
Expand Down
11 changes: 5 additions & 6 deletions internal/cmdinit/cmdinit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package cmdinit_test

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

// verify the contents
b, err := ioutil.ReadFile(filepath.Join(d, "my-pkg", "Kptfile"))
b, err := os.ReadFile(filepath.Join(d, "my-pkg", "Kptfile"))
assert.NoError(t, err)
assert.Equal(t, `apiVersion: kpt.dev/v1
kind: Kptfile
Expand All @@ -56,7 +55,7 @@ info:
description: my description
`, string(b))

b, err = ioutil.ReadFile(filepath.Join(d, "my-pkg", man.ManFilename))
b, err = os.ReadFile(filepath.Join(d, "my-pkg", man.ManFilename))
assert.NoError(t, err)
assert.Equal(t, strings.ReplaceAll(`# my-pkg
Expand All @@ -81,7 +80,7 @@ kpt live apply my-pkg --reconcile-timeout=2m --output=table
Details: https://kpt.dev/reference/cli/live/
`, "'", "`"), string(b))

b, err = ioutil.ReadFile(filepath.Join(d, "my-pkg", builtins.PkgContextFile))
b, err = os.ReadFile(filepath.Join(d, "my-pkg", builtins.PkgContextFile))
assert.NoError(t, err)
assert.Equal(t, b, []byte(builtins.AbstractPkgContext()))
}
Expand Down Expand Up @@ -111,7 +110,7 @@ func TestCmd_currentDir(t *testing.T) {
assert.NoError(t, err)

// verify the contents
b, err := ioutil.ReadFile(filepath.Join(packageDir, "Kptfile"))
b, err := os.ReadFile(filepath.Join(packageDir, "Kptfile"))
assert.NoError(t, err)
assert.Equal(t, `apiVersion: kpt.dev/v1
kind: Kptfile
Expand Down Expand Up @@ -149,7 +148,7 @@ func TestCmd_DefaultToCurrentDir(t *testing.T) {
assert.NoError(t, err)

// verify the contents
b, err := ioutil.ReadFile(filepath.Join(packageDir, "Kptfile"))
b, err := os.ReadFile(filepath.Join(packageDir, "Kptfile"))
assert.NoError(t, err)
assert.Equal(t, `apiVersion: kpt.dev/v1
kind: Kptfile
Expand Down
3 changes: 1 addition & 2 deletions internal/cmdliveinit/cmdliveinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"crypto/sha1"
goerrors "errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -285,7 +284,7 @@ func writeRGFile(dir string, rg *rgfilev1alpha1.ResourceGroup, filename string)
}

// fyi: perm is ignored if the file already exists
err = ioutil.WriteFile(filepath.Join(dir, filename), b, 0600)
err = os.WriteFile(filepath.Join(dir, filename), b, 0600)
if err != nil {
return errors.E(op, errors.IO, types.UniquePath(dir), err)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/cmdliveinit/cmdliveinit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package cmdliveinit

import (
"io/ioutil"
"os"
"path/filepath"
"regexp"
"testing"
Expand Down Expand Up @@ -231,15 +231,15 @@ func TestCmd_Run(t *testing.T) {

w, clean := testutil.SetupWorkspace(t)
defer clean()
err := ioutil.WriteFile(filepath.Join(w.WorkspaceDirectory, kptfilev1.KptFileName),
err := os.WriteFile(filepath.Join(w.WorkspaceDirectory, kptfilev1.KptFileName),
[]byte(tc.kptfile), 0600)
if !assert.NoError(t, err) {
t.FailNow()
}

// Create ResourceGroup file if testing the STDIN feature.
if tc.resourcegroup != "" && tc.rgfilename != "" {
err := ioutil.WriteFile(filepath.Join(w.WorkspaceDirectory, tc.rgfilename),
err := os.WriteFile(filepath.Join(w.WorkspaceDirectory, tc.rgfilename),
[]byte(tc.resourcegroup), 0600)
if !assert.NoError(t, err) {
t.FailNow()
Expand Down
3 changes: 1 addition & 2 deletions internal/cmdmigrate/migratecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
goerrors "errors"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -125,7 +124,7 @@ func (mr *MigrateRunner) Run(reader io.Reader, args []string) error {
var stdinBytes []byte
var err error
if len(args) == 0 {
stdinBytes, err = ioutil.ReadAll(reader)
stdinBytes, err = io.ReadAll(reader)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions internal/cmdmigrate/migratecmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package cmdmigrate

import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
Expand Down Expand Up @@ -142,12 +142,12 @@ func TestKptMigrate_migrateKptfileToRG(t *testing.T) {
// Set up temp directory with Ktpfile
dir := t.TempDir()
p := filepath.Join(dir, "Kptfile")
err := ioutil.WriteFile(p, []byte(tc.kptfile), 0600)
err := os.WriteFile(p, []byte(tc.kptfile), 0600)
assert.NoError(t, err)

if tc.resourcegroup != "" {
p := filepath.Join(dir, tc.rgFilename)
err = ioutil.WriteFile(p, []byte(tc.resourcegroup), 0600)
err = os.WriteFile(p, []byte(tc.resourcegroup), 0600)
assert.NoError(t, err)
}

Expand Down
10 changes: 5 additions & 5 deletions internal/cmdreporeg/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package cmdreporeg
import (
"encoding/json"
"flag"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestRepoReg(t *testing.T) {
var requestBody []byte
switch r.Header.Get("Content-Encoding") {
case "":
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
t.Fatalf("Failed to read request body: %v", err)
}
Expand Down Expand Up @@ -150,13 +150,13 @@ func TestRepoReg(t *testing.T) {
if err != nil {
t.Fatalf("Failed to marshal request body as YAML: %v", err)
}
if err := ioutil.WriteFile(wantFile, data, 0644); err != nil {
if err := os.WriteFile(wantFile, data, 0644); err != nil {
t.Fatalf("Failed to update golden file %q: %v", wantFile, err)
}
}

var want interface{}
wantBytes, err := ioutil.ReadFile(wantFile)
wantBytes, err := os.ReadFile(wantFile)
if err != nil {
t.Fatalf("Failed to reead golden file %q: %v", wantFile, err)
}
Expand All @@ -168,7 +168,7 @@ func TestRepoReg(t *testing.T) {
t.Errorf("Unexpected request body for %q (-want, +got) %s", r.RequestURI, cmp.Diff(want, body))
}

respData, err := ioutil.ReadFile(filepath.Join(testdata, action.sendResponse))
respData, err := os.ReadFile(filepath.Join(testdata, action.sendResponse))
if err != nil {
t.Fatalf("Failed to read response file %q: %v", action.sendResponse, err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/fnruntime/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"context"
goerrors "errors"
"fmt"
"io/ioutil"
"io"
"path"
"path/filepath"
"strings"
Expand Down Expand Up @@ -513,7 +513,7 @@ func newFnConfig(fsys filesys.FileSystem, f *kptfilev1.Function, pkgPath types.U
fmt.Errorf("missing function config %q", f.ConfigPath))
}
defer file.Close()
b, err := ioutil.ReadAll(file)
b, err := io.ReadAll(file)
if err != nil {
return nil, errors.E(op, fn, err)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/fnruntime/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package fnruntime
import (
"bytes"
"context"
"io/ioutil"
"os"
"path"
"strings"
Expand Down Expand Up @@ -84,7 +83,7 @@ data: {foo: bar}
c := c
t.Run(c.name, func(t *testing.T) {
if c.configFileContent != "" {
tmp, err := ioutil.TempFile("", "kpt-pipeline-*")
tmp, err := os.CreateTemp("", "kpt-pipeline-*")
assert.NoError(t, err, "unexpected error")
_, err = tmp.WriteString(c.configFileContent)
assert.NoError(t, err, "unexpected error")
Expand Down
11 changes: 5 additions & 6 deletions internal/testutil/pkgbuilder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package pkgbuilder
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -494,7 +493,7 @@ func buildPkg(pkgPath string, pkg *pkg, pkgName string, reposInfo ReposInfo) err
if pkg.Kptfile != nil {
content := buildKptfile(pkg, pkgName, reposInfo)

err := ioutil.WriteFile(filepath.Join(pkgPath, kptfilev1.KptFileName),
err := os.WriteFile(filepath.Join(pkgPath, kptfilev1.KptFileName),
[]byte(content), 0600)
if err != nil {
return err
Expand All @@ -504,7 +503,7 @@ func buildPkg(pkgPath string, pkg *pkg, pkgName string, reposInfo ReposInfo) err
if pkg.RGFile != nil {
content := buildRGFile(pkg)

err := ioutil.WriteFile(filepath.Join(pkgPath, rgfilev1alpha1.RGFileName),
err := os.WriteFile(filepath.Join(pkgPath, rgfilev1alpha1.RGFileName),
[]byte(content), 0600)
if err != nil {
return err
Expand All @@ -522,7 +521,7 @@ func buildPkg(pkgPath string, pkg *pkg, pkgName string, reposInfo ReposInfo) err
}

filePath := filepath.Join(pkgPath, ri.resourceInfo.filename)
err := ioutil.WriteFile(filePath, []byte(r.MustString()), 0600)
err := os.WriteFile(filePath, []byte(r.MustString()), 0600)
if err != nil {
return err
}
Expand All @@ -537,7 +536,7 @@ func buildPkg(pkgPath string, pkg *pkg, pkgName string, reposInfo ReposInfo) err
if !os.IsNotExist(err) {
return fmt.Errorf("file %s already exists", name)
}
err = ioutil.WriteFile(filePath, []byte(content), 0600)
err = os.WriteFile(filePath, []byte(content), 0600)
if err != nil {
return err
}
Expand Down Expand Up @@ -701,7 +700,7 @@ func (rp *RootPkg) ExpandPkg(t *testing.T, reposInfo ReposInfo) string {
// rootName to set the value of the package directory and the metadata.name
// field of the root package.
func (rp *RootPkg) ExpandPkgWithName(t *testing.T, rootName string, reposInfo ReposInfo) string {
dir, err := ioutil.TempDir("", "test-kpt-builder-")
dir, err := os.MkdirTemp("", "test-kpt-builder-")
if !assert.NoError(t, err) {
t.FailNow()
}
Expand Down
3 changes: 1 addition & 2 deletions internal/testutil/setup_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package testutil

import (
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -88,7 +87,7 @@ func (g *TestSetupManager) Init() bool {
}

// Configure the cache location for cloning repos
cacheDir, err := ioutil.TempDir("", "kpt-test-cache-repos-")
cacheDir, err := os.MkdirTemp("", "kpt-test-cache-repos-")
if !assert.NoError(g.T, err) {
return false
}
Expand Down
15 changes: 7 additions & 8 deletions internal/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package testutil
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -232,11 +231,11 @@ func Diff(sourceDir, destDir string, addMergeCommentsToSource bool) (sets.String
}

// compare upstreamFiles
b1, err := ioutil.ReadFile(filepath.Join(destDir, f))
b1, err := os.ReadFile(filepath.Join(destDir, f))
if err != nil {
return diff, err
}
b2, err := ioutil.ReadFile(filepath.Join(sourceDir, f))
b2, err := os.ReadFile(filepath.Join(sourceDir, f))
if err != nil {
return diff, err
}
Expand Down Expand Up @@ -269,7 +268,7 @@ const trimPrefix = `# Copyright 2019 Google LLC
// AssertKptfile verifies the contents of the KptFile matches the provided value.
func (g *TestGitRepo) AssertKptfile(t *testing.T, cloned string, kpkg kptfilev1.KptFile) bool {
// read the actual generated KptFile
b, err := ioutil.ReadFile(filepath.Join(cloned, kptfilev1.KptFileName))
b, err := os.ReadFile(filepath.Join(cloned, kptfilev1.KptFileName))
if !assert.NoError(t, err) {
return false
}
Expand Down Expand Up @@ -359,7 +358,7 @@ func (g *TestGitRepo) SetupTestGitRepo(name string, data []Content, repos map[st
}

func (g *TestGitRepo) createEmptyGitRepo(defaultBranch string) error {
dir, err := ioutil.TempDir("", fmt.Sprintf("%s-upstream-", TmpDirPrefix))
dir, err := os.MkdirTemp("", fmt.Sprintf("%s-upstream-", TmpDirPrefix))
if err != nil {
return err
}
Expand Down Expand Up @@ -774,7 +773,7 @@ func (w *TestWorkspace) FullPackagePath() string {

func (w *TestWorkspace) SetupTestWorkspace() error {
var err error
w.WorkspaceDirectory, err = ioutil.TempDir("", "test-kpt-local-")
w.WorkspaceDirectory, err = os.MkdirTemp("", "test-kpt-local-")
return err
}

Expand Down Expand Up @@ -824,7 +823,7 @@ func PrintPackage(paths ...string) error {

func PrintFile(paths ...string) error {
path := filepath.Join(paths...)
b, err := ioutil.ReadFile(path)
b, err := os.ReadFile(path)
if err != nil {
return err
}
Expand Down Expand Up @@ -854,7 +853,7 @@ func Chdir(t *testing.T, path string) func() {
// cache, sets the env variable so it will be used for tests, and cleans
// up the directory afterwards.
func ConfigureTestKptCache(m *testing.M) int {
cacheDir, err := ioutil.TempDir("", "kpt-test-cache-repos-")
cacheDir, err := os.MkdirTemp("", "kpt-test-cache-repos-")
if err != nil {
panic(fmt.Errorf("error creating temp dir for cache: %w", err))
}
Expand Down
3 changes: 1 addition & 2 deletions internal/util/addmergecomment/addmergecomment.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package addmergecomment

import (
"fmt"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -138,7 +137,7 @@ func (amc *AddMergeComment) Filter(object *kyaml.RNode) (*kyaml.RNode, error) {
// new temp directory and adds merge comment to the resources in directory
// it also returns the cleanup function to clean the created temp directory
func ProcessWithCleanup(path string) (string, func(), error) {
expected, err := ioutil.TempDir("", "")
expected, err := os.MkdirTemp("", "")
if err != nil {
return "", nil, err
}
Expand Down
Loading

0 comments on commit c39f492

Please sign in to comment.