diff options
author | George Goldberg <george@gberg.me> | 2017-04-20 14:58:54 +0100 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2017-04-20 09:58:54 -0400 |
commit | 55bbf15fc7a83d3cda1fe5bc037823cbbc4fc023 (patch) | |
tree | 312f6a9c42c8f153168df8f960b613666777f64a /model/security_bulletin_test.go | |
parent | 8723f61f4540c74d5c755d7f9532f8fe199ccb6f (diff) | |
download | chat-55bbf15fc7a83d3cda1fe5bc037823cbbc4fc023.tar.gz chat-55bbf15fc7a83d3cda1fe5bc037823cbbc4fc023.tar.bz2 chat-55bbf15fc7a83d3cda1fe5bc037823cbbc4fc023.zip |
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
Diffstat (limited to 'model/security_bulletin_test.go')
-rw-r--r-- | model/security_bulletin_test.go | 55 |
1 files changed, 55 insertions, 0 deletions
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) +} |