go.nanomsg.org/mangos/v3@v3.4.3-0.20240217232803-46464076f1f5/transport/ipc/ipc_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  // +build !nacl,!plan9,!wasm
    16  
    17  package ipc
    18  
    19  import (
    20  	"io/ioutil"
    21  	"os"
    22  	"testing"
    23  
    24  	"go.nanomsg.org/mangos/v3"
    25  	"go.nanomsg.org/mangos/v3/internal/test"
    26  )
    27  
    28  var tran = Transport
    29  
    30  func TestMain(m *testing.M) {
    31  	cwd, err := os.Getwd()
    32  	if err != nil {
    33  		panic("Failed to determine working directory")
    34  	}
    35  
    36  	dir, err := ioutil.TempDir("", "ipctest")
    37  	if err != nil {
    38  		panic("Failed to create directory")
    39  	}
    40  	if err = os.Chdir(dir); err != nil {
    41  		panic("Failed to chdir: " + err.Error())
    42  	}
    43  	v := m.Run()
    44  	if err = os.Chdir(cwd); err != nil {
    45  		panic("Failed to chdir: " + err.Error())
    46  	}
    47  	if err = os.RemoveAll(dir); err != nil {
    48  		panic("Failed to clean up directory: " + err.Error())
    49  	}
    50  	os.Exit(v)
    51  }
    52  
    53  func TestIpcRecvMax(t *testing.T) {
    54  	test.TranVerifyMaxRecvSize(t, tran, nil, nil)
    55  }
    56  
    57  func TestIpcOptions(t *testing.T) {
    58  	test.TranVerifyInvalidOption(t, tran)
    59  	test.TranVerifyIntOption(t, tran, mangos.OptionMaxRecvSize)
    60  }
    61  
    62  func TestIpcScheme(t *testing.T) {
    63  	test.TranVerifyScheme(t, tran)
    64  }
    65  func TestIpcAcceptWithoutListen(t *testing.T) {
    66  	test.TranVerifyAcceptWithoutListen(t, tran)
    67  }
    68  func TestIpcListenAndAccept(t *testing.T) {
    69  	test.TranVerifyListenAndAccept(t, tran, nil, nil)
    70  }
    71  func TestIpcDuplicateListen(t *testing.T) {
    72  	test.TranVerifyDuplicateListen(t, tran, nil)
    73  }
    74  func TestIpcConnectionRefused(t *testing.T) {
    75  	test.TranVerifyConnectionRefused(t, tran, nil)
    76  }
    77  func TestIpcHandshake(t *testing.T) {
    78  	test.TranVerifyHandshakeFail(t, tran, nil, nil)
    79  }
    80  func TestIpcSendRecv(t *testing.T) {
    81  	test.TranVerifySendRecv(t, tran, nil, nil)
    82  }
    83  func TestIpcListenerClosed(t *testing.T) {
    84  	test.TranVerifyListenerClosed(t, tran, nil)
    85  }
    86  func TestIpcMessageSize(t *testing.T) {
    87  	test.TranVerifyMessageSizes(t, tran, nil, nil)
    88  }
    89  func TestIpcMessageHeader(t *testing.T) {
    90  	test.TranVerifyMessageHeader(t, tran, nil, nil)
    91  }
    92  func TestIpcVerifyPipeAddresses(t *testing.T) {
    93  	test.TranVerifyPipeAddresses(t, tran, nil, nil)
    94  }
    95  func TestIpcVerifyPipeOptions(t *testing.T) {
    96  	test.TranVerifyPipeOptions2(t, tran, nil, nil)
    97  }