2014-07-26 16:18:29 +00:00
|
|
|
// +build ignore
|
|
|
|
|
|
|
|
// Make the test files from fstests.go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"html/template"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"regexp"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Search fstests.go and return all the test function names
|
|
|
|
func findTestFunctions() []string {
|
|
|
|
fns := []string{}
|
|
|
|
matcher := regexp.MustCompile(`^func\s+(Test.*?)\(`)
|
|
|
|
|
|
|
|
in, err := os.Open("fstests.go")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Couldn't open fstests.go: %v", err)
|
|
|
|
}
|
|
|
|
defer in.Close()
|
|
|
|
|
|
|
|
scanner := bufio.NewScanner(in)
|
|
|
|
for scanner.Scan() {
|
|
|
|
line := scanner.Text()
|
|
|
|
matches := matcher.FindStringSubmatch(line)
|
|
|
|
if len(matches) > 0 {
|
|
|
|
fns = append(fns, matches[1])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := scanner.Err(); err != nil {
|
|
|
|
log.Fatalf("Error scanning file: %v", err)
|
|
|
|
}
|
|
|
|
return fns
|
|
|
|
}
|
|
|
|
|
|
|
|
// Data to substitute
|
|
|
|
type Data struct {
|
|
|
|
Regenerate string
|
|
|
|
FsName string
|
|
|
|
UpperFsName string
|
|
|
|
TestName string
|
|
|
|
Fns []string
|
2016-08-20 17:47:33 +00:00
|
|
|
Suffix string
|
2014-07-26 16:18:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var testProgram = `
|
|
|
|
// Test {{ .UpperFsName }} filesystem interface
|
|
|
|
//
|
|
|
|
// Automatically generated - DO NOT EDIT
|
|
|
|
// Regenerate with: {{ .Regenerate }}
|
|
|
|
package {{ .FsName }}_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/ncw/rclone/fs"
|
|
|
|
"github.com/ncw/rclone/fstest/fstests"
|
|
|
|
"github.com/ncw/rclone/{{ .FsName }}"
|
2016-07-25 18:18:56 +00:00
|
|
|
{{ if eq .FsName "crypt" }} _ "github.com/ncw/rclone/local"
|
|
|
|
{{end}})
|
2014-07-26 16:18:29 +00:00
|
|
|
|
2016-08-20 17:47:33 +00:00
|
|
|
func TestSetup{{ .Suffix }}(t *testing.T)() {
|
2015-11-07 11:14:46 +00:00
|
|
|
fstests.NilObject = fs.Object((*{{ .FsName }}.Object)(nil))
|
2014-07-26 16:18:29 +00:00
|
|
|
fstests.RemoteName = "{{ .TestName }}"
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generic tests for the Fs
|
2016-08-20 17:47:33 +00:00
|
|
|
{{ range $fn := .Fns }}func {{ $fn }}{{ $.Suffix }}(t *testing.T){ fstests.{{ $fn }}(t) }
|
2014-07-26 16:18:29 +00:00
|
|
|
{{ end }}
|
|
|
|
`
|
|
|
|
|
|
|
|
// Generate test file piping it through gofmt
|
2016-08-20 17:47:33 +00:00
|
|
|
func generateTestProgram(t *template.Template, fns []string, Fsname string, suffix string) {
|
2014-07-26 16:18:29 +00:00
|
|
|
fsname := strings.ToLower(Fsname)
|
2016-08-20 17:47:33 +00:00
|
|
|
TestName := "Test" + Fsname + suffix + ":"
|
|
|
|
outfile := "../../" + fsname + "/" + fsname + suffix + "_test.go"
|
2014-07-26 16:18:29 +00:00
|
|
|
|
|
|
|
if fsname == "local" {
|
|
|
|
TestName = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
data := Data{
|
2015-02-14 18:48:08 +00:00
|
|
|
Regenerate: "make gen_tests",
|
2014-07-26 16:18:29 +00:00
|
|
|
FsName: fsname,
|
|
|
|
UpperFsName: Fsname,
|
|
|
|
TestName: TestName,
|
|
|
|
Fns: fns,
|
2016-08-20 17:47:33 +00:00
|
|
|
Suffix: suffix,
|
2014-07-26 16:18:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd := exec.Command("gofmt")
|
|
|
|
|
|
|
|
log.Printf("Writing %q", outfile)
|
|
|
|
out, err := os.Create(outfile)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
cmd.Stdout = out
|
|
|
|
|
|
|
|
gofmt, err := cmd.StdinPipe()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
if err = cmd.Start(); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
if err = t.Execute(gofmt, data); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
if err = gofmt.Close(); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
if err = cmd.Wait(); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
if err = out.Close(); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
fns := findTestFunctions()
|
|
|
|
t := template.Must(template.New("main").Parse(testProgram))
|
2016-08-20 17:47:33 +00:00
|
|
|
generateTestProgram(t, fns, "Local", "")
|
|
|
|
generateTestProgram(t, fns, "Swift", "")
|
|
|
|
generateTestProgram(t, fns, "S3", "")
|
|
|
|
generateTestProgram(t, fns, "Drive", "")
|
|
|
|
generateTestProgram(t, fns, "GoogleCloudStorage", "")
|
|
|
|
generateTestProgram(t, fns, "Dropbox", "")
|
|
|
|
generateTestProgram(t, fns, "AmazonCloudDrive", "")
|
|
|
|
generateTestProgram(t, fns, "OneDrive", "")
|
|
|
|
generateTestProgram(t, fns, "Hubic", "")
|
|
|
|
generateTestProgram(t, fns, "B2", "")
|
|
|
|
generateTestProgram(t, fns, "Yandex", "")
|
|
|
|
generateTestProgram(t, fns, "Crypt", "")
|
|
|
|
generateTestProgram(t, fns, "Crypt", "2")
|
2017-03-23 20:32:29 +00:00
|
|
|
generateTestProgram(t, fns, "Crypt", "3")
|
2017-01-31 20:34:11 +00:00
|
|
|
generateTestProgram(t, fns, "Sftp", "")
|
2016-12-27 20:52:30 +00:00
|
|
|
generateTestProgram(t, fns, "FTP", "")
|
2014-07-26 16:18:29 +00:00
|
|
|
log.Printf("Done")
|
|
|
|
}
|