Skip to content

Commit

Permalink
fix: replace deprecated go calls
Browse files Browse the repository at this point in the history
  • Loading branch information
mgoltzsche committed Sep 25, 2022
1 parent 2b9f703 commit 9b55a00
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 20 deletions.
3 changes: 1 addition & 2 deletions cmd/khelm/fn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"bytes"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand All @@ -17,7 +16,7 @@ import (
)

func TestKptFnCommand(t *testing.T) {
dir, err := ioutil.TempDir("", "khelm-fn-test-")
dir, err := os.MkdirTemp("", "khelm-fn-test-")
require.NoError(t, err)
defer os.RemoveAll(dir)
os.Setenv("HELM_HOME", dir)
Expand Down
3 changes: 1 addition & 2 deletions cmd/khelm/kustomize_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"bytes"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -14,7 +13,7 @@ import (

func TestKustomizePlugin(t *testing.T) {
file := filepath.Join("..", "..", "example", "include", "generator.yaml")
kustomizeGenCfg, err := ioutil.ReadFile(file)
kustomizeGenCfg, err := os.ReadFile(file)
require.NoError(t, err)
os.Setenv(envKustomizePluginConfig, string(kustomizeGenCfg))
os.Setenv(envTrustAnyRepo, "true")
Expand Down
3 changes: 1 addition & 2 deletions cmd/khelm/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -107,7 +106,7 @@ func TestTemplateCommand(t *testing.T) {
}

func TestTemplateCommandError(t *testing.T) {
dir, err := ioutil.TempDir("", "khelm-tpl-test-")
dir, err := os.MkdirTemp("", "khelm-tpl-test-")
require.NoError(t, err)
repoDir := filepath.Join(dir, "repository")
defer os.RemoveAll(dir)
Expand Down
3 changes: 1 addition & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"path/filepath"
"strings"

Expand Down Expand Up @@ -117,7 +116,7 @@ func (cfg *ChartConfig) Validate() (errs []string) {
// ReadGeneratorConfig read the generator configuration
func ReadGeneratorConfig(reader io.Reader) (cfg *GeneratorConfig, err error) {
cfg = &GeneratorConfig{}
data, err := ioutil.ReadAll(reader)
data, err := io.ReadAll(reader)
if err != nil {
return nil, errors.Wrap(err, "read chart renderer config")
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/helm/locate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package helm
import (
"context"
"fmt"
"io/ioutil"
"log"
"net/url"
"os"
Expand Down Expand Up @@ -90,7 +89,7 @@ func locateChart(ctx context.Context, cfg *config.LoaderConfig, repos repository
if err = os.MkdirAll(destParentDir, 0750); err != nil {
return "", errors.WithStack(err)
}
tmpDestDir, err := ioutil.TempDir(destParentDir, fmt.Sprintf(".tmp-%s-", filepath.Base(destDir)))
tmpDestDir, err := os.MkdirTemp(destParentDir, fmt.Sprintf(".tmp-%s-", filepath.Base(destDir)))
if err != nil {
return "", errors.WithStack(err)
}
Expand Down
13 changes: 6 additions & 7 deletions pkg/helm/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -124,7 +123,7 @@ func TestRender(t *testing.T) {
}

func TestRenderUntrustedRepositoryError(t *testing.T) {
dir, err := ioutil.TempDir("", "khelm-test-untrusted-repo-")
dir, err := os.MkdirTemp("", "khelm-test-untrusted-repo-")
require.NoError(t, err)
defer os.RemoveAll(dir)
os.Setenv("HELM_HOME", dir)
Expand Down Expand Up @@ -178,7 +177,7 @@ func TestRenderRebuildsLocalDependencies(t *testing.T) {
require.NoError(t, err)
defer os.RemoveAll(tplDir)
data := []byte("apiVersion: fancyapi/v1\nkind: FancyKind\nmetadata:\n name: sth\nchangedField: changed-value")
err = ioutil.WriteFile(tplFile, data, 0600)
err = os.WriteFile(tplFile, data, 0600)
require.NoError(t, err)

// Render again and verify that the dependency is rebuilt
Expand Down Expand Up @@ -253,7 +252,7 @@ func TestRenderNoDigest(t *testing.T) {
repoEntry.URL = srv.URL

// Generate temp repository configuration pointing to fake private server
tmpHelmHome, err := ioutil.TempDir("", "khelm-test-home-")
tmpHelmHome, err := os.MkdirTemp("", "khelm-test-home-")
require.NoError(t, err)
defer os.RemoveAll(tmpHelmHome)
origHelmHome := os.Getenv("HELM_HOME")
Expand All @@ -266,7 +265,7 @@ func TestRenderNoDigest(t *testing.T) {
require.NoError(t, err)
err = os.Mkdir(filepath.Join(tmpHelmHome, "repository"), 0755)
require.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(tmpHelmHome, "repository", "repositories.yaml"), b, 0600) // #nosec
err = os.WriteFile(filepath.Join(tmpHelmHome, "repository", "repositories.yaml"), b, 0600) // #nosec
require.NoError(t, err)

cfg.Repository = repoEntry.URL
Expand Down Expand Up @@ -297,7 +296,7 @@ func TestRenderRepositoryCredentials(t *testing.T) {
repoEntry.URL = srv.URL

// Generate temp repository configuration pointing to fake private server
tmpHelmHome, err := ioutil.TempDir("", "khelm-test-home-")
tmpHelmHome, err := os.MkdirTemp("", "khelm-test-home-")
require.NoError(t, err)
defer os.RemoveAll(tmpHelmHome)
origHelmHome := os.Getenv("HELM_HOME")
Expand All @@ -310,7 +309,7 @@ func TestRenderRepositoryCredentials(t *testing.T) {
require.NoError(t, err)
err = os.Mkdir(filepath.Join(tmpHelmHome, "repository"), 0755)
require.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(tmpHelmHome, "repository", "repositories.yaml"), b, 0600) // #nosec
err = os.WriteFile(filepath.Join(tmpHelmHome, "repository", "repositories.yaml"), b, 0600) // #nosec
require.NoError(t, err)

for _, c := range []struct {
Expand Down
5 changes: 2 additions & 3 deletions pkg/helm/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -348,7 +347,7 @@ type tempRepositories struct {
}

func newTempRepositories(r *repositories) (*tempRepositories, error) {
tmpFile, err := ioutil.TempFile("", "helm-repositories-")
tmpFile, err := os.CreateTemp("", "helm-repositories-")
if err != nil {
return nil, errors.WithStack(err)
}
Expand All @@ -372,7 +371,7 @@ func downloadIndexFile(ctx context.Context, entry *repo.Entry, cacheDir string,
if err != nil {
return errors.WithStack(err)
}
tmpIdxFile, err := ioutil.TempFile(filepath.Dir(idxFile), fmt.Sprintf(".tmp-%s-index", entry.Name))
tmpIdxFile, err := os.CreateTemp(filepath.Dir(idxFile), fmt.Sprintf(".tmp-%s-index", entry.Name))
if err != nil {
return errors.WithStack(err)
}
Expand Down

0 comments on commit 9b55a00

Please sign in to comment.