1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/hack/integration-cli-on-swarm/host/enumerate.go
Josh Soref 39bcaee47b
Spelling fixes
* additional
* ambiguous
* anonymous
* anything
* application
* because
* before
* building
* capabilities
* circumstances
* commit
* committer
* compresses
* concatenated
* config
* container
* container's
* current
* definition
* delimiter
* disassociates
* discovery
* distributed
* doesnotexist
* downloads
* duplicates
* either
* enhancing
* enumerate
* escapable
* exactly
* expect
* expectations
* expected
* explicitly
* false
* filesystem
* following
* forbidden
* git with
* healthcheck
* ignore
* independent
* inheritance
* investigating
* irrelevant
* it
* logging
* looking
* membership
* mimic
* minimum
* modify
* mountpoint
* multiline
* notifier
* outputting
* outside
* overridden
* override
* parsable
* plugins
* precedence
* propagation
* provided
* provides
* registries
* repositories
* returning
* settings
* should
* signals
* someone
* something
* specifically
* successfully
* synchronize
* they've
* thinking
* uninitialized
* unintentionally
* unmarshaling
* unnamed
* unreferenced
* verify

Signed-off-by: Josh Soref <jsoref@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-07-03 13:13:09 -07:00

55 lines
1.5 KiB
Go

package main
import (
"fmt"
"io/ioutil"
"path/filepath"
"regexp"
)
var testFuncRegexp *regexp.Regexp
func init() {
testFuncRegexp = regexp.MustCompile(`(?m)^\s*func\s+\(\w*\s*\*(\w+Suite)\)\s+(Test\w+)`)
}
func enumerateTestsForBytes(b []byte) ([]string, error) {
var tests []string
submatches := testFuncRegexp.FindAllSubmatch(b, -1)
for _, submatch := range submatches {
if len(submatch) == 3 {
tests = append(tests, fmt.Sprintf("%s.%s$", submatch[1], submatch[2]))
}
}
return tests, nil
}
// enumerateTests enumerates valid `-check.f` strings for all the test functions.
// Note that we use regexp rather than parsing Go files for performance reason.
// (Try `TESTFLAGS=-check.list make test-integration-cli` to see the slowness of parsing)
// The files needs to be `gofmt`-ed
//
// The result will be as follows, but unsorted ('$' is appended because they are regexp for `-check.f`):
// "DockerAuthzSuite.TestAuthZPluginAPIDenyResponse$"
// "DockerAuthzSuite.TestAuthZPluginAllowEventStream$"
// ...
// "DockerTrustedSwarmSuite.TestTrustedServiceUpdate$"
func enumerateTests(wd string) ([]string, error) {
testGoFiles, err := filepath.Glob(filepath.Join(wd, "integration-cli", "*_test.go"))
if err != nil {
return nil, err
}
var allTests []string
for _, testGoFile := range testGoFiles {
b, err := ioutil.ReadFile(testGoFile)
if err != nil {
return nil, err
}
tests, err := enumerateTestsForBytes(b)
if err != nil {
return nil, err
}
allTests = append(allTests, tests...)
}
return allTests, nil
}