Skip to content

Commit

Permalink
test: add unit tests for event content
Browse files Browse the repository at this point in the history
unmarshaller
  • Loading branch information
wischoepke committed Jan 23, 2025
1 parent 27b9854 commit 02ba3c2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
File renamed without changes.
60 changes: 60 additions & 0 deletions server/src/api/event_content_unmarshaller_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package api

import (
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"reflect"
"testing"
)

type TestStruct struct {
ID string `json:"id"`
}

func TestCorrectString(t *testing.T) {
given := "TEST_STRING"
actual, err := unmarshal[string](given)

assert.NoError(t, err)
assert.Equal(t, given, *actual)
}

func TestCorrectStringSlice(t *testing.T) {
s := "TEST_STRING"
given := []*string{&s}
actual, err := unmarshalSlice[string](given)

assert.NoError(t, err)
assert.Equal(t, given, actual)
}

func TestCorrectEmptySlice(t *testing.T) {
var given []*string
actual, err := unmarshalSlice[string](given)

assert.NoError(t, err)
assert.Equal(t, given, actual)
}

func TestCorrectUUID(t *testing.T) {
given, _ := uuid.NewRandom()
actual, err := unmarshal[uuid.UUID](given)

assert.NoError(t, err)
assert.Equal(t, given, *actual)
}

func TestCorrectInterfaceTypeStruct(t *testing.T) {
given := "TEST_ID"
actual, err := unmarshal[TestStruct](reflect.ValueOf(TestStruct{ID: given}).Interface())

assert.NoError(t, err)
assert.Equal(t, given, actual.ID)
}

func TestNil(t *testing.T) {
actual, err := unmarshal[TestStruct](nil)

assert.NoError(t, err)
assert.Nil(t, actual)
}

0 comments on commit 02ba3c2

Please sign in to comment.