add platformtest: infrastructure for ZFS compatiblity testing

This commit is contained in:
Christian Schwarz
2019-08-20 17:04:13 +02:00
parent 07956c2299
commit a6497b2c6e
15 changed files with 689 additions and 3 deletions
+51
View File
@@ -0,0 +1,51 @@
package main
import (
"context"
"flag"
"fmt"
"time"
"github.com/fatih/color"
"github.com/zrepl/zrepl/config"
"github.com/zrepl/zrepl/daemon/logging"
"github.com/zrepl/zrepl/logger"
"github.com/zrepl/zrepl/platformtest"
"github.com/zrepl/zrepl/platformtest/tests"
)
func main() {
root := flag.String("root", "", "empty root filesystem under which we conduct the platform test")
flag.Parse()
if *root == "" {
panic(*root)
}
outlets := logger.NewOutlets()
outlet, level, err := logging.ParseOutlet(config.LoggingOutletEnum{Ret: &config.StdoutLoggingOutlet{
LoggingOutletCommon: config.LoggingOutletCommon{
Level: "debug",
Format: "human",
},
}})
if err != nil {
panic(err)
}
outlets.Add(outlet, level)
logger := logger.NewLogger(outlets, 1*time.Second)
ctx := &platformtest.Context{
Context: platformtest.WithLogger(context.Background(), logger),
RootDataset: *root,
}
bold := color.New(color.Bold)
for _, c := range tests.Cases {
bold.Printf("BEGIN TEST CASE %s\n", c)
c(ctx)
bold.Printf("DONE TEST CASE %s\n", c)
fmt.Println()
}
}
+44
View File
@@ -0,0 +1,44 @@
package main
import (
"os"
"strings"
"testing"
)
// Idea taken from
// https://github.com/openSUSE/umoci/blob/v0.2.1/cmd/umoci/main_test.go
//
// How to generate coverage:
// go test -c -covermode=atomic -cover -coverpkg github.com/zrepl/zrepl/...
// sudo ../logmockzfs/logzfsenv /tmp/zrepl_platform_test.log /usr/bin/zfs \
// ./harness.test -test.coverprofile=/tmp/harness.out \
// -test.v __DEVEL--i-heard-you-like-tests \
// -root rpool/zreplplayground
// go tool cover -html=/tmp/harness.out -o /tmp/harness.html
//
// Merge with existing coverage reports using gocovmerge:
// https://github.com/wadey/gocovmerge
func TestMain(t *testing.T) {
var (
args []string
run bool
)
for _, arg := range os.Args {
switch {
case arg == "__DEVEL--i-heard-you-like-tests":
run = true
case strings.HasPrefix(arg, "-test"):
case strings.HasPrefix(arg, "__DEVEL"):
default:
args = append(args, arg)
}
}
os.Args = args
if run {
main()
}
}