add some backend unit tests

This commit is contained in:
lukas 2021-09-20 19:06:50 +02:00
parent 70413ac887
commit b10fbd6142
4 changed files with 35 additions and 2 deletions

View File

@ -62,7 +62,7 @@ Backend_Tests:
stage: test
script:
- cd apiGo
- go get -u github.com/jstemmer/go-junit-report
- go install github.com/jstemmer/go-junit-report@v0.9.1
- go test -v ./... 2>&1 | go-junit-report -set-exit-code > report.xml
needs: []
artifacts:

View File

@ -56,5 +56,5 @@ func (r *apicontext) Error(msg string) {
}
func (r *apicontext) Errorf(msg string, args ...interface{}) {
r.Error(fmt.Sprintf(msg, args))
r.Error(fmt.Sprintf(msg, &args))
}

View File

@ -0,0 +1,11 @@
package api
import "testing"
func TestHashlength(t *testing.T) {
h := HashPassword("test")
if len(*h) != 64 {
t.Errorf("Invalid hash length: %d", len(*h))
}
}

View File

@ -0,0 +1,22 @@
package api
import "testing"
func TestJsonify(t *testing.T) {
var obj = struct {
ID uint32
Str string
Boo bool
}{
ID: 42,
Str: "teststr",
Boo: true,
}
res := Jsonify(obj)
exp := `{"ID":42,"Str":"teststr","Boo":true}`
if string(res) != exp {
t.Errorf("Invalid json response: %s !== %s", string(res), exp)
}
}