github.com/aporeto-inc/trireme-lib@v10.358.0+incompatible/monitor/internal/docker/monitor_linux_test.go (about)

     1  // +build linux,!rhel6
     2  
     3  package dockermonitor
     4  
     5  import (
     6  	"errors"
     7  	"os"
     8  	"syscall"
     9  	"testing"
    10  
    11  	. "github.com/smartystreets/goconvey/convey"
    12  
    13  	"go.aporeto.io/enforcerd/trireme-lib/monitor/constants"
    14  )
    15  
    16  func TestInitDockerClient(t *testing.T) {
    17  
    18  	Convey("When I try to initialize a new docker client as unix", t, func() {
    19  		dc, err := initDockerClient(constants.DefaultDockerSocketType, constants.DefaultDockerSocket)
    20  
    21  		Convey("Then docker client should not be nil", func() {
    22  			So(dc, ShouldNotBeNil)
    23  			So(err, ShouldBeNil)
    24  		})
    25  	})
    26  
    27  	Convey("When I try to initialize a new docker client as tcp", t, func() {
    28  		dc, err := initDockerClient("tcp", constants.DefaultDockerSocket)
    29  
    30  		Convey("Then docker client should not be nil", func() {
    31  			So(dc, ShouldNotBeNil)
    32  			So(err, ShouldBeNil)
    33  		})
    34  	})
    35  
    36  	Convey("When I try to initialize a new docker client with some random type", t, func() {
    37  		dc, err := initDockerClient("wrongtype", constants.DefaultDockerSocket)
    38  
    39  		Convey("Then docker client should be nil and I should get error", func() {
    40  			So(dc, ShouldBeNil)
    41  			So(err, ShouldResemble, errors.New("bad socket type: wrongtype"))
    42  		})
    43  	})
    44  
    45  	Convey("When I try to initialize a new docker client with some random path", t, func() {
    46  		dc, err := initDockerClient(constants.DefaultDockerSocketType, "/var/random.sock")
    47  
    48  		Convey("Then docker client should be nil and I should get error", func() {
    49  			So(dc, ShouldBeNil)
    50  			So(err, ShouldResemble, &os.PathError{Op: "stat", Path: "/var/random.sock", Err: syscall.Errno(2)})
    51  		})
    52  	})
    53  }