Replace deprecated ioutil usage (#2181)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Fixing golangci-lint errors[1]: Error: SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package [io] or package [os], and those implementations should be preferred in new code. See the specific function documentation for details. (staticcheck) [1] https://github.com/spf13/cobra/actions/runs/10535452454/job/29194442289?pr=2180
authored by Nir Soffer · committed by GitHub · parent 756ba6d · Browse files · 7 files·+14 added−18 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+14 added−18 removed
- other:+14 added−18 removed
Provenance
- Commit
511af59- Tree
18f41df- Author
Nir Soffer <nsoffer@redhat.com>- Committer
GitHub <noreply@github.com>- Parent
756ba6d
7 files changed+14 added−18 removed
modified:doc/man_docs_test.go+2 added-3 removed
16 unmodified lines17 import (18 "bufio"19 "bytes"20 "fmt"21- "io/ioutil"21 "os"22 "path/filepath"23 "strings"24 "testing"141 unmodified lines166 167 func TestGenManTree(t *testing.T) {168 c := &cobra.Command{Use: "do [OPTIONS] arg1 arg2"}169 header := &GenManHeader{Section: "2"}171- tmpdir, err := ioutil.TempDir("", "test-gen-man-tree")170+ tmpdir, err := os.MkdirTemp("", "test-gen-man-tree")171 if err != nil {172 t.Fatalf("Failed to create tmpdir: %s", err.Error())173 }174 defer os.RemoveAll(tmpdir)42 unmodified lines217 return fmt.Errorf("hit EOF before finding %v", expectedLine)218 }219 220 func BenchmarkGenManToFile(b *testing.B) {222- file, err := ioutil.TempFile("", "")221+ file, err := os.CreateTemp("", "")222 if err != nil {223 b.Fatal(err)224 }225 defer os.Remove(file.Name())9 unmodified linesmodified:doc/md_docs_test.go+2 added-3 removed
14 unmodified lines15 package doc16 17 import (18 "bytes"19- "io/ioutil"19 "os"20 "path/filepath"21 "testing"22 69 unmodified lines92 }93 94 func TestGenMdTree(t *testing.T) {95 c := &cobra.Command{Use: "do [OPTIONS] arg1 arg2"}97- tmpdir, err := ioutil.TempDir("", "test-gen-md-tree")96+ tmpdir, err := os.MkdirTemp("", "test-gen-md-tree")97 if err != nil {98 t.Fatalf("Failed to create tmpdir: %v", err)99 }100 defer os.RemoveAll(tmpdir)7 unmodified lines108 }109 }110 111 func BenchmarkGenMarkdownToFile(b *testing.B) {113- file, err := ioutil.TempFile("", "")112+ file, err := os.CreateTemp("", "")113 if err != nil {114 b.Fatal(err)115 }116 defer os.Remove(file.Name())9 unmodified linesmodified:doc/rest_docs_test.go+2 added-3 removed
14 unmodified lines15 package doc16 17 import (18 "bytes"19- "io/ioutil"19 "os"20 "path/filepath"21 "testing"22 56 unmodified lines79 80 func TestGenRSTTree(t *testing.T) {81 c := &cobra.Command{Use: "do [OPTIONS] arg1 arg2"}82 84- tmpdir, err := ioutil.TempDir("", "test-gen-rst-tree")83+ tmpdir, err := os.MkdirTemp("", "test-gen-rst-tree")84 if err != nil {85 t.Fatalf("Failed to create tmpdir: %s", err.Error())86 }87 defer os.RemoveAll(tmpdir)7 unmodified lines95 }96 }97 98 func BenchmarkGenReSTToFile(b *testing.B) {100- file, err := ioutil.TempFile("", "")99+ file, err := os.CreateTemp("", "")100 if err != nil {101 b.Fatal(err)102 }103 defer os.Remove(file.Name())9 unmodified linesmodified:doc/yaml_docs_test.go+2 added-3 removed
15 unmodified lines16 17 import (18 "bytes"19 "fmt"20- "io/ioutil"20 "os"21 "path/filepath"22 "testing"23 32 unmodified lines56 57 func TestGenYamlTree(t *testing.T) {58 c := &cobra.Command{Use: "do [OPTIONS] arg1 arg2"}59 61- tmpdir, err := ioutil.TempDir("", "test-gen-yaml-tree")60+ tmpdir, err := os.MkdirTemp("", "test-gen-yaml-tree")61 if err != nil {62 t.Fatalf("Failed to create tmpdir: %s", err.Error())63 }64 defer os.RemoveAll(tmpdir)18 unmodified lines83 checkStringContains(t, output, "usage: "+rootCmd.Use)84 }85 86 func BenchmarkGenYamlToFile(b *testing.B) {88- file, err := ioutil.TempFile("", "")87+ file, err := os.CreateTemp("", "")88 if err != nil {89 b.Fatal(err)90 }91 defer os.Remove(file.Name())9 unmodified linesmodified:site/content/docgen/md.md+2 added-2 removed
33 unmodified lines34353637383839404142434445464748484950515263 unmodified lines33 unmodified linespackage main
import ( "log" "io/ioutil" "io" "os"
"k8s.io/kubernetes/pkg/kubectl/cmd" cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"github.com/spf13/cobra/doc")
func main() { kubectl := cmd.NewKubectlCommand(cmdutil.NewFactory(nil), os.Stdin, ioutil.Discard, ioutil.Discard) kubectl := cmd.NewKubectlCommand(cmdutil.NewFactory(nil), os.Stdin, io.Discard, io.Discard) err := doc.GenMarkdownTree(kubectl, "./") if err != nil { log.Fatal(err) }63 unmodified linesmodified:site/content/docgen/rest.md+2 added-2 removed
33 unmodified lines34 package main35 36 import (37 "log"38- "io/ioutil"38+ "io"39 "os"40 41 "k8s.io/kubernetes/pkg/kubectl/cmd"42 cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"1 unmodified line44 "github.com/spf13/cobra/doc"45 )46 47 func main() {48- kubectl := cmd.NewKubectlCommand(cmdutil.NewFactory(nil), os.Stdin, ioutil.Discard, ioutil.Discard)48+ kubectl := cmd.NewKubectlCommand(cmdutil.NewFactory(nil), os.Stdin, io.Discard, io.Discard)49 err := doc.GenReSTTree(kubectl, "./")50 if err != nil {51 log.Fatal(err)52 }62 unmodified linesmodified:site/content/docgen/yaml.md+2 added-2 removed
32 unmodified lines33 ```go34 package main35 36 import (37- "io/ioutil"37+ "io"38 "log"39 "os"40 41 "k8s.io/kubernetes/pkg/kubectl/cmd"2 unmodified lines44 "github.com/spf13/cobra/doc"45 )46 47 func main() {48- kubectl := cmd.NewKubectlCommand(cmdutil.NewFactory(nil), os.Stdin, ioutil.Discard, ioutil.Discard)48+ kubectl := cmd.NewKubectlCommand(cmdutil.NewFactory(nil), os.Stdin, io.Discard, io.Discard)49 err := doc.GenYamlTree(kubectl, "./")50 if err != nil {51 log.Fatal(err)52 }60 unmodified lines