File: api_test.go

package info (click to toggle)
golang-github-akamai-akamaiopen-edgegrid-golang 1.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,408 kB
  • sloc: sh: 532; makefile: 3
file content (38 lines) | stat: -rw-r--r-- 650 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package client

import (
	"testing"

	"github.com/akamai/AkamaiOPEN-edgegrid-golang/jsonhooks-v1"
	"github.com/stretchr/testify/assert"
)

type Test struct {
	Resource
	Foo string `json:"foo"`
}

func (test *Test) PreMarshalJSON() error {
	test.Foo = "bat"

	return nil
}

func TestResourceUnmarshal(t *testing.T) {
	body := []byte(`{"foo":"bar"}`)

	test := &Test{}
	err := jsonhooks.Unmarshal(body, test)

	assert.NoError(t, err)
	assert.True(t, <-test.Complete)
}

func TestResourceMarshal(t *testing.T) {
	test := &Test{Foo: "bar"}

	body, err := jsonhooks.Marshal(test)

	assert.NoError(t, err)
	assert.Equal(t, []byte(`{"foo":"bat"}`), body)
}