Skip to content

Commit 5d7f382

Browse files
committed
Remove ioutil usage in favor of os
ioutil has been deprecated, let's use os instead.
1 parent 0d3e8ba commit 5d7f382

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

helpers/utilities.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"errors"
77
"fmt"
88
"io"
9-
"io/ioutil"
109
"log"
1110
"os"
1211
"os/exec"
@@ -94,7 +93,7 @@ func assertContentDirectory(tc *testConfig.TestConfig) error {
9493
}
9594

9695
func cloneContentDir() (string, error) {
97-
dir, tmperr := ioutil.TempDir("", "content-*")
96+
dir, tmperr := os.MkdirTemp("", "content-*")
9897
if tmperr != nil {
9998
return "", fmt.Errorf("couldn't create tmpdir: %w", tmperr)
10099
}
@@ -860,7 +859,7 @@ func assertResultsAgainstAssertionFile(
860859

861860
// loadAssertionsFromPath loads rule assertions from a specific file path.
862861
func loadAssertionsFromPath(p string) (*RuleTestResults, error) {
863-
data, err := ioutil.ReadFile(p)
862+
data, err := os.ReadFile(p)
864863
if err != nil {
865864
return nil, err
866865
}
@@ -976,7 +975,7 @@ func GenerateAssertionFileFromResults(
976975
}
977976

978977
fullPath := path.Join(tc.LogDir, assertionFile)
979-
err = ioutil.WriteFile(fullPath, data, 0o600)
978+
err = os.WriteFile(fullPath, data, 0o600)
980979
if err != nil {
981980
return fmt.Errorf("failed to write assertion file: %w", err)
982981
}
@@ -1740,7 +1739,7 @@ func SaveResultAsYAML(tc *testConfig.TestConfig, results map[string]string, file
17401739
if err != nil {
17411740
return fmt.Errorf("failed to marshal results to YAML: %w", err)
17421741
}
1743-
err = ioutil.WriteFile(p, yamlData, 0o600)
1742+
err = os.WriteFile(p, yamlData, 0o600)
17441743
if err != nil {
17451744
return fmt.Errorf("failed to write YAML file: %w", err)
17461745
}
@@ -1755,7 +1754,7 @@ func SaveMismatchesAsYAML(tc *testConfig.TestConfig, mismatchedAssertions []Asse
17551754
if err != nil {
17561755
return fmt.Errorf("failed to marshal results to YAML: %w", err)
17571756
}
1758-
err = ioutil.WriteFile(p, yamlData, 0o600)
1757+
err = os.WriteFile(p, yamlData, 0o600)
17591758
if err != nil {
17601759
return fmt.Errorf("failed to write YAML file: %w", err)
17611760
}
@@ -1813,7 +1812,7 @@ func GenerateMismatchReport(
18131812
f := fmt.Sprintf("%s-report.md", bindingName)
18141813
p := path.Join(tc.LogDir, f)
18151814

1816-
err := ioutil.WriteFile(p, []byte(report.String()), 0o600)
1815+
err := os.WriteFile(p, []byte(report.String()), 0o600)
18171816
if err != nil {
18181817
return fmt.Errorf("failed to write markdown report: %w", err)
18191818
}
@@ -1825,7 +1824,7 @@ func GenerateMismatchReport(
18251824
htmlFilename := fmt.Sprintf("%s-report.html", bindingName)
18261825
htmlFilePath := path.Join(tc.LogDir, htmlFilename)
18271826

1828-
err = ioutil.WriteFile(htmlFilePath, []byte(htmlContent), 0o600)
1827+
err = os.WriteFile(htmlFilePath, []byte(htmlContent), 0o600)
18291828
if err != nil {
18301829
return fmt.Errorf("failed to write HTML report: %w", err)
18311830
}

0 commit comments

Comments
 (0)