Add testing

This commit is contained in:
Melody Becker 2025-04-14 16:59:59 +02:00
parent 3233f8c27f
commit 06e6d457da
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI
14 changed files with 273 additions and 5 deletions

View file

@ -24,14 +24,17 @@ type Note struct {
var _ shared.Clonable = &Note{}
var _ shared.Sanitisable = &Note{}
// No test, does nothing currently
func (note *Note) Sanitize() {
}
// No test, no data processing, only copy
func (note *Note) Clone() shared.Clonable {
tmp := *note
return &tmp
}
// No test, no data processing, only copy
func (n *Note) FromModel(m *models.Note) {
n.ID = m.ID
n.CreatedAt = m.CreatedAt

View file

@ -44,11 +44,13 @@ type User struct {
var _ shared.Sanitisable = &User{}
var _ shared.Clonable = &User{}
// No test due to no fancy processing, just setting values to constants
func (u *User) Sanitize() {
u.Verified = nil
u.FinishedRegistration = nil
}
// No test, no data processing, only copy
func (u *User) Clone() shared.Clonable {
user := *u
if u.IconId != nil {
@ -83,6 +85,7 @@ func (u *User) Clone() shared.Clonable {
return &user
}
// No test, no data processing, only copy
func (u *User) FromModel(m *models.User) {
u.ID = m.ID
u.CreatedAt = m.CreatedAt

57
web/shared/client_test.go Normal file
View file

@ -0,0 +1,57 @@
package webshared
import (
"io"
"net/http"
"reflect"
"testing"
)
const testBody = `{
"key": "value",
"more-key": 21
}`
var testBodyHash = []byte("22a5173da554010ea25f7d2ae34032a434c3a883a55d65f34c3413fdc555bed3")
func TestSignRequest(t *testing.T) {
// TODO: Implement tests
}
func Test_applyBodyHash_WithBody(t *testing.T) {
var headers = make(http.Header, 0)
digest := "SHA-256=" + string(testBodyHash)
applyBodyHash(headers, []byte(testBody))
headerDigest := headers.Get("Digest")
if headerDigest != digest {
t.Fatalf("digests didn't match: header \"%v\" != precalc \"%v\"", headerDigest, digest)
}
}
func TestNewRequest(t *testing.T) {
type args struct {
method string
url string
body io.Reader
}
tests := []struct {
name string
args args
want *http.Request
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := NewRequest(tt.args.method, tt.args.url, tt.args.body)
if (err != nil) != tt.wantErr {
t.Errorf("NewRequest() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("NewRequest() = %v, want %v", got, tt.want)
}
})
}
}