nanomsg.org/go/mangos/v2@v2.0.9-0.20200203084354-8a092611e461/protocol/star/star_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 star 16 17 import ( 18 "nanomsg.org/go/mangos/v2/protocol/xstar" 19 "testing" 20 21 "nanomsg.org/go/mangos/v2" 22 . "nanomsg.org/go/mangos/v2/internal/test" 23 . "nanomsg.org/go/mangos/v2/protocol" 24 _ "nanomsg.org/go/mangos/v2/transport/inproc" 25 ) 26 27 func TestStarIdentity(t *testing.T) { 28 id := GetSocket(t, NewSocket).Info() 29 MustBeTrue(t, id.Self == ProtoStar) 30 MustBeTrue(t, id.Peer == ProtoStar) 31 MustBeTrue(t, id.SelfName == "star") 32 MustBeTrue(t, id.PeerName == "star") 33 } 34 35 func TestStarCooked(t *testing.T) { 36 VerifyCooked(t, NewSocket) 37 } 38 39 func TestStarClosed(t *testing.T) { 40 VerifyClosedRecv(t, NewSocket) 41 VerifyClosedSend(t, NewSocket) 42 VerifyClosedClose(t, NewSocket) 43 VerifyClosedDial(t, NewSocket) 44 VerifyClosedListen(t, NewSocket) 45 VerifyClosedAddPipe(t, NewSocket) 46 } 47 48 func TestStarDiscardHeader(t *testing.T) { 49 s1 := GetSocket(t, NewSocket) 50 s2 := GetSocket(t, NewSocket) 51 ConnectPair(t, s1, s2) 52 53 m := mangos.NewMessage(0) 54 m.Header = append(m.Header, 0, 1, 2, 3) 55 m.Body = append(m.Body, 'a', 'b', 'c') 56 57 MustSendMsg(t, s1, m) 58 m = MustRecvMsg(t, s2) 59 MustBeTrue(t, len(m.Header) == 0) 60 MustBeTrue(t, string(m.Body) == "abc") 61 } 62 63 func TestStarTTL(t *testing.T) { 64 SetTTLZero(t, NewSocket) 65 SetTTLNegative(t, NewSocket) 66 SetTTLTooBig(t, NewSocket) 67 SetTTLNotInt(t, NewSocket) 68 SetTTL(t, NewSocket) 69 TTLDropTest(t, NewSocket, NewSocket, xstar.NewSocket, xstar.NewSocket) 70 }