From 0f0f8dd99b54f8a60c0590fefdbb6072de1d4f12 Mon Sep 17 00:00:00 2001 From: Norbert Klar Date: Sat, 11 Jun 2022 08:42:54 +0200 Subject: [PATCH] Replacing the deprecated ioutil package (#569) * replaced ioutil in .md files * replaced ioutil in .go files --- command-line/v1/file_system_store_test.go | 3 +-- command-line/v1/tape_test.go | 4 ++-- command-line/v2/file_system_store_test.go | 3 +-- command-line/v2/tape_test.go | 4 ++-- command-line/v3/file_system_store_test.go | 3 +-- command-line/v3/tape_test.go | 4 ++-- context-aware-reader.md | 2 +- error-types.md | 2 +- io.md | 6 +++--- io/v3/file_system_store_test.go | 3 +-- io/v4/file_system_store_test.go | 3 +-- io/v5/file_system_store_test.go | 3 +-- io/v6/file_system_store_test.go | 3 +-- io/v7/file_system_store_test.go | 3 +-- io/v7/tape_test.go | 4 ++-- io/v8/file_system_store_test.go | 3 +-- io/v8/tape_test.go | 4 ++-- io/v9/file_system_store_test.go | 3 +-- io/v9/tape_test.go | 4 ++-- os-exec.md | 2 +- q-and-a/error-types/error-types_test.go | 4 ++-- q-and-a/error-types/v2/error-types_test.go | 4 ++-- q-and-a/os-exec/os-exec_test.go | 3 +-- time/v1/file_system_store_test.go | 3 +-- time/v1/tape_test.go | 4 ++-- time/v2/file_system_store_test.go | 3 +-- time/v2/tape_test.go | 4 ++-- time/v3/file_system_store_test.go | 3 +-- time/v3/tape_test.go | 4 ++-- websockets.md | 12 ++++++------ websockets/v1/file_system_store_test.go | 3 +-- websockets/v1/tape_test.go | 4 ++-- websockets/v2/file_system_store_test.go | 3 +-- websockets/v2/tape_test.go | 7 ++++--- websockets/v2/texas_holdem_test.go | 9 +++++---- 35 files changed, 61 insertions(+), 75 deletions(-) diff --git a/command-line/v1/file_system_store_test.go b/command-line/v1/file_system_store_test.go index 07d62ca46..764f2feaa 100644 --- a/command-line/v1/file_system_store_test.go +++ b/command-line/v1/file_system_store_test.go @@ -1,7 +1,6 @@ package poker import ( - "io/ioutil" "os" "testing" ) @@ -9,7 +8,7 @@ import ( func createTempFile(t testing.TB, initialData string) (*os.File, func()) { t.Helper() - tmpfile, err := ioutil.TempFile("", "db") + tmpfile, err := os.CreateTemp("", "db") if err != nil { t.Fatalf("could not create temp file %v", err) diff --git a/command-line/v1/tape_test.go b/command-line/v1/tape_test.go index e4117165b..1937fc491 100644 --- a/command-line/v1/tape_test.go +++ b/command-line/v1/tape_test.go @@ -1,7 +1,7 @@ package poker import ( - "io/ioutil" + "io" "testing" ) @@ -14,7 +14,7 @@ func TestTape_Write(t *testing.T) { tape.Write([]byte("abc")) file.Seek(0, 0) - newFileContents, _ := ioutil.ReadAll(file) + newFileContents, _ := io.ReadAll(file) got := string(newFileContents) want := "abc" diff --git a/command-line/v2/file_system_store_test.go b/command-line/v2/file_system_store_test.go index 07d62ca46..764f2feaa 100644 --- a/command-line/v2/file_system_store_test.go +++ b/command-line/v2/file_system_store_test.go @@ -1,7 +1,6 @@ package poker import ( - "io/ioutil" "os" "testing" ) @@ -9,7 +8,7 @@ import ( func createTempFile(t testing.TB, initialData string) (*os.File, func()) { t.Helper() - tmpfile, err := ioutil.TempFile("", "db") + tmpfile, err := os.CreateTemp("", "db") if err != nil { t.Fatalf("could not create temp file %v", err) diff --git a/command-line/v2/tape_test.go b/command-line/v2/tape_test.go index e4117165b..1937fc491 100644 --- a/command-line/v2/tape_test.go +++ b/command-line/v2/tape_test.go @@ -1,7 +1,7 @@ package poker import ( - "io/ioutil" + "io" "testing" ) @@ -14,7 +14,7 @@ func TestTape_Write(t *testing.T) { tape.Write([]byte("abc")) file.Seek(0, 0) - newFileContents, _ := ioutil.ReadAll(file) + newFileContents, _ := io.ReadAll(file) got := string(newFileContents) want := "abc" diff --git a/command-line/v3/file_system_store_test.go b/command-line/v3/file_system_store_test.go index 07d62ca46..764f2feaa 100644 --- a/command-line/v3/file_system_store_test.go +++ b/command-line/v3/file_system_store_test.go @@ -1,7 +1,6 @@ package poker import ( - "io/ioutil" "os" "testing" ) @@ -9,7 +8,7 @@ import ( func createTempFile(t testing.TB, initialData string) (*os.File, func()) { t.Helper() - tmpfile, err := ioutil.TempFile("", "db") + tmpfile, err := os.CreateTemp("", "db") if err != nil { t.Fatalf("could not create temp file %v", err) diff --git a/command-line/v3/tape_test.go b/command-line/v3/tape_test.go index e4117165b..1937fc491 100644 --- a/command-line/v3/tape_test.go +++ b/command-line/v3/tape_test.go @@ -1,7 +1,7 @@ package poker import ( - "io/ioutil" + "io" "testing" ) @@ -14,7 +14,7 @@ func TestTape_Write(t *testing.T) { tape.Write([]byte("abc")) file.Seek(0, 0) - newFileContents, _ := ioutil.ReadAll(file) + newFileContents, _ := io.ReadAll(file) got := string(newFileContents) want := "abc" diff --git a/context-aware-reader.md b/context-aware-reader.md index 8fb26f755..0d440dfe4 100644 --- a/context-aware-reader.md +++ b/context-aware-reader.md @@ -28,7 +28,7 @@ They combined two simple abstractions (`context.Context` and `io.Reader`) to sol Let's try and TDD some functionality so that we can wrap an `io.Reader` so it can be cancelled. -Testing this poses an interesting challenge. Normally when using an `io.Reader` you're usually supplying it to some other function and you don't really concern yourself with the details; such as `json.NewDecoder` or `ioutil.ReadAll`. +Testing this poses an interesting challenge. Normally when using an `io.Reader` you're usually supplying it to some other function and you don't really concern yourself with the details; such as `json.NewDecoder` or `io.ReadAll`. What we want to demonstrate is something like diff --git a/error-types.md b/error-types.md index 81772d0ef..3c720afe4 100644 --- a/error-types.md +++ b/error-types.md @@ -24,7 +24,7 @@ func DumbGetter(url string) (string, error) { } defer res.Body.Close() - body, _ := ioutil.ReadAll(res.Body) // ignoring err for brevity + body, _ := io.ReadAll(res.Body) // ignoring err for brevity return string(body), nil } diff --git a/io.md b/io.md index 09c7e7113..4a2235d13 100644 --- a/io.md +++ b/io.md @@ -459,7 +459,7 @@ Let's create some helper functions which will create a temporary file with some func createTempFile(t testing.TB, initialData string) (io.ReadWriteSeeker, func()) { t.Helper() - tmpfile, err := ioutil.TempFile("", "db") + tmpfile, err := os.CreateTemp("", "db") if err != nil { t.Fatalf("could not create temp file %v", err) @@ -483,7 +483,7 @@ func assertScoreEquals(t testing.TB, got, want int) { } ``` -[TempFile](https://golang.org/pkg/io/ioutil/#TempFile) creates a temporary file for us to use. The `"db"` value we've passed in is a prefix put on a random file name it will create. This is to ensure it won't clash with other files by accident. +[CreateTemp](https://pkg.go.dev/os#CreateTemp) creates a temporary file for us to use. The `"db"` value we've passed in is a prefix put on a random file name it will create. This is to ensure it won't clash with other files by accident. You'll notice we're not only returning our `ReadWriteSeeker` (the file) but also a function. We need to make sure that the file is removed once the test is finished. We don't want to leak details of the files into the test as it's prone to error and uninteresting for the reader. By returning a `removeFile` function, we can take care of the details in our helper and all the caller has to do is run `defer cleanDatabase()`. @@ -881,7 +881,7 @@ func TestTape_Write(t *testing.T) { tape.Write([]byte("abc")) file.Seek(0, 0) - newFileContents, _ := ioutil.ReadAll(file) + newFileContents, _ := io.ReadAll(file) got := string(newFileContents) want := "abc" diff --git a/io/v3/file_system_store_test.go b/io/v3/file_system_store_test.go index 3b5aa866e..a2dacd59c 100644 --- a/io/v3/file_system_store_test.go +++ b/io/v3/file_system_store_test.go @@ -2,7 +2,6 @@ package main import ( "io" - "io/ioutil" "os" "testing" ) @@ -10,7 +9,7 @@ import ( func createTempFile(t testing.TB, initialData string) (io.ReadWriteSeeker, func()) { t.Helper() - tmpfile, err := ioutil.TempFile("", "db") + tmpfile, err := os.CreateTemp("", "db") if err != nil { t.Fatalf("could not create temp file %v", err) diff --git a/io/v4/file_system_store_test.go b/io/v4/file_system_store_test.go index e5a813978..6bbaa6540 100644 --- a/io/v4/file_system_store_test.go +++ b/io/v4/file_system_store_test.go @@ -2,7 +2,6 @@ package main import ( "io" - "io/ioutil" "os" "testing" ) @@ -10,7 +9,7 @@ import ( func createTempFile(t testing.TB, initialData string) (io.ReadWriteSeeker, func()) { t.Helper() - tmpfile, err := ioutil.TempFile("", "db") + tmpfile, err := os.CreateTemp("", "db") if err != nil { t.Fatalf("could not create temp file %v", err) diff --git a/io/v5/file_system_store_test.go b/io/v5/file_system_store_test.go index e5a813978..6bbaa6540 100644 --- a/io/v5/file_system_store_test.go +++ b/io/v5/file_system_store_test.go @@ -2,7 +2,6 @@ package main import ( "io" - "io/ioutil" "os" "testing" ) @@ -10,7 +9,7 @@ import ( func createTempFile(t testing.TB, initialData string) (io.ReadWriteSeeker, func()) { t.Helper() - tmpfile, err := ioutil.TempFile("", "db") + tmpfile, err := os.CreateTemp("", "db") if err != nil { t.Fatalf("could not create temp file %v", err) diff --git a/io/v6/file_system_store_test.go b/io/v6/file_system_store_test.go index 64e0681bb..cc885e295 100644 --- a/io/v6/file_system_store_test.go +++ b/io/v6/file_system_store_test.go @@ -2,7 +2,6 @@ package main import ( "io" - "io/ioutil" "os" "testing" ) @@ -10,7 +9,7 @@ import ( func createTempFile(t testing.TB, initialData string) (io.ReadWriteSeeker, func()) { t.Helper() - tmpfile, err := ioutil.TempFile("", "db") + tmpfile, err := os.CreateTemp("", "db") if err != nil { t.Fatalf("could not create temp file %v", err) diff --git a/io/v7/file_system_store_test.go b/io/v7/file_system_store_test.go index eba273f05..030794dbf 100644 --- a/io/v7/file_system_store_test.go +++ b/io/v7/file_system_store_test.go @@ -1,7 +1,6 @@ package main import ( - "io/ioutil" "os" "testing" ) @@ -9,7 +8,7 @@ import ( func createTempFile(t testing.TB, initialData string) (*os.File, func()) { t.Helper() - tmpfile, err := ioutil.TempFile("", "db") + tmpfile, err := os.CreateTemp("", "db") if err != nil { t.Fatalf("could not create temp file %v", err) diff --git a/io/v7/tape_test.go b/io/v7/tape_test.go index 6385dfd3d..bc0444ee5 100644 --- a/io/v7/tape_test.go +++ b/io/v7/tape_test.go @@ -1,7 +1,7 @@ package main import ( - "io/ioutil" + "io" "testing" ) @@ -14,7 +14,7 @@ func TestTape_Write(t *testing.T) { tape.Write([]byte("abc")) file.Seek(0, 0) - newFileContents, _ := ioutil.ReadAll(file) + newFileContents, _ := io.ReadAll(file) got := string(newFileContents) want := "abc" diff --git a/io/v8/file_system_store_test.go b/io/v8/file_system_store_test.go index fa75827a2..45d89afbb 100644 --- a/io/v8/file_system_store_test.go +++ b/io/v8/file_system_store_test.go @@ -1,7 +1,6 @@ package main import ( - "io/ioutil" "os" "testing" ) @@ -9,7 +8,7 @@ import ( func createTempFile(t testing.TB, initialData string) (*os.File, func()) { t.Helper() - tmpfile, err := ioutil.TempFile("", "db") + tmpfile, err := os.CreateTemp("", "db") if err != nil { t.Fatalf("could not create temp file %v", err) diff --git a/io/v8/tape_test.go b/io/v8/tape_test.go index 6385dfd3d..bc0444ee5 100644 --- a/io/v8/tape_test.go +++ b/io/v8/tape_test.go @@ -1,7 +1,7 @@ package main import ( - "io/ioutil" + "io" "testing" ) @@ -14,7 +14,7 @@ func TestTape_Write(t *testing.T) { tape.Write([]byte("abc")) file.Seek(0, 0) - newFileContents, _ := ioutil.ReadAll(file) + newFileContents, _ := io.ReadAll(file) got := string(newFileContents) want := "abc" diff --git a/io/v9/file_system_store_test.go b/io/v9/file_system_store_test.go index 45a4ab344..a38308be3 100644 --- a/io/v9/file_system_store_test.go +++ b/io/v9/file_system_store_test.go @@ -1,7 +1,6 @@ package main import ( - "io/ioutil" "os" "testing" ) @@ -9,7 +8,7 @@ import ( func createTempFile(t testing.TB, initialData string) (*os.File, func()) { t.Helper() - tmpfile, err := ioutil.TempFile("", "db") + tmpfile, err := os.CreateTemp("", "db") if err != nil { t.Fatalf("could not create temp file %v", err) diff --git a/io/v9/tape_test.go b/io/v9/tape_test.go index 6385dfd3d..bc0444ee5 100644 --- a/io/v9/tape_test.go +++ b/io/v9/tape_test.go @@ -1,7 +1,7 @@ package main import ( - "io/ioutil" + "io" "testing" ) @@ -14,7 +14,7 @@ func TestTape_Write(t *testing.T) { tape.Write([]byte("abc")) file.Seek(0, 0) - newFileContents, _ := ioutil.ReadAll(file) + newFileContents, _ := io.ReadAll(file) got := string(newFileContents) want := "abc" diff --git a/os-exec.md b/os-exec.md index ffc3c5aad..c09a43c85 100644 --- a/os-exec.md +++ b/os-exec.md @@ -99,7 +99,7 @@ func getXMLFromCommand() io.Reader { out, _ := cmd.StdoutPipe() cmd.Start() - data, _ := ioutil.ReadAll(out) + data, _ := io.ReadAll(out) cmd.Wait() return bytes.NewReader(data) diff --git a/q-and-a/error-types/error-types_test.go b/q-and-a/error-types/error-types_test.go index ea2055c7f..52e5ba359 100644 --- a/q-and-a/error-types/error-types_test.go +++ b/q-and-a/error-types/error-types_test.go @@ -2,7 +2,7 @@ package errortypes import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "testing" @@ -30,7 +30,7 @@ func DumbGetter(url string) (string, error) { } defer res.Body.Close() - body, _ := ioutil.ReadAll(res.Body) // ignoring err for brevity + body, _ := io.ReadAll(res.Body) // ignoring err for brevity return string(body), nil } diff --git a/q-and-a/error-types/v2/error-types_test.go b/q-and-a/error-types/v2/error-types_test.go index 191e3ead2..37aabfe92 100644 --- a/q-and-a/error-types/v2/error-types_test.go +++ b/q-and-a/error-types/v2/error-types_test.go @@ -3,7 +3,7 @@ package errortypes import ( "errors" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "testing" @@ -31,7 +31,7 @@ func DumbGetter(url string) (string, error) { } defer res.Body.Close() - body, _ := ioutil.ReadAll(res.Body) // ignoring err for brevity + body, _ := io.ReadAll(res.Body) // ignoring err for brevity return string(body), nil } diff --git a/q-and-a/os-exec/os-exec_test.go b/q-and-a/os-exec/os-exec_test.go index ad19d05e9..c3c07a067 100644 --- a/q-and-a/os-exec/os-exec_test.go +++ b/q-and-a/os-exec/os-exec_test.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/xml" "io" - "io/ioutil" "os/exec" "strings" "testing" @@ -25,7 +24,7 @@ func getXMLFromCommand() io.Reader { out, _ := cmd.StdoutPipe() cmd.Start() - data, _ := ioutil.ReadAll(out) + data, _ := io.ReadAll(out) cmd.Wait() return bytes.NewReader(data) diff --git a/time/v1/file_system_store_test.go b/time/v1/file_system_store_test.go index 366b166eb..4449725e8 100644 --- a/time/v1/file_system_store_test.go +++ b/time/v1/file_system_store_test.go @@ -1,7 +1,6 @@ package poker import ( - "io/ioutil" "os" "testing" ) @@ -9,7 +8,7 @@ import ( func createTempFile(t testing.TB, initialData string) (*os.File, func()) { t.Helper() - tmpfile, err := ioutil.TempFile("", "db") + tmpfile, err := os.CreateTemp("", "db") if err != nil { t.Fatalf("could not create temp file %v", err) diff --git a/time/v1/tape_test.go b/time/v1/tape_test.go index e4117165b..1937fc491 100644 --- a/time/v1/tape_test.go +++ b/time/v1/tape_test.go @@ -1,7 +1,7 @@ package poker import ( - "io/ioutil" + "io" "testing" ) @@ -14,7 +14,7 @@ func TestTape_Write(t *testing.T) { tape.Write([]byte("abc")) file.Seek(0, 0) - newFileContents, _ := ioutil.ReadAll(file) + newFileContents, _ := io.ReadAll(file) got := string(newFileContents) want := "abc" diff --git a/time/v2/file_system_store_test.go b/time/v2/file_system_store_test.go index 557a287b4..4ef693922 100644 --- a/time/v2/file_system_store_test.go +++ b/time/v2/file_system_store_test.go @@ -1,7 +1,6 @@ package poker import ( - "io/ioutil" "os" "testing" ) @@ -9,7 +8,7 @@ import ( func createTempFile(t testing.TB, initialData string) (*os.File, func()) { t.Helper() - tmpfile, err := ioutil.TempFile("", "db") + tmpfile, err := os.CreateTemp("", "db") if err != nil { t.Fatalf("could not create temp file %v", err) diff --git a/time/v2/tape_test.go b/time/v2/tape_test.go index e4117165b..1937fc491 100644 --- a/time/v2/tape_test.go +++ b/time/v2/tape_test.go @@ -1,7 +1,7 @@ package poker import ( - "io/ioutil" + "io" "testing" ) @@ -14,7 +14,7 @@ func TestTape_Write(t *testing.T) { tape.Write([]byte("abc")) file.Seek(0, 0) - newFileContents, _ := ioutil.ReadAll(file) + newFileContents, _ := io.ReadAll(file) got := string(newFileContents) want := "abc" diff --git a/time/v3/file_system_store_test.go b/time/v3/file_system_store_test.go index 557a287b4..4ef693922 100644 --- a/time/v3/file_system_store_test.go +++ b/time/v3/file_system_store_test.go @@ -1,7 +1,6 @@ package poker import ( - "io/ioutil" "os" "testing" ) @@ -9,7 +8,7 @@ import ( func createTempFile(t testing.TB, initialData string) (*os.File, func()) { t.Helper() - tmpfile, err := ioutil.TempFile("", "db") + tmpfile, err := os.CreateTemp("", "db") if err != nil { t.Fatalf("could not create temp file %v", err) diff --git a/time/v3/tape_test.go b/time/v3/tape_test.go index e4117165b..1937fc491 100644 --- a/time/v3/tape_test.go +++ b/time/v3/tape_test.go @@ -1,7 +1,7 @@ package poker import ( - "io/ioutil" + "io" "testing" ) @@ -14,7 +14,7 @@ func TestTape_Write(t *testing.T) { tape.Write([]byte("abc")) file.Seek(0, 0) - newFileContents, _ := ioutil.ReadAll(file) + newFileContents, _ := io.ReadAll(file) got := string(newFileContents) want := "abc" diff --git a/websockets.md b/websockets.md index 6a61427e2..986541bf6 100644 --- a/websockets.md +++ b/websockets.md @@ -592,7 +592,7 @@ Let the compiler tell you what you need to fix. The change isn't so bad: - Update `TexasHoldem` so it properly implements `Game` - In `CLI` when we start the game, pass in our `out` property (`cli.game.Start(numberOfPlayers, cli.out)`) -- In `TexasHoldem`'s test i use `game.Start(5, ioutil.Discard)` to fix the compilation problem and configure the alert output to be discarded +- In `TexasHoldem`'s test i use `game.Start(5, io.Discard)` to fix the compilation problem and configure the alert output to be discarded If you've got everything right, everything should be green! Now we can try and use `Game` within `Server`. @@ -722,7 +722,7 @@ func (p *PlayerServer) webSocket(w http.ResponseWriter, r *http.Request) { _, numberOfPlayersMsg, _ := conn.ReadMessage() numberOfPlayers, _ := strconv.Atoi(string(numberOfPlayersMsg)) - p.game.Start(numberOfPlayers, ioutil.Discard) //todo: Don't discard the blinds messages! + p.game.Start(numberOfPlayers, io.Discard) //todo: Don't discard the blinds messages! _, winner, _ := conn.ReadMessage() p.game.Finish(string(winner)) @@ -731,7 +731,7 @@ func (p *PlayerServer) webSocket(w http.ResponseWriter, r *http.Request) { Hooray! The tests pass. -We are not going to send the blind messages anywhere _just yet_ as we need to have a think about that. When we call `game.Start` we send in `ioutil.Discard` which will just discard any messages written to it. +We are not going to send the blind messages anywhere _just yet_ as we need to have a think about that. When we call `game.Start` we send in `io.Discard` which will just discard any messages written to it. For now start the web server up. You'll need to update the `main.go` to pass a `Game` to the `PlayerServer` @@ -801,7 +801,7 @@ func (p *PlayerServer) webSocket(w http.ResponseWriter, r *http.Request) { numberOfPlayersMsg := ws.WaitForMsg() numberOfPlayers, _ := strconv.Atoi(numberOfPlayersMsg) - p.game.Start(numberOfPlayers, ioutil.Discard) //todo: Don't discard the blinds messages! + p.game.Start(numberOfPlayers, io.Discard) //todo: Don't discard the blinds messages! winner := ws.WaitForMsg() p.game.Finish(winner) @@ -817,7 +817,7 @@ Sometimes when we're not sure how to do something, it's best just to play around The problematic line of code we have is ```go -p.game.Start(numberOfPlayers, ioutil.Discard) //todo: Don't discard the blinds messages! +p.game.Start(numberOfPlayers, io.Discard) //todo: Don't discard the blinds messages! ``` We need to pass in an `io.Writer` for the game to write the blind alerts to. @@ -868,7 +868,7 @@ blindIncrement := time.Duration(5+numberOfPlayers) * time.Second // (rather than You should see it working! The blind amount increments in the browser as if by magic. -Now let's revert the code and think how to test it. In order to _implement_ it all we did was pass through to `StartGame` was `playerServerWS` rather than `ioutil.Discard` so that might make you think we should perhaps spy on the call to verify it works. +Now let's revert the code and think how to test it. In order to _implement_ it all we did was pass through to `StartGame` was `playerServerWS` rather than `io.Discard` so that might make you think we should perhaps spy on the call to verify it works. Spying is great and helps us check implementation details but we should always try and favour testing the _real_ behaviour if we can because when you decide to refactor it's often spy tests that start failing because they are usually checking implementation details that you're trying to change. diff --git a/websockets/v1/file_system_store_test.go b/websockets/v1/file_system_store_test.go index 557a287b4..4ef693922 100644 --- a/websockets/v1/file_system_store_test.go +++ b/websockets/v1/file_system_store_test.go @@ -1,7 +1,6 @@ package poker import ( - "io/ioutil" "os" "testing" ) @@ -9,7 +8,7 @@ import ( func createTempFile(t testing.TB, initialData string) (*os.File, func()) { t.Helper() - tmpfile, err := ioutil.TempFile("", "db") + tmpfile, err := os.CreateTemp("", "db") if err != nil { t.Fatalf("could not create temp file %v", err) diff --git a/websockets/v1/tape_test.go b/websockets/v1/tape_test.go index e4117165b..1937fc491 100644 --- a/websockets/v1/tape_test.go +++ b/websockets/v1/tape_test.go @@ -1,7 +1,7 @@ package poker import ( - "io/ioutil" + "io" "testing" ) @@ -14,7 +14,7 @@ func TestTape_Write(t *testing.T) { tape.Write([]byte("abc")) file.Seek(0, 0) - newFileContents, _ := ioutil.ReadAll(file) + newFileContents, _ := io.ReadAll(file) got := string(newFileContents) want := "abc" diff --git a/websockets/v2/file_system_store_test.go b/websockets/v2/file_system_store_test.go index 15cba01e0..6ab52830c 100644 --- a/websockets/v2/file_system_store_test.go +++ b/websockets/v2/file_system_store_test.go @@ -1,7 +1,6 @@ package poker_test import ( - "io/ioutil" "os" "testing" @@ -11,7 +10,7 @@ import ( func createTempFile(t testing.TB, initialData string) (*os.File, func()) { t.Helper() - tmpfile, err := ioutil.TempFile("", "db") + tmpfile, err := os.CreateTemp("", "db") if err != nil { t.Fatalf("could not create temp file %v", err) diff --git a/websockets/v2/tape_test.go b/websockets/v2/tape_test.go index 8c0d18fa8..86e225988 100644 --- a/websockets/v2/tape_test.go +++ b/websockets/v2/tape_test.go @@ -1,9 +1,10 @@ package poker_test import ( - "github.com/quii/learn-go-with-tests/websockets/v2" - "io/ioutil" + "io" "testing" + + poker "github.com/quii/learn-go-with-tests/websockets/v2" ) func TestTape_Write(t *testing.T) { @@ -15,7 +16,7 @@ func TestTape_Write(t *testing.T) { tape.Write([]byte("abc")) file.Seek(0, 0) - newFileContents, _ := ioutil.ReadAll(file) + newFileContents, _ := io.ReadAll(file) got := string(newFileContents) want := "abc" diff --git a/websockets/v2/texas_holdem_test.go b/websockets/v2/texas_holdem_test.go index 9bdc50d4e..5cbc33c29 100644 --- a/websockets/v2/texas_holdem_test.go +++ b/websockets/v2/texas_holdem_test.go @@ -2,10 +2,11 @@ package poker_test import ( "fmt" - "github.com/quii/learn-go-with-tests/websockets/v2" - "io/ioutil" + "io" "testing" "time" + + poker "github.com/quii/learn-go-with-tests/websockets/v2" ) func TestGame_Start(t *testing.T) { @@ -13,7 +14,7 @@ func TestGame_Start(t *testing.T) { blindAlerter := &poker.SpyBlindAlerter{} game := poker.NewTexasHoldem(blindAlerter, dummyPlayerStore) - game.Start(5, ioutil.Discard) + game.Start(5, io.Discard) cases := []poker.ScheduledAlert{ {At: 0 * time.Second, Amount: 100}, @@ -36,7 +37,7 @@ func TestGame_Start(t *testing.T) { blindAlerter := &poker.SpyBlindAlerter{} game := poker.NewTexasHoldem(blindAlerter, dummyPlayerStore) - game.Start(7, ioutil.Discard) + game.Start(7, io.Discard) cases := []poker.ScheduledAlert{ {At: 0 * time.Second, Amount: 100},