summaryrefslogtreecommitdiffstats
path: root/model/security_bulletin_test.go
blob: a6e55fe1c447194721fc7c9334bc7943499aa8c1 (plain)
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
49
50
51
52
53
54
55
// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

package model

import (
	"strings"
	"testing"
)

func TestSecurityBulletinToFromJson(t *testing.T) {
	b := SecurityBulletin{
		Id:               NewId(),
		AppliesToVersion: NewId(),
	}

	j := b.ToJson()
	b1 := SecurityBulletinFromJson(strings.NewReader(j))

	CheckString(t, b1.AppliesToVersion, b.AppliesToVersion)
	CheckString(t, b1.Id, b.Id)

	// Malformed JSON
	s2 := `{"wat"`
	b2 := SecurityBulletinFromJson(strings.NewReader(s2))

	if b2 != nil {
		t.Fatal("expected nil")
	}
}

func TestSecurityBulletinsToFromJson(t *testing.T) {
	b := SecurityBulletins{
		{
			Id:               NewId(),
			AppliesToVersion: NewId(),
		},
		{
			Id:               NewId(),
			AppliesToVersion: NewId(),
		},
	}

	j := b.ToJson()

	b1 := SecurityBulletinsFromJson(strings.NewReader(j))

	CheckInt(t, len(b1), 2)

	// Malformed JSON
	s2 := `{"wat"`
	b2 := SecurityBulletinsFromJson(strings.NewReader(s2))

	CheckInt(t, len(b2), 0)
}