1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 18:15:42 +01:00
gocsaf/util/file_test.go
Bernhard E. Reiter 87dd8307a3
Add first simple unit test with workflow (#81)
* Adding first simple unit test

* Add test run to workflow

Co-authored-by: Sascha L. Teichmann <sascha.teichmann@intevation.de>
2022-03-08 16:25:17 +01:00

30 lines
551 B
Go

package util
import (
"bytes"
"testing"
)
func TestNWriter(t *testing.T) {
msg := []byte("Gruß!\n")
first, second := msg[:len(msg)/2], msg[len(msg)/2:]
var buf bytes.Buffer
nw := NWriter{Writer: &buf, N: 0}
_, err1 := nw.Write(first)
_, err2 := nw.Write(second)
if err1 != nil || err2 != nil {
t.Error("Calling NWriter failed")
}
if n := int64(len(msg)); nw.N != n {
t.Errorf("Expected %d bytes, but counted %d", n, nw.N)
}
if out := buf.Bytes(); !bytes.Equal(msg, out) {
t.Errorf("Expected %q, but got %q", msg, out)
}
}