2019-08-20 17:04:13 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2019-09-29 18:44:59 +02:00
|
|
|
"path/filepath"
|
2019-08-20 17:04:13 +02:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/fatih/color"
|
2019-09-29 18:44:59 +02:00
|
|
|
"github.com/pkg/errors"
|
2019-08-20 17:04:13 +02:00
|
|
|
"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() {
|
|
|
|
|
2019-09-29 18:44:59 +02:00
|
|
|
var args struct {
|
|
|
|
createArgs platformtest.ZpoolCreateArgs
|
2019-08-20 17:04:13 +02:00
|
|
|
}
|
2019-09-29 18:44:59 +02:00
|
|
|
flag.StringVar(&args.createArgs.PoolName, "poolname", "", "")
|
|
|
|
flag.StringVar(&args.createArgs.ImagePath, "imagepath", "", "")
|
|
|
|
flag.Int64Var(&args.createArgs.ImageSize, "imagesize", 100*(1<<20), "")
|
|
|
|
flag.StringVar(&args.createArgs.Mountpoint, "mountpoint", "none", "")
|
|
|
|
flag.Parse()
|
2019-08-20 17:04:13 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2019-09-29 18:44:59 +02:00
|
|
|
if err := args.createArgs.Validate(); err != nil {
|
|
|
|
logger.Error(err.Error())
|
|
|
|
panic(err)
|
2019-08-20 17:04:13 +02:00
|
|
|
}
|
2019-09-29 18:44:59 +02:00
|
|
|
ctx := platformtest.WithLogger(context.Background(), logger)
|
|
|
|
ex := platformtest.NewEx(logger)
|
2019-08-20 17:04:13 +02:00
|
|
|
|
|
|
|
bold := color.New(color.Bold)
|
2019-10-14 17:32:58 +02:00
|
|
|
boldRed := color.New(color.Bold, color.FgHiRed)
|
|
|
|
boldGreen := color.New(color.Bold, color.FgHiGreen)
|
2019-08-20 17:04:13 +02:00
|
|
|
for _, c := range tests.Cases {
|
2019-09-29 18:44:59 +02:00
|
|
|
// ATTENTION future parallelism must pass c by value into closure!
|
|
|
|
err := func() error {
|
|
|
|
bold.Printf("BEGIN TEST CASE %s\n", c)
|
|
|
|
pool, err := platformtest.CreateOrReplaceZpool(ctx, ex, args.createArgs)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "create test pool")
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
if err := pool.Destroy(ctx, ex); err != nil {
|
|
|
|
fmt.Printf("error destroying test pool: %s", err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
ctx := &platformtest.Context{
|
|
|
|
Context: ctx,
|
|
|
|
RootDataset: filepath.Join(pool.Name(), "rootds"),
|
|
|
|
}
|
|
|
|
c(ctx)
|
|
|
|
return nil
|
|
|
|
}()
|
|
|
|
if err != nil {
|
2019-10-14 17:32:58 +02:00
|
|
|
boldRed.Printf("TEST CASE FAILED WITH ERROR:\n")
|
|
|
|
} else {
|
|
|
|
boldGreen.Printf("DONE TEST CASE %s\n", c)
|
2019-09-29 18:44:59 +02:00
|
|
|
}
|
2019-10-14 17:32:58 +02:00
|
|
|
fmt.Println()
|
2019-08-20 17:04:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|