File: model_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 (48 lines) | stat: -rw-r--r-- 944 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
48
package swagger

import (
	"encoding/json"
	"testing"
)

func TestModelList(t *testing.T) {
	m := Model{}
	m.Id = "m"
	l := ModelList{}
	l.Put("m", m)
	k, ok := l.At("m")
	if !ok {
		t.Error("want model back")
	}
	if got, want := k.Id, "m"; got != want {
		t.Errorf("got %v want %v", got, want)
	}
}

func TestModelList_Marshal(t *testing.T) {
	l := ModelList{}
	m := Model{Id: "myid"}
	l.Put("myid", m)
	data, err := json.Marshal(l)
	if err != nil {
		t.Error(err)
	}
	if got, want := string(data), `{"myid":{"id":"myid","properties":{}}}`; got != want {
		t.Errorf("got %v want %v", got, want)
	}
}

func TestModelList_Unmarshal(t *testing.T) {
	data := `{"myid":{"id":"myid","properties":{}}}`
	l := ModelList{}
	if err := json.Unmarshal([]byte(data), &l); err != nil {
		t.Error(err)
	}
	m, ok := l.At("myid")
	if !ok {
		t.Error("expected myid")
	}
	if got, want := m.Id, "myid"; got != want {
		t.Errorf("got %v want %v", got, want)
	}
}