add cnf/parser/nginx/encoder writer error
This commit is contained in:
parent
685da832df
commit
a77923a686
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue