go.nanomsg.org/mangos/v3@v3.4.3-0.20240217232803-46464076f1f5/protocol/push/push_test.go (about)

     1  // Copyright 2019 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 push
    16  
    17  import (
    18  	"testing"
    19  
    20  	"go.nanomsg.org/mangos/v3"
    21  	. "go.nanomsg.org/mangos/v3/internal/test"
    22  )
    23  
    24  func TestPushIdentity(t *testing.T) {
    25  	s := GetSocket(t, NewSocket)
    26  	id := s.Info()
    27  	MustBeTrue(t, id.Self == mangos.ProtoPush)
    28  	MustBeTrue(t, id.SelfName == "push")
    29  	MustBeTrue(t, id.Peer == mangos.ProtoPull)
    30  	MustBeTrue(t, id.PeerName == "pull")
    31  	MustSucceed(t, s.Close())
    32  }
    33  
    34  func TestPushCooked(t *testing.T) {
    35  	VerifyCooked(t, NewSocket)
    36  }
    37  
    38  func TestPushNoContext(t *testing.T) {
    39  	s := GetSocket(t, NewSocket)
    40  	_, e := s.OpenContext()
    41  	MustBeError(t, e, mangos.ErrProtoOp)
    42  	MustSucceed(t, s.Close())
    43  }
    44  
    45  func TestPushOptions(t *testing.T) {
    46  	VerifyInvalidOption(t, NewSocket)
    47  }
    48  
    49  func TestPushNoRecv(t *testing.T) {
    50  	CannotRecv(t, NewSocket)
    51  }
    52  
    53  func TestPushFastFailNoPeer(t *testing.T) {
    54  	VerifyOptionBool(t, NewSocket, mangos.OptionFailNoPeers)
    55  
    56  	s := GetSocket(t, NewSocket)
    57  	MustSucceed(t, s.SetOption(mangos.OptionFailNoPeers, true))
    58  	MustBeError(t, s.Send([]byte("junk")), mangos.ErrNoPeers)
    59  }