2018-09-29 21:48:29 +08:00
|
|
|
// Config handling
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-11-04 18:12:57 +08:00
|
|
|
"fmt"
|
2022-08-20 22:38:02 +08:00
|
|
|
"os"
|
2018-09-29 21:48:29 +08:00
|
|
|
"path"
|
2024-09-25 22:47:30 +08:00
|
|
|
"slices"
|
2018-09-29 21:48:29 +08:00
|
|
|
|
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
|
|
|
|
//
|
2021-11-04 19:50:43 +08:00
|
|
|
// FIXME make bucket-based remotes set sub-dir automatically???
|
2018-09-29 21:48:29 +08:00
|
|
|
type Backend struct {
|
2020-10-26 00:15:41 +08:00
|
|
|
Backend string // name of the backend directory
|
|
|
|
Remote string // name of the test remote
|
|
|
|
FastList bool // set to test with -fast-list
|
|
|
|
Short bool // set to test with -short
|
|
|
|
OneOnly bool // set to run only one backend test at once
|
|
|
|
MaxFile string // file size limit
|
|
|
|
CleanUp bool // when running clean, run cleanup first
|
|
|
|
Ignore []string // test names to ignore the failure of
|
|
|
|
Tests []string // paths of tests to run, blank for all
|
2024-09-25 22:47:30 +08:00
|
|
|
IgnoreTests []string // paths of tests not to run, blank for none
|
2020-10-26 00:15:41 +08:00
|
|
|
ListRetries int // -list-retries if > 0
|
2021-10-21 00:34:56 +08:00
|
|
|
ExtraTime float64 // factor to multiply the timeout by
|
2019-07-02 00:42:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// includeTest returns true if this backend should be included in this
|
|
|
|
// test
|
|
|
|
func (b *Backend) includeTest(t *Test) bool {
|
2024-09-25 22:47:30 +08:00
|
|
|
// Is this test ignored
|
|
|
|
if slices.Contains(b.IgnoreTests, t.Path) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
// Empty b.Tests imples do all of them except the ignored
|
2019-07-02 00:42:34 +08:00
|
|
|
if len(b.Tests) == 0 {
|
|
|
|
return true
|
|
|
|
}
|
2024-09-25 22:47:30 +08:00
|
|
|
return slices.Contains(b.Tests, t.Path)
|
2018-09-29 21:48:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// MakeRuns creates Run objects the Backend and Test
|
|
|
|
//
|
Spelling fixes
Fix spelling of: above, already, anonymous, associated,
authentication, bandwidth, because, between, blocks, calculate,
candidates, cautious, changelog, cleaner, clipboard, command,
completely, concurrently, considered, constructs, corrupt, current,
daemon, dependencies, deprecated, directory, dispatcher, download,
eligible, ellipsis, encrypter, endpoint, entrieslist, essentially,
existing writers, existing, expires, filesystem, flushing, frequently,
hierarchy, however, implementation, implements, inaccurate,
individually, insensitive, longer, maximum, metadata, modified,
multipart, namedirfirst, nextcloud, obscured, opened, optional,
owncloud, pacific, passphrase, password, permanently, persimmon,
positive, potato, protocol, quota, receiving, recommends, referring,
requires, revisited, satisfied, satisfies, satisfy, semver,
serialized, session, storage, strategies, stringlist, successful,
supported, surprise, temporarily, temporary, transactions, unneeded,
update, uploads, wrapped
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2020-10-09 08:17:24 +08:00
|
|
|
// There can be several created, one for each combination of optional
|
2020-10-14 05:49:58 +08:00
|
|
|
// flags (e.g. 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 {
|
2024-08-18 22:58:35 +08:00
|
|
|
fs.Logf(nil, "Invalid maxfile value %q: %v", b.MaxFile, err)
|
2019-09-17 01:52:41 +08:00
|
|
|
}
|
|
|
|
}
|
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{
|
2020-10-26 00:15:41 +08:00
|
|
|
Remote: b.Remote,
|
|
|
|
Backend: b.Backend,
|
|
|
|
Path: t.Path,
|
|
|
|
FastList: fastlist,
|
|
|
|
Short: (b.Short && t.Short),
|
|
|
|
NoRetries: t.NoRetries,
|
|
|
|
OneOnly: b.OneOnly,
|
|
|
|
NoBinary: t.NoBinary,
|
|
|
|
SizeLimit: int64(maxSize),
|
|
|
|
Ignore: ignore,
|
|
|
|
ListRetries: b.ListRetries,
|
2021-10-21 00:34:56 +08:00
|
|
|
ExtraTime: b.ExtraTime,
|
2019-08-09 02:58:02 +08:00
|
|
|
}
|
|
|
|
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) {
|
2022-08-20 22:38:02 +08:00
|
|
|
d, err := os.ReadFile(configFile)
|
2018-09-29 21:48:29 +08:00
|
|
|
if err != nil {
|
2021-11-04 18:12:57 +08:00
|
|
|
return nil, fmt.Errorf("failed to read config file: %w", err)
|
2018-09-29 21:48:29 +08:00
|
|
|
}
|
|
|
|
config := &Config{}
|
|
|
|
err = yaml.Unmarshal(d, &config)
|
|
|
|
if err != nil {
|
2021-11-04 18:12:57 +08:00
|
|
|
return nil, fmt.Errorf("failed to parse config file: %w", err)
|
2018-09-29 21:48:29 +08:00
|
|
|
}
|
|
|
|
// 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 {
|
2024-08-18 22:58:35 +08:00
|
|
|
fs.Logf(nil, "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 {
|
2024-08-18 22:58:35 +08:00
|
|
|
fs.Fatalf(nil, "couldn't find remote %q: %v", name, err)
|
2019-01-10 18:59:32 +08:00
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|