github.com/keys-pub/mattermost-server@v4.10.10+incompatible/model/security_bulletin_test.go (about)

     1  // Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package model
     5  
     6  import (
     7  	"strings"
     8  	"testing"
     9  )
    10  
    11  func TestSecurityBulletinToFromJson(t *testing.T) {
    12  	b := SecurityBulletin{
    13  		Id:               NewId(),
    14  		AppliesToVersion: NewId(),
    15  	}
    16  
    17  	j := b.ToJson()
    18  	b1 := SecurityBulletinFromJson(strings.NewReader(j))
    19  
    20  	CheckString(t, b1.AppliesToVersion, b.AppliesToVersion)
    21  	CheckString(t, b1.Id, b.Id)
    22  
    23  	// Malformed JSON
    24  	s2 := `{"wat"`
    25  	b2 := SecurityBulletinFromJson(strings.NewReader(s2))
    26  
    27  	if b2 != nil {
    28  		t.Fatal("expected nil")
    29  	}
    30  }
    31  
    32  func TestSecurityBulletinsToFromJson(t *testing.T) {
    33  	b := SecurityBulletins{
    34  		{
    35  			Id:               NewId(),
    36  			AppliesToVersion: NewId(),
    37  		},
    38  		{
    39  			Id:               NewId(),
    40  			AppliesToVersion: NewId(),
    41  		},
    42  	}
    43  
    44  	j := b.ToJson()
    45  
    46  	b1 := SecurityBulletinsFromJson(strings.NewReader(j))
    47  
    48  	CheckInt(t, len(b1), 2)
    49  
    50  	// Malformed JSON
    51  	s2 := `{"wat"`
    52  	b2 := SecurityBulletinsFromJson(strings.NewReader(s2))
    53  
    54  	CheckInt(t, len(b2), 0)
    55  }