github.com/mattermosttest/mattermost-server/v5@v5.0.0-20200917143240-9dfa12e121f9/model/security_bulletin_test.go (about)

     1  // Copyright (c) 2015-present 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  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestSecurityBulletinToFromJson(t *testing.T) {
    14  	b := SecurityBulletin{
    15  		Id:               NewId(),
    16  		AppliesToVersion: NewId(),
    17  	}
    18  
    19  	j := b.ToJson()
    20  	b1 := SecurityBulletinFromJson(strings.NewReader(j))
    21  
    22  	require.Equal(t, b, *b1)
    23  
    24  	// Malformed JSON
    25  	s2 := `{"wat"`
    26  	b2 := SecurityBulletinFromJson(strings.NewReader(s2))
    27  	require.Nil(t, b2)
    28  }
    29  
    30  func TestSecurityBulletinsToFromJson(t *testing.T) {
    31  	b := SecurityBulletins{
    32  		{
    33  			Id:               NewId(),
    34  			AppliesToVersion: NewId(),
    35  		},
    36  		{
    37  			Id:               NewId(),
    38  			AppliesToVersion: NewId(),
    39  		},
    40  	}
    41  
    42  	j := b.ToJson()
    43  
    44  	b1 := SecurityBulletinsFromJson(strings.NewReader(j))
    45  
    46  	require.Len(t, b1, 2)
    47  
    48  	// Malformed JSON
    49  	s2 := `{"wat"`
    50  	b2 := SecurityBulletinsFromJson(strings.NewReader(s2))
    51  
    52  	require.Empty(t, b2)
    53  }