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/webrtc_test.go | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'model/webrtc_test.go') diff --git a/model/webrtc_test.go b/model/webrtc_test.go index 2418bd53a..7ec6605f8 100644 --- a/model/webrtc_test.go +++ b/model/webrtc_test.go @@ -8,12 +8,33 @@ import ( "testing" ) -func TestWebrtcJson(t *testing.T) { +func TestWebrtcInfoResponseToFromJson(t *testing.T) { o := WebrtcInfoResponse{Token: NewId(), GatewayUrl: NewId()} json := o.ToJson() ro := WebrtcInfoResponseFromJson(strings.NewReader(json)) - if o.Token != ro.Token { - t.Fatal("Tokens do not match") + CheckString(t, ro.Token, o.Token) + CheckString(t, ro.GatewayUrl, o.GatewayUrl) + + invalidJson := `{"wat"` + r := WebrtcInfoResponseFromJson(strings.NewReader(invalidJson)) + if r != nil { + t.Fatalf("Should have failed") + } +} + +func TestGatewayResponseFromJson(t *testing.T) { + // Valid Gateway Response + s1 := `{"janus": "something"}` + g1 := GatewayResponseFromJson(strings.NewReader(s1)) + + CheckString(t, g1.Status, "something") + + // Malformed JSON + s2 := `{"wat"` + g2 := GatewayResponseFromJson(strings.NewReader(s2)) + + if g2 != nil { + t.Fatal("expected nil") } } -- cgit v1.2.3-1-g7c22