fn: favor fn-test-utils over hello (to be decommissioned) (#761)

This commit is contained in:
Tolga Ceylan
2018-02-28 17:44:13 -08:00
committed by GitHub
parent a2ed1dfb2d
commit a83f2cfbe8
8 changed files with 72 additions and 65 deletions

View File

@@ -16,18 +16,19 @@ type taskDockerTest struct {
id string
input io.Reader
output io.Writer
errors io.Writer
}
func (f *taskDockerTest) Command() string { return "" }
func (f *taskDockerTest) EnvVars() map[string]string {
return map[string]string{}
return map[string]string{"FN_FORMAT": "default"}
}
func (f *taskDockerTest) Labels() map[string]string { return nil }
func (f *taskDockerTest) Id() string { return f.id }
func (f *taskDockerTest) Group() string { return "" }
func (f *taskDockerTest) Image() string { return "fnproject/hello" }
func (f *taskDockerTest) Image() string { return "fnproject/fn-test-utils" }
func (f *taskDockerTest) Timeout() time.Duration { return 30 * time.Second }
func (f *taskDockerTest) Logger() (stdout, stderr io.Writer) { return f.output, nil }
func (f *taskDockerTest) Logger() (stdout, stderr io.Writer) { return f.output, f.errors }
func (f *taskDockerTest) WriteStat(context.Context, drivers.Stat) { /* TODO */ }
func (f *taskDockerTest) Volumes() [][2]string { return [][2]string{} }
func (f *taskDockerTest) Memory() uint64 { return 256 * 1024 * 1024 }
@@ -39,8 +40,10 @@ func (f *taskDockerTest) Input() io.Reader { return f.inp
func TestRunnerDocker(t *testing.T) {
dkr := NewDocker(drivers.Config{})
ctx := context.Background()
var output bytes.Buffer
var errors bytes.Buffer
task := &taskDockerTest{"test-docker", nil, nil}
task := &taskDockerTest{"test-docker", bytes.NewBufferString(`{"isDebug": true}`), &output, &errors}
cookie, err := dkr.Prepare(ctx, task)
if err != nil {
@@ -59,7 +62,8 @@ func TestRunnerDocker(t *testing.T) {
}
if result.Status() != "success" {
t.Fatal("Test should successfully run the image")
t.Fatalf("Test should successfully run the image: %s output: %s errors: %s",
result.Error(), output.String(), errors.String())
}
}
@@ -87,10 +91,12 @@ func TestRunnerDockerStdin(t *testing.T) {
dkr := NewDocker(drivers.Config{})
ctx := context.Background()
input := `{"name": "test"}`
var output bytes.Buffer
input := `{"echoContent": "italian parsley", "isDebug": true}`
task := &taskDockerTest{"test-docker-stdin", bytes.NewBufferString(input), &output}
var output bytes.Buffer
var errors bytes.Buffer
task := &taskDockerTest{"test-docker-stdin", bytes.NewBufferString(input), &output, &errors}
cookie, err := dkr.Prepare(ctx, task)
if err != nil {
@@ -109,10 +115,11 @@ func TestRunnerDockerStdin(t *testing.T) {
}
if result.Status() != "success" {
t.Error("Test should successfully run the image")
t.Fatalf("Test should successfully run the image: %s output: %s errors: %s",
result.Error(), output.String(), errors.String())
}
expect := "Hello test!"
expect := "italian parsley"
got := output.String()
if !strings.Contains(got, expect) {
t.Errorf("Test expected output to contain '%s', got '%s'", expect, got)
@@ -120,7 +127,7 @@ func TestRunnerDockerStdin(t *testing.T) {
}
func TestRegistry(t *testing.T) {
image := "fnproject/hello"
image := "fnproject/fn-test-utils"
sizer, err := CheckRegistry(context.Background(), image, docker.AuthConfiguration{})
if err != nil {