add some backend unit tests
This commit is contained in:
parent
70413ac887
commit
b10fbd6142
@ -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:
|
||||
|
@ -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))
|
||||
}
|
||||
|
11
apiGo/api/api/Hash_test.go
Normal file
11
apiGo/api/api/Hash_test.go
Normal 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))
|
||||
}
|
||||
}
|
22
apiGo/api/api/Helpers_test.go
Normal file
22
apiGo/api/api/Helpers_test.go
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user