All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
40 lines
818 B
Go
40 lines
818 B
Go
package common
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gitea.maximumdirect.net/ejr/feedkit/event"
|
|
)
|
|
|
|
func TestDecodeJSONPayloadAcceptsTypedPayload(t *testing.T) {
|
|
type rawPayload struct {
|
|
Value string `json:"value"`
|
|
}
|
|
|
|
got, err := DecodeJSONPayload[rawPayload](event.Event{
|
|
Payload: rawPayload{Value: "ok"},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("DecodeJSONPayload() error = %v", err)
|
|
}
|
|
if got.Value != "ok" {
|
|
t.Fatalf("Value = %q, want ok", got.Value)
|
|
}
|
|
}
|
|
|
|
func TestDecodeJSONPayloadAcceptsTypedPointerPayload(t *testing.T) {
|
|
type rawPayload struct {
|
|
Value string `json:"value"`
|
|
}
|
|
|
|
got, err := DecodeJSONPayload[rawPayload](event.Event{
|
|
Payload: &rawPayload{Value: "ok"},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("DecodeJSONPayload() error = %v", err)
|
|
}
|
|
if got.Value != "ok" {
|
|
t.Fatalf("Value = %q, want ok", got.Value)
|
|
}
|
|
}
|