Skip to content

Commit

Permalink
remove ioutil, use testing.TempDir
Browse files Browse the repository at this point in the history
Signed-off-by: junya koyama <[email protected]>
  • Loading branch information
arukiidou authored and owenrumney committed Nov 4, 2023
1 parent 4346d6b commit 3eb71b3
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 12 deletions.
3 changes: 1 addition & 2 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"encoding/json"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -96,7 +95,7 @@ func main() {
// load the example results file
func loadTfsecResults() (TfsecResults, error) {

jsonResult, err := ioutil.ReadFile("../example/results.json")
jsonResult, err := os.ReadFile("../example/results.json")
if err != nil {
panic(err)
}
Expand Down
3 changes: 1 addition & 2 deletions sarif/sarif.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
)

Expand Down Expand Up @@ -45,7 +44,7 @@ func Open(filename string) (*Report, error) {
return nil, fmt.Errorf("the provided file path doesn't have a file")
}

content, err := ioutil.ReadFile(filename)
content, err := os.ReadFile(filename)
if err != nil {
return nil, fmt.Errorf("the provided filepath could not be opened. %w", err)
}
Expand Down
5 changes: 2 additions & 3 deletions test/report_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package test

import (
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -93,11 +92,11 @@ func Test_load_sarif_report_from_file(t *testing.T) {
]
}`

file, err := ioutil.TempFile(os.TempDir(), "sarifReport")
file, err := os.CreateTemp(t.TempDir(), "sarifReport")
assert.NoError(t, err)
defer file.Close()

ioutil.WriteFile(file.Name(), []byte(content), 755)
os.WriteFile(file.Name(), []byte(content), 755)

given.a_report_is_loaded_from_a_file(file.Name())
then.the_report_has_expected_driver_name_and_information_uri("ESLint", "https://eslint.org")
Expand Down
3 changes: 1 addition & 2 deletions v2/sarif/sarif.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
)

Expand Down Expand Up @@ -58,7 +57,7 @@ func Open(filename string) (*Report, error) {
return nil, fmt.Errorf("the provided file path doesn't have a file")
}

content, err := ioutil.ReadFile(filename)
content, err := os.ReadFile(filename)
if err != nil {
return nil, fmt.Errorf("the provided filepath could not be opened. %w", err)
}
Expand Down
5 changes: 2 additions & 3 deletions v2/test/report_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package test

import (
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -93,11 +92,11 @@ func Test_load_sarif_report_from_file(t *testing.T) {
]
}`

file, err := ioutil.TempFile(os.TempDir(), "sarifReport")
file, err := os.TempFile(t.TempDir(), "sarifReport")
assert.NoError(t, err)
defer file.Close()

ioutil.WriteFile(file.Name(), []byte(content), 755)
os.WriteFile(file.Name(), []byte(content), 755)

given.a_report_is_loaded_from_a_file(file.Name())
then.the_report_has_expected_driver_name_and_information_uri("ESLint", "https://eslint.org")
Expand Down

0 comments on commit 3eb71b3

Please sign in to comment.