Skip to content
Myr

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

7 files+14 added−18 removed

modified:doc/man_docs_test.go+2 added-3 removed
16 unmodified lines
17import (18 "bufio"19 "bytes"20 "fmt"21 "io/ioutil"21 "os"22 "path/filepath"23 "strings"24 "testing"
141 unmodified lines
166167func 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 lines
217 return fmt.Errorf("hit EOF before finding %v", expectedLine)218}219220func 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 lines
modified:doc/md_docs_test.go+2 added-3 removed
14 unmodified lines
15package doc1617import (18 "bytes"19 "io/ioutil"19 "os"20 "path/filepath"21 "testing"22
69 unmodified lines
92}9394func 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 lines
108 }109}110111func 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 lines
modified:doc/rest_docs_test.go+2 added-3 removed
14 unmodified lines
15package doc1617import (18 "bytes"19 "io/ioutil"19 "os"20 "path/filepath"21 "testing"22
56 unmodified lines
7980func TestGenRSTTree(t *testing.T) {81 c := &cobra.Command{Use: "do [OPTIONS] arg1 arg2"}8284 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 lines
95 }96}9798func 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 lines
modified:doc/yaml_docs_test.go+2 added-3 removed
15 unmodified lines
1617import (18 "bytes"19 "fmt"20 "io/ioutil"20 "os"21 "path/filepath"22 "testing"23
32 unmodified lines
5657func TestGenYamlTree(t *testing.T) {58 c := &cobra.Command{Use: "do [OPTIONS] arg1 arg2"}5961 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 lines
83 checkStringContains(t, output, "usage: "+rootCmd.Use)84}8586func 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 lines
modified:site/content/docgen/md.md+2 added-2 removed
modified:site/content/docgen/rest.md+2 added-2 removed
33 unmodified lines
34package main3536import (37 "log"38 "io/ioutil"38 "io"39 "os"4041 "k8s.io/kubernetes/pkg/kubectl/cmd"42 cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
1 unmodified line
44 "github.com/spf13/cobra/doc"45)4647func 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 lines
modified:site/content/docgen/yaml.md+2 added-2 removed
32 unmodified lines
33```go34package main3536import (37 "io/ioutil"37 "io"38 "log"39 "os"4041 "k8s.io/kubernetes/pkg/kubectl/cmd"
2 unmodified lines
44 "github.com/spf13/cobra/doc"45)4647func 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