github.com/levb/mattermost-server@v5.3.1+incompatible/model/webrtc_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 TestWebrtcInfoResponseToFromJson(t *testing.T) {
    12  	if testing.Short() {
    13  		t.SkipNow()
    14  	}
    15  
    16  	o := WebrtcInfoResponse{Token: NewId(), GatewayUrl: NewId()}
    17  	json := o.ToJson()
    18  	ro := WebrtcInfoResponseFromJson(strings.NewReader(json))
    19  
    20  	CheckString(t, ro.Token, o.Token)
    21  	CheckString(t, ro.GatewayUrl, o.GatewayUrl)
    22  
    23  	invalidJson := `{"wat"`
    24  	r := WebrtcInfoResponseFromJson(strings.NewReader(invalidJson))
    25  	if r != nil {
    26  		t.Fatalf("Should have failed")
    27  	}
    28  }
    29  
    30  func TestGatewayResponseFromJson(t *testing.T) {
    31  	if testing.Short() {
    32  		t.SkipNow()
    33  	}
    34  
    35  	// Valid Gateway Response
    36  	s1 := `{"janus": "something"}`
    37  	g1 := GatewayResponseFromJson(strings.NewReader(s1))
    38  
    39  	CheckString(t, g1.Status, "something")
    40  
    41  	// Malformed JSON
    42  	s2 := `{"wat"`
    43  	g2 := GatewayResponseFromJson(strings.NewReader(s2))
    44  
    45  	if g2 != nil {
    46  		t.Fatal("expected nil")
    47  	}
    48  }