-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[metricbeat] replace depricated io/ioutil #36963
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -20,9 +20,9 @@ package testing | |||||||
import ( | ||||||||
"encoding/json" | ||||||||
"fmt" | ||||||||
"io/ioutil" | ||||||||
"net/http" | ||||||||
"net/http/httptest" | ||||||||
"os" | ||||||||
"path/filepath" | ||||||||
"sort" | ||||||||
"strings" | ||||||||
|
@@ -131,7 +131,7 @@ func ReadDataConfig(t *testing.T, f string) DataConfig { | |||||||
t.Helper() | ||||||||
config := defaultDataConfig() | ||||||||
|
||||||||
configFile, err := ioutil.ReadFile(f) | ||||||||
configFile, err := os.ReadFile(f) | ||||||||
if err != nil { | ||||||||
t.Fatalf("failed to read '%s': %v", f, err) | ||||||||
} | ||||||||
|
@@ -294,13 +294,13 @@ func runTest(t *testing.T, file string, module, metricSetName string, config Dat | |||||||
if err != nil { | ||||||||
t.Fatal(err) | ||||||||
} | ||||||||
if err = ioutil.WriteFile(expectedFile, outputIndented, 0644); err != nil { | ||||||||
if err = os.WriteFile(expectedFile, outputIndented, 0644); err != nil { | ||||||||
t.Fatal(err) | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
// Read expected file | ||||||||
expected, err := ioutil.ReadFile(expectedFile) | ||||||||
expected, err := os.ReadFile(expectedFile) | ||||||||
if err != nil { | ||||||||
t.Fatalf("could not read file: %s", err) | ||||||||
} | ||||||||
|
@@ -362,7 +362,11 @@ func writeDataJSON(t *testing.T, data mapstr.M, path string) { | |||||||
// Add hardcoded timestamp | ||||||||
data.Put("@timestamp", "2019-03-01T08:05:34.853Z") | ||||||||
output, err := json.MarshalIndent(&data, "", " ") | ||||||||
if err = ioutil.WriteFile(path, output, 0644); err != nil { | ||||||||
if err != nil { | ||||||||
t.Error(err) | ||||||||
t.FailNow() | ||||||||
Comment on lines
+366
to
+367
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at existing code, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The bits of the codebase I mostly work with follow a different pattern 😅 , anyway this one is not a blocker. |
||||||||
} | ||||||||
if err = os.WriteFile(path, output, 0644); err != nil { | ||||||||
t.Fatal(err) | ||||||||
} | ||||||||
} | ||||||||
|
@@ -494,7 +498,7 @@ func getConfig(module, metricSet, url string, config DataConfig) map[string]inte | |||||||
// server starts a server with a mock output | ||||||||
func server(t *testing.T, path string, url string, contentType string) *httptest.Server { | ||||||||
|
||||||||
body, err := ioutil.ReadFile(path) | ||||||||
body, err := os.ReadFile(path) | ||||||||
if err != nil { | ||||||||
t.Fatalf("could not read file: %s", err) | ||||||||
} | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That can be replaced by a single
t.Fatal()