add cnf/parser/nginx/encoder writer error

This commit is contained in:
Adrien Marquès 2018-11-13 21:11:15 +01:00
parent 685da832df
commit a77923a686
1 changed files with 31 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package nginx
import (
"bytes"
"errors"
"strings"
"testing"
)
@ -166,6 +167,36 @@ func TestDefaultIndent(t *testing.T) {
}
}
var writerError = errors.New("error")
type defectiveWriter struct{}
func (d defectiveWriter) Write(buf []byte) (int, error) {
return 0, writerError
}
func TestWriteError(t *testing.T) {
input := "section {\nkey value;\n}\n"
// create reader/writer
r, w := strings.NewReader(input), &defectiveWriter{}
// parse input
receiver := new(Line)
decoder := NewDecoder(r)
if err := decoder.Decode(receiver); err != nil {
t.Fatalf("unexpected error <%s>", err)
}
// encode back to writer
encoder := NewEncoder(w)
if err := encoder.Encode(receiver); err != writerError {
t.Fatalf("expected error <%s>, got <%s>", writerError, err)
}
}
func escape(raw string) string {
escaped := make([]rune, 0)