github.com/vvnotw/moby@v1.13.1/pkg/plugins/discovery_unix_test.go (about)

     1  // +build !windows
     2  
     3  package plugins
     4  
     5  import (
     6  	"fmt"
     7  	"net"
     8  	"os"
     9  	"path/filepath"
    10  	"reflect"
    11  	"testing"
    12  )
    13  
    14  func TestLocalSocket(t *testing.T) {
    15  	// TODO Windows: Enable a similar version for Windows named pipes
    16  	tmpdir, unregister := Setup(t)
    17  	defer unregister()
    18  
    19  	cases := []string{
    20  		filepath.Join(tmpdir, "echo.sock"),
    21  		filepath.Join(tmpdir, "echo", "echo.sock"),
    22  	}
    23  
    24  	for _, c := range cases {
    25  		if err := os.MkdirAll(filepath.Dir(c), 0755); err != nil {
    26  			t.Fatal(err)
    27  		}
    28  
    29  		l, err := net.Listen("unix", c)
    30  		if err != nil {
    31  			t.Fatal(err)
    32  		}
    33  
    34  		r := newLocalRegistry()
    35  		p, err := r.Plugin("echo")
    36  		if err != nil {
    37  			t.Fatal(err)
    38  		}
    39  
    40  		pp, err := r.Plugin("echo")
    41  		if err != nil {
    42  			t.Fatal(err)
    43  		}
    44  		if !reflect.DeepEqual(p, pp) {
    45  			t.Fatalf("Expected %v, was %v\n", p, pp)
    46  		}
    47  
    48  		if p.name != "echo" {
    49  			t.Fatalf("Expected plugin `echo`, got %s\n", p.name)
    50  		}
    51  
    52  		addr := fmt.Sprintf("unix://%s", c)
    53  		if p.Addr != addr {
    54  			t.Fatalf("Expected plugin addr `%s`, got %s\n", addr, p.Addr)
    55  		}
    56  		if p.TLSConfig.InsecureSkipVerify != true {
    57  			t.Fatalf("Expected TLS verification to be skipped")
    58  		}
    59  		l.Close()
    60  	}
    61  }