2018-09-29 21:48:29 +08:00
|
|
|
// Config handling
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"path"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2019-07-29 01:47:38 +08:00
|
|
|
"github.com/rclone/rclone/fs"
|
2018-12-04 18:11:57 +08:00
|
|
|
yaml "gopkg.in/yaml.v2"
|
2018-09-29 21:48:29 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// Test describes an integration test to run with `go test`
|
|
|
|
type Test struct {
|
|
|
|
Path string // path to the source directory
|
|
|
|
FastList bool // if it is possible to add -fast-list to tests
|
2019-08-29 13:10:10 +08:00
|
|
|
Short bool // if it is possible to run the test with -short
|
2018-09-29 21:48:29 +08:00
|
|
|
AddBackend bool // set if Path needs the current backend appending
|
|
|
|
NoRetries bool // set if no retries should be performed
|
2018-10-24 00:31:11 +08:00
|
|
|
NoBinary bool // set to not build a binary in advance
|
2019-05-01 18:46:42 +08:00
|
|
|
LocalOnly bool // if set only run with the local backend
|
2018-09-29 21:48:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Backend describes a backend test
|
|
|
|
//
|
|
|
|
// FIXME make bucket based remotes set sub-dir automatically???
|
|
|
|
type Backend struct {
|
2019-01-13 04:18:05 +08:00
|
|
|
Backend string // name of the backend directory
|
|
|
|
Remote string // name of the test remote
|
|
|
|
FastList bool // set to test with -fast-list
|
2019-08-29 13:10:10 +08:00
|
|
|
Short bool // set to test with -short
|
2019-01-13 04:18:05 +08:00
|
|
|
OneOnly bool // set to run only one backend test at once
|
2019-09-17 01:52:41 +08:00
|
|
|
MaxFile string // file size limit
|
2020-03-31 22:56:58 +08:00
|
|
|
CleanUp bool // when running clean, run cleanup first
|
2019-01-13 04:18:05 +08:00
|
|
|
Ignore []string // test names to ignore the failure of
|
2019-07-02 00:42:34 +08:00
|
|
|
Tests []string // paths of tests to run, blank for all
|
|
|
|
}
|
|
|
|
|
|
|
|
// includeTest returns true if this backend should be included in this
|
|
|
|
// test
|
|
|
|
func (b *Backend) includeTest(t *Test) bool {
|
|
|
|
if len(b.Tests) == 0 {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
for _, testPath := range b.Tests {
|
|
|
|
if testPath == t.Path {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
2018-09-29 21:48:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// MakeRuns creates Run objects the Backend and Test
|
|
|
|
//
|
2019-08-09 02:58:02 +08:00
|
|
|
// There can be several created, one for each combination of optionl
|
|
|
|
// flags (eg FastList)
|
2018-09-29 21:48:29 +08:00
|
|
|
func (b *Backend) MakeRuns(t *Test) (runs []*Run) {
|
2019-07-02 00:42:34 +08:00
|
|
|
if !b.includeTest(t) {
|
|
|
|
return runs
|
|
|
|
}
|
2019-09-17 01:52:41 +08:00
|
|
|
maxSize := fs.SizeSuffix(0)
|
|
|
|
if b.MaxFile != "" {
|
|
|
|
if err := maxSize.Set(b.MaxFile); err != nil {
|
|
|
|
log.Printf("Invalid maxfile value %q: %v", b.MaxFile, err)
|
|
|
|
}
|
|
|
|
}
|
2018-09-29 21:48:29 +08:00
|
|
|
fastlists := []bool{false}
|
|
|
|
if b.FastList && t.FastList {
|
|
|
|
fastlists = append(fastlists, true)
|
|
|
|
}
|
2019-01-13 04:18:05 +08:00
|
|
|
ignore := make(map[string]struct{}, len(b.Ignore))
|
|
|
|
for _, item := range b.Ignore {
|
|
|
|
ignore[item] = struct{}{}
|
|
|
|
}
|
2019-08-09 02:58:02 +08:00
|
|
|
for _, fastlist := range fastlists {
|
|
|
|
if t.LocalOnly && b.Backend != "local" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
run := &Run{
|
|
|
|
Remote: b.Remote,
|
|
|
|
Backend: b.Backend,
|
|
|
|
Path: t.Path,
|
|
|
|
FastList: fastlist,
|
2019-08-29 13:10:10 +08:00
|
|
|
Short: (b.Short && t.Short),
|
2019-08-09 02:58:02 +08:00
|
|
|
NoRetries: t.NoRetries,
|
|
|
|
OneOnly: b.OneOnly,
|
|
|
|
NoBinary: t.NoBinary,
|
2019-09-17 01:52:41 +08:00
|
|
|
SizeLimit: int64(maxSize),
|
2019-08-09 02:58:02 +08:00
|
|
|
Ignore: ignore,
|
|
|
|
}
|
|
|
|
if t.AddBackend {
|
|
|
|
run.Path = path.Join(run.Path, b.Backend)
|
2018-09-29 21:48:29 +08:00
|
|
|
}
|
2019-08-09 02:58:02 +08:00
|
|
|
runs = append(runs, run)
|
2018-09-29 21:48:29 +08:00
|
|
|
}
|
|
|
|
return runs
|
|
|
|
}
|
|
|
|
|
|
|
|
// Config describes the config for this program
|
|
|
|
type Config struct {
|
|
|
|
Tests []Test
|
|
|
|
Backends []Backend
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewConfig reads the config file
|
|
|
|
func NewConfig(configFile string) (*Config, error) {
|
|
|
|
d, err := ioutil.ReadFile(configFile)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "failed to read config file")
|
|
|
|
}
|
|
|
|
config := &Config{}
|
|
|
|
err = yaml.Unmarshal(d, &config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "failed to parse config file")
|
|
|
|
}
|
|
|
|
// d, err = yaml.Marshal(&config)
|
|
|
|
// if err != nil {
|
|
|
|
// log.Fatalf("error: %v", err)
|
|
|
|
// }
|
|
|
|
// fmt.Printf("--- m dump:\n%s\n\n", string(d))
|
|
|
|
return config, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// MakeRuns makes Run objects for each combination of Backend and Test
|
|
|
|
// in the config
|
2018-10-24 17:33:38 +08:00
|
|
|
func (c *Config) MakeRuns() (runs Runs) {
|
2018-09-29 21:48:29 +08:00
|
|
|
for _, backend := range c.Backends {
|
|
|
|
for _, test := range c.Tests {
|
|
|
|
runs = append(runs, backend.MakeRuns(&test)...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return runs
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filter the Backends with the remotes passed in.
|
|
|
|
//
|
|
|
|
// If no backend is found with a remote is found then synthesize one
|
|
|
|
func (c *Config) filterBackendsByRemotes(remotes []string) {
|
|
|
|
var newBackends []Backend
|
|
|
|
for _, name := range remotes {
|
|
|
|
found := false
|
|
|
|
for i := range c.Backends {
|
|
|
|
if c.Backends[i].Remote == name {
|
|
|
|
newBackends = append(newBackends, c.Backends[i])
|
|
|
|
found = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !found {
|
|
|
|
log.Printf("Remote %q not found - inserting with default flags", name)
|
2019-01-10 18:59:32 +08:00
|
|
|
// Lookup which backend
|
|
|
|
fsInfo, _, _, _, err := fs.ConfigFs(name)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("couldn't find remote %q: %v", name, err)
|
|
|
|
}
|
|
|
|
newBackends = append(newBackends, Backend{Backend: fsInfo.FileName(), Remote: name})
|
2018-09-29 21:48:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
c.Backends = newBackends
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filter the Backends with the backendNames passed in
|
|
|
|
func (c *Config) filterBackendsByBackends(backendNames []string) {
|
|
|
|
var newBackends []Backend
|
|
|
|
for _, name := range backendNames {
|
|
|
|
for i := range c.Backends {
|
|
|
|
if c.Backends[i].Backend == name {
|
|
|
|
newBackends = append(newBackends, c.Backends[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.Backends = newBackends
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filter the incoming tests into the backends selected
|
|
|
|
func (c *Config) filterTests(paths []string) {
|
|
|
|
var newTests []Test
|
|
|
|
for _, path := range paths {
|
|
|
|
for i := range c.Tests {
|
|
|
|
if c.Tests[i].Path == path {
|
|
|
|
newTests = append(newTests, c.Tests[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.Tests = newTests
|
|
|
|
}
|