nanomsg.org/go/mangos/v2@v2.0.9-0.20200203084354-8a092611e461/transport/wss/wss_test.go (about)

     1  // Copyright 2018 The Mangos Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use file except in compliance with the License.
     5  // You may obtain a copy of the license at
     6  //
     7  //    http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package wss
    16  
    17  import (
    18  	"crypto/tls"
    19  	"testing"
    20  
    21  	"nanomsg.org/go/mangos/v2"
    22  	. "nanomsg.org/go/mangos/v2/internal/test"
    23  )
    24  
    25  var tran = Transport
    26  
    27  var lOpts map[string]interface{}
    28  var dOpts map[string]interface{}
    29  
    30  func init() {
    31  	dOpts = make(map[string]interface{})
    32  	lOpts = make(map[string]interface{})
    33  	var t *testing.T
    34  	dOpts[mangos.OptionTLSConfig] = GetTLSConfig(t, false)
    35  	lOpts[mangos.OptionTLSConfig] = GetTLSConfig(t, true)
    36  }
    37  
    38  func TestWssOptions(t *testing.T) {
    39  	TranVerifyInvalidOption(t, tran)
    40  	TranVerifyIntOption(t, tran, mangos.OptionMaxRecvSize)
    41  	TranVerifyNoDelayOption(t, tran)
    42  	TranVerifyTLSConfigOption(t, tran)
    43  }
    44  
    45  func TestWssScheme(t *testing.T) {
    46  	TranVerifyScheme(t, tran)
    47  }
    48  func TestWssRecvMax(t *testing.T) {
    49  	TranVerifyMaxRecvSize(t, tran, dOpts, lOpts)
    50  }
    51  func TestWssAcceptWithoutListen(t *testing.T) {
    52  	TranVerifyAcceptWithoutListen(t, tran)
    53  }
    54  func TestWssListenAndAccept(t *testing.T) {
    55  	TranVerifyListenAndAccept(t, tran, dOpts, lOpts)
    56  }
    57  func TestWssDuplicateListen(t *testing.T) {
    58  	TranVerifyDuplicateListen(t, tran, lOpts)
    59  }
    60  func TestWssConnectionRefused(t *testing.T) {
    61  	TranVerifyConnectionRefused(t, tran, dOpts)
    62  }
    63  func TestWssSendRecv(t *testing.T) {
    64  	TranVerifySendRecv(t, tran, dOpts, lOpts)
    65  }
    66  func TestWssListenNoCert(t *testing.T) {
    67  	sock := GetMockSocket()
    68  	defer MustClose(t, sock)
    69  
    70  	addr := AddrTestWSS()
    71  	MustBeError(t, sock.ListenOptions(addr, nil), mangos.ErrTLSNoConfig)
    72  
    73  	cfg := &tls.Config{}
    74  	opts := make(map[string]interface{})
    75  	opts[mangos.OptionTLSConfig] = cfg
    76  	MustBeError(t, sock.ListenOptions(addr, opts), mangos.ErrTLSNoCert)
    77  }
    78  
    79  func TestWssDialNoCert(t *testing.T) {
    80  	TranVerifyDialNoCert(t, tran)
    81  }
    82  
    83  func TestWssDialInsecure(t *testing.T) {
    84  	TranVerifyDialInsecure(t, tran)
    85  }
    86  
    87  func TestWssMessageSize(t *testing.T) {
    88  	TranVerifyMessageSizes(t, tran, dOpts, lOpts)
    89  }
    90  
    91  func TestWssMessageHeader(t *testing.T) {
    92  	TranVerifyMessageHeader(t, tran, dOpts, lOpts)
    93  }