Skip to content

Commit

Permalink
fix(test): update
Browse files Browse the repository at this point in the history
Signed-off-by: Junjie Gao <[email protected]>
  • Loading branch information
JeyJeyGao committed Dec 9, 2024
1 parent 3099d35 commit 067d4f6
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions internal/io/limitedwriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ package io

import (
"bytes"
"io"
"testing"
)

func TestLimitWriter(t *testing.T) {
limit := int64(10)
longString := "1234567891011"

tests := []struct {
input string
Expand All @@ -46,13 +46,22 @@ func TestLimitWriter(t *testing.T) {
if buf.String() != tt.expected {
t.Errorf("expected buffer %q, got %q", tt.expected, buf.String())
}
}
}

n, err = lw.Write([]byte(longString))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if n == len(longString) {
t.Errorf("should not write more than the limit")
}
func TestLimitWriterFailed(t *testing.T) {
limit := int64(10)
longString := "1234567891011"

var buf bytes.Buffer
lw := LimitWriter(&buf, limit)
_, err := lw.Write([]byte(longString))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
_, err = lw.Write([]byte(longString))
expectedErr := io.ErrShortWrite
if err != expectedErr {
t.Errorf("expected error %v, got %v", expectedErr, err)
}
}

0 comments on commit 067d4f6

Please sign in to comment.