lab.nexedi.com/kirr/go123@v0.0.0-20240207185015-8299741fa871/xnet/pipenet/pipenet_test.go (about)

     1  // Copyright (C) 2017-2018  Nexedi SA and Contributors.
     2  //                          Kirill Smelkov <kirr@nexedi.com>
     3  //
     4  // This program is free software: you can Use, Study, Modify and Redistribute
     5  // it under the terms of the GNU General Public License version 3, or (at your
     6  // option) any later version, as published by the Free Software Foundation.
     7  //
     8  // You can also Link and Combine this program with other software covered by
     9  // the terms of any of the Free Software licenses or any of the Open Source
    10  // Initiative approved licenses and Convey the resulting work. Corresponding
    11  // source of such a combination shall include the source code for all other
    12  // software used.
    13  //
    14  // This program is distributed WITHOUT ANY WARRANTY; without even the implied
    15  // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    16  //
    17  // See COPYING file for full licensing terms.
    18  // See https://www.nexedi.com/licensing for rationale and options.
    19  
    20  package pipenet
    21  
    22  import (
    23  	"testing"
    24  
    25  	"lab.nexedi.com/kirr/go123/internal/xtesting"
    26  	"lab.nexedi.com/kirr/go123/xnet/internal/virtnettest"
    27  )
    28  
    29  func TestPipeNet(t *testing.T) {
    30  	virtnettest.TestBasic(t, New("t").vnet)
    31  }
    32  
    33  // pipenet has a bit different API than virtnet: Host has no error and returns
    34  // same instance if called twice, not dup, etc. Test it.
    35  func TestPipeNet2(t *testing.T) {
    36  	assert := xtesting.Assert(t)
    37  	pnet := New("t")
    38  
    39  	hα := pnet.Host("α")
    40  	hβ := pnet.Host("β")
    41  
    42  	assert.Eq(hα.Network(), "pipet")
    43  	assert.Eq(hβ.Network(), "pipet")
    44  	assert.Eq(hα.Name(), "α")
    45  	assert.Eq(hβ.Name(), "β")
    46  
    47  	hα2 := pnet.Host("α")
    48  	hβ2 := pnet.Host("β")
    49  
    50  	if !(hα == hα2 && hβ == hβ2) {
    51  		t.Fatalf("Host(x) is not idempotent")
    52  	}
    53  
    54  	if AsVirtNet(pnet) != pnet.vnet {
    55  		t.Fatal("AsVirtNet broken")
    56  	}
    57  }