From 55bbf15fc7a83d3cda1fe5bc037823cbbc4fc023 Mon Sep 17 00:00:00 2001 From: George Goldberg Date: Thu, 20 Apr 2017 14:58:54 +0100 Subject: PLT-6112: Add some more unit tests to the model package (#6142) * Unit Tests for model/push_response.go * Unit tests for security_bulletin.go * Unit tests for webrtc.go * Unit tests for model/password_recovery.go * Add missing headers. * Unit tests for model/license.go * Tidy up existing tests. * Simplify JSON to/from tests. * Fix gofmt --- model/security_bulletin_test.go | 55 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 model/security_bulletin_test.go (limited to 'model/security_bulletin_test.go') diff --git a/model/security_bulletin_test.go b/model/security_bulletin_test.go new file mode 100644 index 000000000..a6e55fe1c --- /dev/null +++ b/model/security_bulletin_test.go @@ -0,0 +1,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) +} -- cgit v1.2.3-1-g7c22