2019-04-10 15:08:00 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/laszlocph/drone-oss-08/cncd/pipeline/pipeline"
|
|
|
|
"github.com/laszlocph/drone-oss-08/cncd/pipeline/pipeline/backend/docker"
|
|
|
|
"github.com/laszlocph/drone-oss-08/cncd/pipeline/pipeline/backend/kubernetes"
|
|
|
|
"github.com/laszlocph/drone-oss-08/cncd/pipeline/pipeline/interrupt"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestExec(t *testing.T) {
|
|
|
|
reader, err := os.Open("../samples/sample_1/pipeline.json")
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Could not read pipeline %f", err)
|
|
|
|
}
|
|
|
|
defer reader.Close()
|
|
|
|
|
|
|
|
config, err := pipeline.Parse(reader)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Could not parse pipeline %f", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
engine, err := docker.NewEnv()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Could not start Docker engine %f", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Hour)
|
|
|
|
defer cancel()
|
|
|
|
ctx = interrupt.WithContext(ctx)
|
|
|
|
|
|
|
|
err = pipeline.New(config,
|
|
|
|
pipeline.WithContext(ctx),
|
|
|
|
pipeline.WithLogger(defaultLogger),
|
|
|
|
pipeline.WithTracer(defaultTracer),
|
|
|
|
pipeline.WithEngine(engine),
|
|
|
|
).Run()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Pipeline exited with error %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestKubeExec(t *testing.T) {
|
2019-04-12 09:36:30 +00:00
|
|
|
// reader, err := os.Open("../samples/sample_1/pipeline.json")
|
|
|
|
reader, err := os.Open("../samples/sample_7_redis/pipeline.json")
|
2019-04-10 15:08:00 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Could not read pipeline %f", err)
|
|
|
|
}
|
|
|
|
defer reader.Close()
|
|
|
|
|
|
|
|
config, err := pipeline.Parse(reader)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Could not parse pipeline %f", err)
|
|
|
|
}
|
|
|
|
|
2019-04-10 19:41:06 +00:00
|
|
|
// os.Setenv("KUBECONFIG", "/etc/rancher/k3s/k3s.yaml")
|
2019-04-10 15:08:00 +00:00
|
|
|
engine, err := kubernetes.New()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Could not start Kubernetes engine %f", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Hour)
|
|
|
|
defer cancel()
|
|
|
|
ctx = interrupt.WithContext(ctx)
|
|
|
|
|
|
|
|
err = pipeline.New(config,
|
|
|
|
pipeline.WithContext(ctx),
|
|
|
|
pipeline.WithLogger(defaultLogger),
|
|
|
|
pipeline.WithTracer(defaultTracer),
|
|
|
|
pipeline.WithEngine(engine),
|
|
|
|
).Run()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Pipeline exited with error %v", err)
|
|
|
|
}
|
|
|
|
}
|