mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 18:15:42 +01:00
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>
This commit is contained in:
parent
b852ae4ec1
commit
87dd8307a3
2 changed files with 33 additions and 0 deletions
3
.github/workflows/go.yml
vendored
3
.github/workflows/go.yml
vendored
|
|
@ -29,3 +29,6 @@ jobs:
|
||||||
|
|
||||||
- name: golint
|
- name: golint
|
||||||
uses: Jerome1337/golint-action@v1.0.2
|
uses: Jerome1337/golint-action@v1.0.2
|
||||||
|
|
||||||
|
- name: Tests
|
||||||
|
run: go test -v ./..
|
||||||
|
|
|
||||||
30
util/file_test.go
Normal file
30
util/file_test.go
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue