github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/hack/integration-cli-on-swarm/host/enumerate_test.go (about)

     1  package main
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"reflect"
     7  	"sort"
     8  	"strings"
     9  	"testing"
    10  )
    11  
    12  func getRepoTopDir(t *testing.T) string {
    13  	wd, err := os.Getwd()
    14  	if err != nil {
    15  		t.Fatal(err)
    16  	}
    17  	wd = filepath.Clean(wd)
    18  	suffix := "hack/integration-cli-on-swarm/host"
    19  	if !strings.HasSuffix(wd, suffix) {
    20  		t.Skipf("cwd seems strange (needs to have suffix %s): %v", suffix, wd)
    21  	}
    22  	return filepath.Clean(filepath.Join(wd, "../../.."))
    23  }
    24  
    25  func TestEnumerateTests(t *testing.T) {
    26  	if testing.Short() {
    27  		t.Skip("skipping in short mode")
    28  	}
    29  	tests, err := enumerateTests(getRepoTopDir(t))
    30  	if err != nil {
    31  		t.Fatal(err)
    32  	}
    33  	sort.Strings(tests)
    34  	t.Logf("enumerated %d test filter strings:", len(tests))
    35  	for _, s := range tests {
    36  		t.Logf("- %q", s)
    37  	}
    38  }
    39  
    40  func TestEnumerateTestsForBytes(t *testing.T) {
    41  	b := []byte(`package main
    42  import (
    43  	"github.com/go-check/check"
    44  )
    45  
    46  func (s *FooSuite) TestA(c *check.C) {
    47  }
    48  
    49  func (s *FooSuite) TestAAA(c *check.C) {
    50  }
    51  
    52  func (s *BarSuite) TestBar(c *check.C) {
    53  }
    54  
    55  func (x *FooSuite) TestC(c *check.C) {
    56  }
    57  
    58  func (*FooSuite) TestD(c *check.C) {
    59  }
    60  
    61  // should not be counted
    62  func (s *FooSuite) testE(c *check.C) {
    63  }
    64  
    65  // counted, although we don't support ungofmt file
    66    func   (s *FooSuite)    TestF  (c   *check.C){}
    67  `)
    68  	expected := []string{
    69  		"FooSuite.TestA$",
    70  		"FooSuite.TestAAA$",
    71  		"BarSuite.TestBar$",
    72  		"FooSuite.TestC$",
    73  		"FooSuite.TestD$",
    74  		"FooSuite.TestF$",
    75  	}
    76  
    77  	actual, err := enumerateTestsForBytes(b)
    78  	if err != nil {
    79  		t.Fatal(err)
    80  	}
    81  	if !reflect.DeepEqual(expected, actual) {
    82  		t.Fatalf("expected %q, got %q", expected, actual)
    83  	}
    84  }