summaryrefslogtreecommitdiff
path: root/compat/json/borrowed_stream_test.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@datawire.io>2022-08-17 19:57:00 -0600
committerLuke Shumaker <lukeshu@datawire.io>2022-08-17 19:57:00 -0600
commit3bd2e0e93647b806a68f06f319ea23511ec24a37 (patch)
tree0c0f56296d0fe49e34e23d7738aed4dd60ca32e1 /compat/json/borrowed_stream_test.go
parentb2bf19e062ad1ce46dbf9107f5c3b47354f64d03 (diff)
Get the borrowed files passing the linter
Diffstat (limited to 'compat/json/borrowed_stream_test.go')
-rw-r--r--compat/json/borrowed_stream_test.go16
1 files changed, 11 insertions, 5 deletions
diff --git a/compat/json/borrowed_stream_test.go b/compat/json/borrowed_stream_test.go
index 658e347..edeab4a 100644
--- a/compat/json/borrowed_stream_test.go
+++ b/compat/json/borrowed_stream_test.go
@@ -81,7 +81,9 @@ func TestEncoderIndent(t *testing.T) {
enc := NewEncoder(&buf)
enc.SetIndent(">", ".")
for _, v := range streamTest {
- enc.Encode(v)
+ if err := enc.Encode(v); err != nil { // MODIFIED: check the error
+ t.Error("Encode:", err) // MODIFIED: added
+ } // MODIFIED: added
}
if have, want := buf.String(), streamEncodedIndent; have != want {
t.Error("indented encoding mismatch")
@@ -106,7 +108,7 @@ func TestEncoderSetEscapeHTML(t *testing.T) {
var ct CText
var tagStruct struct {
Valid int `json:"<>&#! "`
- Invalid int `json:"\\"`
+ Invalid int `json:"\\"` //nolint:staticcheck // testing handling of bad tags // MODIFIED: added nolint annotation
}
// This case is particularly interesting, as we force the encoder to
@@ -296,7 +298,8 @@ var blockingTests = []string{
func TestBlocking(t *testing.T) {
for _, enc := range blockingTests {
r, w := net.Pipe()
- go w.Write([]byte(enc))
+ ch := make(chan error) // MODIFIED: added
+ go func() { _, err := w.Write([]byte(enc)); ch <- err }() // MODIFIED: check the error
var val any
// If Decode reads beyond what w.Write writes above,
@@ -305,6 +308,9 @@ func TestBlocking(t *testing.T) {
t.Errorf("decoding %s: %v", enc, err)
}
r.Close()
+ if err := <-ch; err != nil { // MODIFIED: added
+ t.Error(err) // MODIFIED: added
+ } // MODIFIED: added
w.Close()
}
}
@@ -324,6 +330,7 @@ func BenchmarkEncoderEncode(b *testing.B) {
})
}
+/* // MODIFIED: we don't have tokens
type tokenStreamCase struct {
json string
expTokens []any
@@ -333,7 +340,6 @@ type decodeThis struct {
v any
}
-/* // MODIFIED: we don't have tokens
var tokenStreamCases = []tokenStreamCase{
// streaming token cases
{json: `10`, expTokens: []any{float64(10)}},
@@ -446,7 +452,7 @@ func TestHTTPDecoding(t *testing.T) {
const raw = `{ "foo": "bar" }`
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- w.Write([]byte(raw))
+ _, _ = w.Write([]byte(raw)) // MODIFIED: added the _, _ dogsled for the linter
}))
defer ts.Close()
res, err := http.Get(ts.URL)