github.com/robertojrojas/docker@v1.9.1/pkg/integration/checker/checker_test.go (about)

     1  package checker
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	"github.com/go-check/check"
     8  )
     9  
    10  func Test(t *testing.T) {
    11  	check.TestingT(t)
    12  }
    13  
    14  func init() {
    15  	check.Suite(&CheckersS{})
    16  }
    17  
    18  type CheckersS struct{}
    19  
    20  var _ = check.Suite(&CheckersS{})
    21  
    22  func testInfo(c *check.C, checker check.Checker, name string, paramNames []string) {
    23  	info := checker.Info()
    24  	if info.Name != name {
    25  		c.Fatalf("Got name %s, expected %s", info.Name, name)
    26  	}
    27  	if !reflect.DeepEqual(info.Params, paramNames) {
    28  		c.Fatalf("Got param names %#v, expected %#v", info.Params, paramNames)
    29  	}
    30  }
    31  
    32  func testCheck(c *check.C, checker check.Checker, expectedResult bool, expectedError string, params ...interface{}) ([]interface{}, []string) {
    33  	info := checker.Info()
    34  	if len(params) != len(info.Params) {
    35  		c.Fatalf("unexpected param count in test; expected %d got %d", len(info.Params), len(params))
    36  	}
    37  	names := append([]string{}, info.Params...)
    38  	result, error := checker.Check(params, names)
    39  	if result != expectedResult || error != expectedError {
    40  		c.Fatalf("%s.Check(%#v) returned (%#v, %#v) rather than (%#v, %#v)",
    41  			info.Name, params, result, error, expectedResult, expectedError)
    42  	}
    43  	return params, names
    44  }
    45  
    46  func (s *CheckersS) TestContains(c *check.C) {
    47  	testInfo(c, Contains, "Contains", []string{"value", "substring"})
    48  
    49  	testCheck(c, Contains, true, "", "abcd", "bc")
    50  	testCheck(c, Contains, false, "", "abcd", "efg")
    51  	testCheck(c, Contains, false, "", "", "bc")
    52  	testCheck(c, Contains, true, "", "abcd", "")
    53  	testCheck(c, Contains, true, "", "", "")
    54  
    55  	testCheck(c, Contains, false, "Obtained value is not a string and has no .String()", 12, "1")
    56  	testCheck(c, Contains, false, "Substring must be a string", "", 1)
    57  }