File: model_property_list_test.go

package info (click to toggle)
golang-github-emicklei-go-restful-swagger12 1.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 196 kB
  • sloc: makefile: 2
file content (47 lines) | stat: -rw-r--r-- 993 bytes parent folder | download | duplicates (2)
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
39
40
41
42
43
44
45
46
47
package swagger

import (
	"encoding/json"
	"testing"
)

func TestModelPropertyList(t *testing.T) {
	l := ModelPropertyList{}
	p := ModelProperty{Description: "d"}
	l.Put("p", p)
	q, ok := l.At("p")
	if !ok {
		t.Error("expected p")
	}
	if got, want := q.Description, "d"; got != want {
		t.Errorf("got %v want %v", got, want)
	}
}

func TestModelPropertyList_Marshal(t *testing.T) {
	l := ModelPropertyList{}
	p := ModelProperty{Description: "d"}
	l.Put("p", p)
	data, err := json.Marshal(l)
	if err != nil {
		t.Error(err)
	}
	if got, want := string(data), `{"p":{"description":"d"}}`; got != want {
		t.Errorf("got %v want %v", got, want)
	}
}

func TestModelPropertyList_Unmarshal(t *testing.T) {
	data := `{"p":{"description":"d"}}`
	l := ModelPropertyList{}
	if err := json.Unmarshal([]byte(data), &l); err != nil {
		t.Error(err)
	}
	m, ok := l.At("p")
	if !ok {
		t.Error("expected p")
	}
	if got, want := m.Description, "d"; got != want {
		t.Errorf("got %v want %v", got, want)
	}
}