Unverified Commit 0eb6c050 authored by Eng Zer Jun's avatar Eng Zer Jun
Browse files

refactor: move from io/ioutil to io and os package

The io/ioutil package has been deprecated as of Go 1.16, see
https://golang.org/doc/go1.16#ioutil

. This commit replaces the existing
io/ioutil functions with their new definitions in io and os packages.
Signed-off-by: default avatarEng Zer Jun <engzerjun@gmail.com>
parent 44a515d4
No related merge requests found
Showing with 15 additions and 18 deletions
+15 -18
......@@ -3,11 +3,11 @@ package files
import (
"bytes"
"fmt"
"gopkg.in/yaml.v3"
"io/ioutil"
"os"
"path/filepath"
"gopkg.in/yaml.v3"
"github.com/datreeio/datree/bl/validation"
"github.com/datreeio/datree/pkg/extractor"
)
......@@ -71,7 +71,7 @@ func ExtractYamlFileToUnknownStruct(path string) (UnknownStruct, error) {
return nil, err
}
yamlContent, err := ioutil.ReadFile(absolutePath)
yamlContent, err := os.ReadFile(absolutePath)
if err != nil {
return nil, err
}
......
......@@ -3,7 +3,6 @@ package test
import (
"fmt"
"io"
"io/ioutil"
"os"
"strings"
......@@ -158,7 +157,7 @@ func test(ctx *TestCommandContext, paths []string, flags TestCommandFlags) error
if len(paths) > 1 {
return fmt.Errorf(fmt.Sprintf("Unexpected args: [%s]", strings.Join(paths[1:], ",")))
}
tempFile, err := ioutil.TempFile("", "datree_temp_*.yaml")
tempFile, err := os.CreateTemp("", "datree_temp_*.yaml")
if err != nil {
return err
}
......
......@@ -2,7 +2,7 @@ package version
import (
"bytes"
"io/ioutil"
"io"
"testing"
"github.com/datreeio/datree/bl/messager"
......@@ -45,13 +45,13 @@ func Test_ExecuteCommand(t *testing.T) {
cmd := New(&VersionCommandContext{
CliVersion: "1.2.3",
Messager: messager,
Printer: printer,
Printer: printer,
})
b := bytes.NewBufferString("1.2.3")
cmd.SetOut(b)
cmd.Execute()
out, err := ioutil.ReadAll(b)
out, err := io.ReadAll(b)
if err != nil {
t.Fatal(err)
}
......
......@@ -4,8 +4,8 @@ import (
"bytes"
"encoding/json"
"errors"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"testing"
......@@ -231,7 +231,7 @@ func readMock(path string) ([]extractor.Configuration, error) {
var configurations []extractor.Configuration
absPath, _ := filepath.Abs(path)
content, err := ioutil.ReadFile(absPath)
content, err := os.ReadFile(absPath)
if err != nil {
return []extractor.Configuration{}, err
......
......@@ -3,7 +3,7 @@ package extractor
import (
"bytes"
"io"
"io/ioutil"
"os"
"gopkg.in/yaml.v3"
)
......@@ -54,7 +54,7 @@ func extractYamlConfigurations(content string) (*[]Configuration, error) {
}
func ReadFileContent(filepath string) (string, error) {
dat, err := ioutil.ReadFile(filepath)
dat, err := os.ReadFile(filepath)
if err != nil {
return "", err
}
......
package fileReader
import (
"io/ioutil"
"os"
"path/filepath"
......@@ -29,7 +28,7 @@ type FileReaderOptions struct {
func CreateFileReader(opts *FileReaderOptions) *FileReader {
fileReader := &FileReader{
readFile: ioutil.ReadFile,
readFile: os.ReadFile,
glob: doublestar.Glob,
abs: filepath.Abs,
stat: os.Stat,
......
......@@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
......@@ -67,7 +66,7 @@ func (c *Client) Request(method string, resourceURI string, body interface{}, he
defer response.Body.Close()
b, err := ioutil.ReadAll(response.Body)
b, err := io.ReadAll(response.Body)
if err != nil {
return responseBody, err
}
......
......@@ -3,7 +3,7 @@ package httpClient
import (
"bytes"
"compress/gzip"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
......@@ -100,7 +100,7 @@ func createMockServer(t *testing.T, tc *testCase) *httptest.Server {
assert.Equal(t, tc.path, req.URL.String())
body, _ := ioutil.ReadAll(req.Body)
body, _ := io.ReadAll(req.Body)
if len(tc.expectedRequestBody) > 0 {
gunzippedBody := gunzipBody(body)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment