Replace deprecated ioutil usage (#2181)

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
This commit is contained in:
Nir Soffer 2024-08-24 14:05:26 +03:00 committed by GitHub
parent 756ba6dad6
commit 511af59cb3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 14 additions and 18 deletions

View file

@ -18,7 +18,6 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -168,7 +167,7 @@ func TestManPrintFlagsHidesShortDeprecated(t *testing.T) {
func TestGenManTree(t *testing.T) { func TestGenManTree(t *testing.T) {
c := &cobra.Command{Use: "do [OPTIONS] arg1 arg2"} c := &cobra.Command{Use: "do [OPTIONS] arg1 arg2"}
header := &GenManHeader{Section: "2"} header := &GenManHeader{Section: "2"}
tmpdir, err := ioutil.TempDir("", "test-gen-man-tree") tmpdir, err := os.MkdirTemp("", "test-gen-man-tree")
if err != nil { if err != nil {
t.Fatalf("Failed to create tmpdir: %s", err.Error()) t.Fatalf("Failed to create tmpdir: %s", err.Error())
} }
@ -219,7 +218,7 @@ func assertNextLineEquals(scanner *bufio.Scanner, expectedLine string) error {
} }
func BenchmarkGenManToFile(b *testing.B) { func BenchmarkGenManToFile(b *testing.B) {
file, err := ioutil.TempFile("", "") file, err := os.CreateTemp("", "")
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }

View file

@ -16,7 +16,6 @@ package doc
import ( import (
"bytes" "bytes"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -94,7 +93,7 @@ func TestGenMdNoTag(t *testing.T) {
func TestGenMdTree(t *testing.T) { func TestGenMdTree(t *testing.T) {
c := &cobra.Command{Use: "do [OPTIONS] arg1 arg2"} c := &cobra.Command{Use: "do [OPTIONS] arg1 arg2"}
tmpdir, err := ioutil.TempDir("", "test-gen-md-tree") tmpdir, err := os.MkdirTemp("", "test-gen-md-tree")
if err != nil { if err != nil {
t.Fatalf("Failed to create tmpdir: %v", err) t.Fatalf("Failed to create tmpdir: %v", err)
} }
@ -110,7 +109,7 @@ func TestGenMdTree(t *testing.T) {
} }
func BenchmarkGenMarkdownToFile(b *testing.B) { func BenchmarkGenMarkdownToFile(b *testing.B) {
file, err := ioutil.TempFile("", "") file, err := os.CreateTemp("", "")
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }

View file

@ -16,7 +16,6 @@ package doc
import ( import (
"bytes" "bytes"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -81,7 +80,7 @@ func TestGenRSTNoTag(t *testing.T) {
func TestGenRSTTree(t *testing.T) { func TestGenRSTTree(t *testing.T) {
c := &cobra.Command{Use: "do [OPTIONS] arg1 arg2"} c := &cobra.Command{Use: "do [OPTIONS] arg1 arg2"}
tmpdir, err := ioutil.TempDir("", "test-gen-rst-tree") tmpdir, err := os.MkdirTemp("", "test-gen-rst-tree")
if err != nil { if err != nil {
t.Fatalf("Failed to create tmpdir: %s", err.Error()) t.Fatalf("Failed to create tmpdir: %s", err.Error())
} }
@ -97,7 +96,7 @@ func TestGenRSTTree(t *testing.T) {
} }
func BenchmarkGenReSTToFile(b *testing.B) { func BenchmarkGenReSTToFile(b *testing.B) {
file, err := ioutil.TempFile("", "") file, err := os.CreateTemp("", "")
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }

View file

@ -17,7 +17,6 @@ package doc
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -58,7 +57,7 @@ func TestGenYamlNoTag(t *testing.T) {
func TestGenYamlTree(t *testing.T) { func TestGenYamlTree(t *testing.T) {
c := &cobra.Command{Use: "do [OPTIONS] arg1 arg2"} c := &cobra.Command{Use: "do [OPTIONS] arg1 arg2"}
tmpdir, err := ioutil.TempDir("", "test-gen-yaml-tree") tmpdir, err := os.MkdirTemp("", "test-gen-yaml-tree")
if err != nil { if err != nil {
t.Fatalf("Failed to create tmpdir: %s", err.Error()) t.Fatalf("Failed to create tmpdir: %s", err.Error())
} }
@ -85,7 +84,7 @@ func TestGenYamlDocRunnable(t *testing.T) {
} }
func BenchmarkGenYamlToFile(b *testing.B) { func BenchmarkGenYamlToFile(b *testing.B) {
file, err := ioutil.TempFile("", "") file, err := os.CreateTemp("", "")
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }

View file

@ -35,7 +35,7 @@ package main
import ( import (
"log" "log"
"io/ioutil" "io"
"os" "os"
"k8s.io/kubernetes/pkg/kubectl/cmd" "k8s.io/kubernetes/pkg/kubectl/cmd"
@ -45,7 +45,7 @@ import (
) )
func main() { 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, "./") err := doc.GenMarkdownTree(kubectl, "./")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View file

@ -35,7 +35,7 @@ package main
import ( import (
"log" "log"
"io/ioutil" "io"
"os" "os"
"k8s.io/kubernetes/pkg/kubectl/cmd" "k8s.io/kubernetes/pkg/kubectl/cmd"
@ -45,7 +45,7 @@ import (
) )
func main() { 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.GenReSTTree(kubectl, "./") err := doc.GenReSTTree(kubectl, "./")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View file

@ -34,7 +34,7 @@ This program can actually generate docs for the kubectl command in the kubernete
package main package main
import ( import (
"io/ioutil" "io"
"log" "log"
"os" "os"
@ -45,7 +45,7 @@ import (
) )
func main() { 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.GenYamlTree(kubectl, "./") err := doc.GenYamlTree(kubectl, "./")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)