diff --git a/config/config.go b/config/config.go index 23647cb1..92dd8bda 100644 --- a/config/config.go +++ b/config/config.go @@ -3,8 +3,8 @@ package config import ( "encoding/json" "fmt" - "io/ioutil" "log" + "os" "strings" "sync" "time" @@ -85,7 +85,7 @@ func NewConfig() *Config { } func loadJSON(filename string, v interface{}) error { - buf, err := ioutil.ReadFile(filename) + buf, err := os.ReadFile(filename) if err != nil { return fmt.Errorf("read error: %v", err) } diff --git a/config_test.go b/config_test.go index f848afb0..fbd200dc 100644 --- a/config_test.go +++ b/config_test.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "io/ioutil" "log" "os" "testing" @@ -15,7 +14,7 @@ import ( const testLogConf = "config/container-logs.json" func configfile(s string) string { - tmp, err := ioutil.TempFile("", "config") + tmp, err := os.CreateTemp("", "config") if err != nil { log.Fatal(err) } diff --git a/metadata.go b/metadata.go index 8d226e34..b8ed2768 100644 --- a/metadata.go +++ b/metadata.go @@ -5,8 +5,8 @@ package main import ( "encoding/json" - "io/ioutil" "log" + "os" "path/filepath" "time" @@ -39,7 +39,7 @@ func (mp *MetadataProcessor) OnSessionStopped(stoppedSession event.StoppedSessio return } filename := filepath.Join(logOutputDir, stoppedSession.SessionId+metadataFileExtension) - err = ioutil.WriteFile(filename, data, 0644) + err = os.WriteFile(filename, data, 0644) if err != nil { log.Printf("[%d] [METADATA] [%s] [Failed to save to %s: %v]", stoppedSession.RequestId, stoppedSession.SessionId, filename, err) return diff --git a/s3_test.go b/s3_test.go index b8e14866..7ba0fe69 100644 --- a/s3_test.go +++ b/s3_test.go @@ -5,10 +5,10 @@ package main import ( "context" - "io/ioutil" "net" "net/http" "net/http/httptest" + "os" "strings" "testing" "time" @@ -64,7 +64,7 @@ func TestS3Uploader(t *testing.T) { ReducedRedundancy: true, } uploader.Init() - f, _ := ioutil.TempFile("", "some-file") + f, _ := os.CreateTemp("", "some-file") input := event.CreatedFile{ Event: event.Event{ RequestId: 4342, diff --git a/selenoid.go b/selenoid.go index 12713670..8e1f3aa3 100644 --- a/selenoid.go +++ b/selenoid.go @@ -10,7 +10,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "log" "net" "net/http" @@ -112,7 +111,7 @@ func create(w http.ResponseWriter, r *http.Request) { sessionStartTime := time.Now() requestId := serial() user, remote := util.RequestInfo(r) - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) r.Body.Close() if err != nil { log.Printf("[%d] [ERROR_READING_REQUEST] [%v]", requestId, err) @@ -680,7 +679,7 @@ func logs(w http.ResponseWriter, r *http.Request) { } func listFilesAsJson(requestId uint64, w http.ResponseWriter, dir string, errStatus string) { - files, err := ioutil.ReadDir(dir) + files, err := os.ReadDir(dir) if err != nil { log.Printf("[%d] [%s] [%s]", requestId, errStatus, fmt.Sprintf("Failed to list directory %s: %v", logOutputDir, err)) w.WriteHeader(http.StatusInternalServerError) diff --git a/selenoid_test.go b/selenoid_test.go index 9983d8d2..d15c1e5b 100644 --- a/selenoid_test.go +++ b/selenoid_test.go @@ -5,7 +5,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "log" "net/http" "net/http/httptest" @@ -34,8 +34,8 @@ var ( func init() { enableFileUpload = true - videoOutputDir, _ = ioutil.TempDir("", "selenoid-test") - logOutputDir, _ = ioutil.TempDir("", "selenoid-test") + videoOutputDir, _ = os.MkdirTemp("", "selenoid-test") + logOutputDir, _ = os.MkdirTemp("", "selenoid-test") saveAllLogs = true gitRevision = "test-revision" ggrHost = &ggr.Host{ @@ -652,7 +652,7 @@ func TestFileUpload(t *testing.T) { f, err := os.Open(jsonResponse["value"]) AssertThat(t, err, Is{nil}) - content, err := ioutil.ReadAll(f) + content, err := io.ReadAll(f) AssertThat(t, err, Is{nil}) AssertThat(t, string(content), EqualTo{"Hello World!"}) @@ -720,7 +720,7 @@ func TestPing(t *testing.T) { AssertThat(t, rsp.Body, Is{Not{nil}}) var data map[string]interface{} - bt, readErr := ioutil.ReadAll(rsp.Body) + bt, readErr := io.ReadAll(rsp.Body) AssertThat(t, readErr, Is{nil}) jsonErr := json.Unmarshal(bt, &data) AssertThat(t, jsonErr, Is{nil}) @@ -743,7 +743,7 @@ func TestStatus(t *testing.T) { AssertThat(t, rsp.Body, Is{Not{nil}}) var data map[string]interface{} - bt, readErr := ioutil.ReadAll(rsp.Body) + bt, readErr := io.ReadAll(rsp.Body) AssertThat(t, readErr, Is{nil}) jsonErr := json.Unmarshal(bt, &data) AssertThat(t, jsonErr, Is{nil}) @@ -760,7 +760,7 @@ func TestStatus(t *testing.T) { func TestServeAndDeleteVideoFile(t *testing.T) { fileName := "testfile" filePath := filepath.Join(videoOutputDir, fileName) - ioutil.WriteFile(filePath, []byte("test-data"), 0644) + os.WriteFile(filePath, []byte("test-data"), 0644) rsp, err := http.Get(With(srv.URL).Path("/video/testfile")) AssertThat(t, err, Is{nil}) @@ -787,7 +787,7 @@ func TestServeAndDeleteVideoFile(t *testing.T) { func TestServeAndDeleteLogFile(t *testing.T) { fileName := "logfile.log" filePath := filepath.Join(logOutputDir, fileName) - ioutil.WriteFile(filePath, []byte("test-data"), 0644) + os.WriteFile(filePath, []byte("test-data"), 0644) rsp, err := http.Get(With(srv.URL).Path("/logs/logfile.log")) AssertThat(t, err, Is{nil}) @@ -822,7 +822,7 @@ func TestFileDownload(t *testing.T) { rsp, err := http.Get(With(srv.URL).Path(fmt.Sprintf("/download/%s/testfile", sess["sessionId"]))) AssertThat(t, err, Is{nil}) AssertThat(t, rsp, Code{http.StatusOK}) - data, err := ioutil.ReadAll(rsp.Body) + data, err := io.ReadAll(rsp.Body) AssertThat(t, err, Is{nil}) AssertThat(t, string(data), EqualTo{"test-data"}) @@ -848,7 +848,7 @@ func TestClipboard(t *testing.T) { rsp, err := http.Get(With(srv.URL).Path(fmt.Sprintf("/clipboard/%s", sess["sessionId"]))) AssertThat(t, err, Is{nil}) AssertThat(t, rsp, Code{http.StatusOK}) - data, err := ioutil.ReadAll(rsp.Body) + data, err := io.ReadAll(rsp.Body) AssertThat(t, err, Is{nil}) AssertThat(t, string(data), EqualTo{"test-clipboard-value"}) diff --git a/service_test.go b/service_test.go index 40d3d51c..b59f6289 100644 --- a/service_test.go +++ b/service_test.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "net" "net/http" "net/http/httptest" @@ -223,7 +222,7 @@ func testConfig(env *service.Environment) *config.Config { } func testEnvironment() *service.Environment { - logOutputDir, _ = ioutil.TempDir("", "selenoid-test") + logOutputDir, _ = os.MkdirTemp("", "selenoid-test") return &service.Environment{ CPU: int64(0), Memory: int64(0),