diff --git a/client_test.go b/client_test.go index 316c1425..562215ef 100644 --- a/client_test.go +++ b/client_test.go @@ -9,7 +9,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net" "net/http" "os" @@ -177,7 +176,7 @@ func TestClient_New_NonemptyAborts(t *testing.T) { // Write a visible file which should cause an abort visibleFile := filepath.Join(root, "file.txt") - if err := ioutil.WriteFile(visibleFile, []byte{}, 0644); err != nil { + if err := os.WriteFile(visibleFile, []byte{}, 0644); err != nil { t.Fatal(err) } @@ -201,7 +200,7 @@ func TestClient_New_HiddenFilesIgnored(t *testing.T) { // Create a hidden file that should be ignored. hiddenFile := filepath.Join(root, ".envrc") - if err := ioutil.WriteFile(hiddenFile, []byte{}, 0644); err != nil { + if err := os.WriteFile(hiddenFile, []byte{}, 0644); err != nil { t.Fatal(err) } diff --git a/cmd/delete_test.go b/cmd/delete_test.go index c739a411..bae21c16 100644 --- a/cmd/delete_test.go +++ b/cmd/delete_test.go @@ -1,7 +1,7 @@ package cmd import ( - "io/ioutil" + "os" "testing" fn "knative.dev/kn-plugin-func" @@ -63,7 +63,7 @@ annotations: {} labels: [] created: 2021-01-01T00:00:00+00:00 ` - if err := ioutil.WriteFile("func.yaml", []byte(funcYaml), 0600); err != nil { + if err := os.WriteFile("func.yaml", []byte(funcYaml), 0600); err != nil { t.Fatal(err) } diff --git a/cmd/invoke.go b/cmd/invoke.go index 8197868e..9e327e5b 100644 --- a/cmd/invoke.go +++ b/cmd/invoke.go @@ -3,7 +3,6 @@ package cmd import ( "encoding/base64" "fmt" - "io/ioutil" "os" "strings" @@ -241,7 +240,7 @@ func newInvokeConfig(newClient ClientFactory) (cfg invokeConfig, err error) { // If file was passed, read it in as data if cfg.File != "" { - b, err := ioutil.ReadFile(cfg.File) + b, err := os.ReadFile(cfg.File) if err != nil { return cfg, err } diff --git a/config/config.go b/config/config.go index dc4b98d7..ffbc731a 100644 --- a/config/config.go +++ b/config/config.go @@ -2,7 +2,6 @@ package config import ( "fmt" - "io/ioutil" "os" "path/filepath" @@ -79,7 +78,7 @@ func (c Config) Save(path string) (err error) { if bb, err = yaml.Marshal(&c); err != nil { return } - return ioutil.WriteFile(path, bb, os.ModePerm) + return os.WriteFile(path, bb, os.ModePerm) } // Path is derived in the following order, from lowest diff --git a/docker/creds/credentials.go b/docker/creds/credentials.go index 52ab2545..960205a9 100644 --- a/docker/creds/credentials.go +++ b/docker/creds/credentials.go @@ -5,7 +5,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "net" "net/http" "net/url" @@ -299,7 +298,7 @@ func (c *credentialsProvider) getCredentials(ctx context.Context, image string) var errNoCredentialHelperConfigured = errors.New("no credential helper configure") func getCredentialHelperFromConfig(confFilePath string) (string, error) { - data, err := ioutil.ReadFile(confFilePath) + data, err := os.ReadFile(confFilePath) if err != nil { return "", err } @@ -321,7 +320,7 @@ func setCredentialHelperToConfig(confFilePath, helper string) error { configData := make(map[string]interface{}) - if data, err := ioutil.ReadFile(confFilePath); err == nil { + if data, err := os.ReadFile(confFilePath); err == nil { err = json.Unmarshal(data, &configData) if err != nil { return err @@ -335,7 +334,7 @@ func setCredentialHelperToConfig(confFilePath, helper string) error { return err } - err = ioutil.WriteFile(confFilePath, data, 0600) + err = os.WriteFile(confFilePath, data, 0600) if err != nil { return err } @@ -399,7 +398,7 @@ func listCredentialHelpers() []string { helpers := make(map[string]bool) for _, p := range paths { - fss, err := ioutil.ReadDir(p) + fss, err := os.ReadDir(p) if err != nil { continue } diff --git a/docker/creds/credentials_test.go b/docker/creds/credentials_test.go index dae25e53..86bb07f6 100644 --- a/docker/creds/credentials_test.go +++ b/docker/creds/credentials_test.go @@ -15,7 +15,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "math/big" "net" "net/http" @@ -566,7 +565,7 @@ func withPopulatedDockerAuthConfig(t *testing.T) { }` configJSON = fmt.Sprintf(configJSON, base64.StdEncoding.EncodeToString([]byte(dockerIoUser+":"+dockerIoUserPwd))) - err = ioutil.WriteFile(dockerConfigPath, []byte(configJSON), 0600) + err = os.WriteFile(dockerConfigPath, []byte(configJSON), 0600) if err != nil { t.Fatal(err) } @@ -595,7 +594,7 @@ func withPopulatedFuncAuthConfig(t *testing.T) { base64.StdEncoding.EncodeToString([]byte(dockerIoUser+":"+dockerIoUserPwd)), base64.StdEncoding.EncodeToString([]byte(quayIoUser+":"+quayIoUserPwd))) - err = ioutil.WriteFile(authConfig, []byte(authJSON), 0600) + err = os.WriteFile(authConfig, []byte(authJSON), 0600) if err != nil { t.Fatal(err) } @@ -669,7 +668,7 @@ func handlerForCredHelper(t *testing.T, credHelper credentials.Helper) http.Hand var serverURL string if uri == "get" || uri == "erase" { - data, err := ioutil.ReadAll(request.Body) + data, err := io.ReadAll(request.Body) if err != nil { writer.WriteHeader(http.StatusInternalServerError) return diff --git a/docker/docker_client_ssh_test.go b/docker/docker_client_ssh_test.go index fe7d3b2b..4249dfa6 100644 --- a/docker/docker_client_ssh_test.go +++ b/docker/docker_client_ssh_test.go @@ -10,7 +10,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net" "net/http" "os" @@ -338,7 +337,7 @@ func withCleanHome(t *testing.T) func() { if runtime.GOOS == "windows" { homeName = "USERPROFILE" } - tmpDir, err := ioutil.TempDir("", "tmpHome") + tmpDir, err := os.MkdirTemp("", "tmpHome") if err != nil { t.Fatal(err) } diff --git a/docs/generator/main.go b/docs/generator/main.go index 157d5b82..9b42c468 100644 --- a/docs/generator/main.go +++ b/docs/generator/main.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "html/template" - "io/ioutil" "os" "regexp" "strings" @@ -113,7 +112,7 @@ func writeMarkdown(c *cobra.Command, name string, opts TemplateOptions) error { re := regexp.MustCompile(`[^\S\r\n]+\n`) data := re.ReplaceAll(out.Bytes(), []byte{'\n'}) // trim white spaces before EOL - if err := ioutil.WriteFile(targetDir+"/"+name+".md", data, 0666); err != nil { + if err := os.WriteFile(targetDir+"/"+name+".md", data, 0666); err != nil { return err } return nil diff --git a/filesystem_test.go b/filesystem_test.go index a1e8f19e..58aaf334 100644 --- a/filesystem_test.go +++ b/filesystem_test.go @@ -5,8 +5,8 @@ import ( "crypto/md5" "encoding/hex" "fmt" + "io" "io/fs" - "io/ioutil" "os" "path/filepath" "runtime" @@ -124,12 +124,12 @@ func TestFileSystems(t *testing.T) { return err } - localFileContent, err := ioutil.ReadFile(localFilePath) + localFileContent, err := os.ReadFile(localFilePath) if err != nil { return err } - embeddedFileContent, err := ioutil.ReadAll(embeddedFile) + embeddedFileContent, err := io.ReadAll(embeddedFile) if err != nil { return err } diff --git a/function.go b/function.go index 1fb72aad..6c57e0b3 100644 --- a/function.go +++ b/function.go @@ -3,7 +3,6 @@ package function import ( "errors" "fmt" - "io/ioutil" "os" "path/filepath" "regexp" @@ -494,7 +493,7 @@ var contentiousFiles = []string{ // contentiousFilesIn the given directory func contentiousFilesIn(dir string) (contentious []string, err error) { - files, err := ioutil.ReadDir(dir) + files, err := os.ReadDir(dir) for _, file := range files { for _, name := range contentiousFiles { if file.Name() == name { @@ -508,7 +507,7 @@ func contentiousFilesIn(dir string) (contentious []string, err error) { // effectivelyEmpty directories are those which have no visible files func isEffectivelyEmpty(dir string) (bool, error) { // Check for any non-hidden files - files, err := ioutil.ReadDir(dir) + files, err := os.ReadDir(dir) if err != nil { return false, err } @@ -531,7 +530,7 @@ func hasInitializedFunction(path string) (bool, error) { } return false, err // invalid path or access error } - bb, err := ioutil.ReadFile(filename) + bb, err := os.ReadFile(filename) if err != nil { return false, err } diff --git a/function_volumes.go b/function_volumes.go index fd85dd07..c8363cf2 100644 --- a/function_volumes.go +++ b/function_volumes.go @@ -22,10 +22,10 @@ func (v Volume) String() string { // Returns array of error messages, empty if no errors are found // // Allowed settings: -// - secret: example-secret # mount Secret as Volume -// path: /etc/secret-volume -// - configMap: example-configMap # mount ConfigMap as Volume -// path: /etc/configMap-volume +// - secret: example-secret # mount Secret as Volume +// path: /etc/secret-volume +// - configMap: example-configMap # mount ConfigMap as Volume +// path: /etc/configMap-volume func validateVolumes(volumes []Volume) (errors []string) { for i, vol := range volumes { diff --git a/invoke.go b/invoke.go index 80185fd7..5baa76b6 100644 --- a/invoke.go +++ b/invoke.go @@ -98,8 +98,9 @@ func invoke(ctx context.Context, c *Client, f Function, target string, m InvokeM // 'remote': remote environment; first available instance (error if none) // '': A valid alternate target which contains instances. // '': An explicit URL -// '': Default if no target is passed is to first use local, then remote. -// errors if neither are available. +// ”: Default if no target is passed is to first use local, then remote. +// +// errors if neither are available. func invocationRoute(ctx context.Context, c *Client, f Function, target string) (string, error) { // TODO: this function has code-smell; will de-smellify it in next pass. if target == EnvironmentLocal { diff --git a/repository.go b/repository.go index 9fe68578..405f52b0 100644 --- a/repository.go +++ b/repository.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "io/ioutil" "net/url" "os" "path" @@ -492,7 +491,7 @@ func (r *Repository) Write(path string) (err error) { clone *git.Repository wt *git.Worktree ) - if tempDir, err = ioutil.TempDir("", "func"); err != nil { + if tempDir, err = os.MkdirTemp("", "func"); err != nil { return } if clone, err = git.PlainClone(tempDir, false, // not bare diff --git a/s2i/builder_test.go b/s2i/builder_test.go index 95ce2879..808fde96 100644 --- a/s2i/builder_test.go +++ b/s2i/builder_test.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "log" "net" "net/http" @@ -318,7 +317,7 @@ func TestBuildContextUpload(t *testing.T) { switch hdr.Name { case ".": case "Dockerfile": - bs, err := ioutil.ReadAll(tr) + bs, err := io.ReadAll(tr) if err != nil { return types.ImageBuildResponse{}, err } @@ -326,7 +325,7 @@ func TestBuildContextUpload(t *testing.T) { return types.ImageBuildResponse{}, errors.New("bad content for Dockerfile") } case "a.txt": - bs, err := ioutil.ReadAll(tr) + bs, err := io.ReadAll(tr) if err != nil { return types.ImageBuildResponse{}, err } @@ -346,11 +345,11 @@ func TestBuildContextUpload(t *testing.T) { impl := &mockImpl{ BuildFn: func(config *api.Config) (*api.Result, error) { - err := ioutil.WriteFile(config.AsDockerfile, dockerfileContent, 0644) + err := os.WriteFile(config.AsDockerfile, dockerfileContent, 0644) if err != nil { return nil, err } - err = ioutil.WriteFile(filepath.Join(filepath.Dir(config.AsDockerfile), "a.txt"), atxtContent, 0644) + err = os.WriteFile(filepath.Join(filepath.Dir(config.AsDockerfile), "a.txt"), atxtContent, 0644) if err != nil { return nil, err } diff --git a/schema/generator/main.go b/schema/generator/main.go index f194e572..33025817 100644 --- a/schema/generator/main.go +++ b/schema/generator/main.go @@ -3,7 +3,7 @@ package main import ( "bytes" "encoding/json" - "io/ioutil" + "os" "github.com/alecthomas/jsonschema" @@ -37,5 +37,5 @@ func generateFuncYamlSchema() error { } // write schema to the file - return ioutil.WriteFile("schema/func_yaml-schema.json", indentedSchema.Bytes(), 0644) + return os.WriteFile("schema/func_yaml-schema.json", indentedSchema.Bytes(), 0644) } diff --git a/ssh/ssh_dialer.go b/ssh/ssh_dialer.go index 2efaf906..df1a0fd1 100644 --- a/ssh/ssh_dialer.go +++ b/ssh/ssh_dialer.go @@ -8,7 +8,6 @@ import ( "context" "errors" "fmt" - "io/ioutil" "net" urlPkg "net/url" "os" @@ -355,7 +354,7 @@ func NewSSHClientConfig(url *urlPkg.URL, credentialsConfig Config) (*ssh.ClientC } func publicKey(path string, passphrase []byte, passPhraseCallback PassPhraseCallback) (ssh.Signer, error) { - key, err := ioutil.ReadFile(path) + key, err := os.ReadFile(path) if err != nil { return nil, fmt.Errorf("failed to read key file: %w", err) } diff --git a/test/_e2e/trigger_events_test.go b/test/_e2e/trigger_events_test.go index 4cd34e59..9a1e87c7 100644 --- a/test/_e2e/trigger_events_test.go +++ b/test/_e2e/trigger_events_test.go @@ -2,7 +2,7 @@ package e2e import ( "fmt" - "io/ioutil" + "io" "net/http" "strings" "testing" @@ -31,7 +31,7 @@ func (s SimpleTestEvent) pushTo(url string, t *testing.T) (body string, statusCo } t.Logf("event POST %v -> %v", url, resp.Status) defer resp.Body.Close() - b, err := ioutil.ReadAll(resp.Body) + b, err := io.ReadAll(resp.Body) if err != nil { return "", resp.StatusCode, fmt.Errorf("Error reading response body: %v", err.Error()) } diff --git a/test/_e2e/trigger_http_test.go b/test/_e2e/trigger_http_test.go index a054352a..357fb0e3 100644 --- a/test/_e2e/trigger_http_test.go +++ b/test/_e2e/trigger_http_test.go @@ -2,7 +2,7 @@ package e2e import ( "fmt" - "io/ioutil" + "io" "net/http" "strings" "testing" @@ -48,7 +48,7 @@ func (f FunctionHttpResponsivenessValidator) Validate(t *testing.T, project Func defer resp.Body.Close() t.Logf("%v %v -> %v", method, url, resp.Status) - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { t.Fatalf("Error reading response body: %v", err.Error()) } diff --git a/test/_e2e/update_test.go b/test/_e2e/update_test.go index c952ecbd..662625a7 100644 --- a/test/_e2e/update_test.go +++ b/test/_e2e/update_test.go @@ -2,8 +2,6 @@ package e2e import ( "io" - "io/ioutil" - "os" "path/filepath" "testing" @@ -45,14 +43,12 @@ func Update(t *testing.T, knFunc *TestShellCmdRunner, project *FunctionTestProje project.IsNewRevision = true } -// // projectUpdater offers methods to update the project source content by the // source provided on update_templates folder // The strategy used consists in // 1. Create a temporary project folder with some files from original test folder (such as func.yaml, pom.xml) // 2. Copy recursivelly all files from ./update_template//