github.com/devcamcar/cli@v0.0.0-20181107134215-706a05759d18/test/cli_invoke_test.go (about)

     1  package test
     2  
     3  import (
     4  	"github.com/fnproject/cli/testharness"
     5  	"strings"
     6  	"testing"
     7  )
     8  
     9  func TestFnInvokeInvalidImage(t *testing.T) {
    10  	t.Parallel()
    11  
    12  	h := testharness.Create(t)
    13  	defer h.Cleanup()
    14  
    15  	appName1 := h.NewAppName()
    16  	funcName1 := h.NewFuncName(appName1)
    17  	h.Fn("create", "app", appName1).AssertSuccess()
    18  	h.Fn("create", "function", appName1, funcName1, "foo/duffimage:0.0.1").AssertSuccess()
    19  	h.Fn("invoke", appName1, funcName1).AssertFailed()
    20  }
    21  
    22  func TestFnInvokeValidImage(t *testing.T) {
    23  	t.Parallel()
    24  
    25  	h := testharness.Create(t)
    26  	defer h.Cleanup()
    27  
    28  	h.MkDir("fn")
    29  	h.Cd("fn")
    30  	withGoFunction(h)
    31  	h.WithFile("Dockerfile", dockerFile, 0644)
    32  	h.Docker("build", "-t", "fnproject/hello:latest", ".").AssertSuccess()
    33  
    34  	h.Cd("")
    35  	appName1 := h.NewAppName()
    36  	funcName1 := h.NewFuncName(appName1)
    37  	h.Fn("create", "app", appName1).AssertSuccess()
    38  	h.Fn("create", "function", appName1, funcName1, "fnproject/hello:latest").AssertSuccess()
    39  	h.Fn("invoke", appName1, funcName1).AssertSuccess()
    40  }
    41  
    42  func TestFnInvokeViaDirectUrl(t *testing.T) {
    43  	t.Parallel()
    44  
    45  	h := testharness.Create(t)
    46  	defer h.Cleanup()
    47  
    48  	h.MkDir("fn")
    49  	h.Cd("fn")
    50  	withGoFunction(h)
    51  	h.WithFile("Dockerfile", dockerFile, 0644)
    52  	h.Docker("build", "-t", "fnproject/hello:latest", ".").AssertSuccess()
    53  
    54  	appName1 := h.NewAppName()
    55  	funcName1 := h.NewFuncName(appName1)
    56  	h.Fn("create", "app", appName1).AssertSuccess()
    57  	h.Fn("create", "function", appName1, funcName1, "fnproject/hello:latest").AssertSuccess()
    58  
    59  	res := h.Fn("inspect", "function", appName1, funcName1, "--endpoint").AssertSuccess()
    60  
    61  	url := strings.TrimSpace(res.Stdout)
    62  
    63  	h.Fn("invoke", "--endpoint", url).AssertSuccess()
    64  }