github.com/devcamcar/cli@v0.0.0-20181107134215-706a05759d18/test/cli_docker_runtime_test.go (about) 1 package test 2 3 import ( 4 "github.com/fnproject/cli/testharness" 5 "testing" 6 ) 7 8 const dockerFile = `FROM golang:latest 9 FROM fnproject/go:dev as build-stage 10 WORKDIR /function 11 ADD . /go/src/func/ 12 RUN cd /go/src/func/ && go build -o func 13 FROM fnproject/go 14 WORKDIR /function 15 COPY --from=build-stage /go/src/func/func /function/ 16 ENTRYPOINT ["./func"] 17 ` 18 19 const funcYaml = `name: fn_test_hello_docker_runtime 20 version: 0.0.1 21 runtime: docker` 22 23 func withGoFunction(h *testharness.CLIHarness) { 24 25 h.CopyFiles(map[string]string{ 26 "simplefunc/vendor": "vendor", 27 "simplefunc/func.go": "func.go", 28 "simplefunc/Gopkg.lock": "Gopkg.lock", 29 "simplefunc/Gopkg.toml": "Gopkg.toml", 30 }) 31 } 32 33 func TestDockerRuntimeInit(t *testing.T) { 34 t.Parallel() 35 tctx := testharness.Create(t) 36 defer tctx.Cleanup() 37 38 appName := tctx.NewAppName() 39 fnName := tctx.NewFuncName(appName) 40 tctx.MkDir(fnName) 41 tctx.Cd(fnName) 42 withGoFunction(tctx) 43 tctx.WithFile("Dockerfile", dockerFile, 0644) 44 45 tctx.Fn("init").AssertSuccess() 46 tctx.Fn("--verbose", "build").AssertSuccess() 47 tctx.Fn("--registry", "test", "deploy", "--local", "--app", appName).AssertSuccess() 48 tctx.Fn("invoke", appName, fnName).AssertSuccess() 49 } 50 51 func TestDockerRuntimeBuildFailsWithNoDockerfile(t *testing.T) { 52 t.Parallel() 53 tctx := testharness.Create(t) 54 defer tctx.Cleanup() 55 56 appName := tctx.NewAppName() 57 fnName := tctx.NewFuncName(appName) 58 tctx.MkDir(fnName) 59 tctx.Cd(fnName) 60 withGoFunction(tctx) 61 tctx.WithFile("func.yaml", funcYaml, 0644) 62 63 tctx.Fn("--verbose", "build").AssertFailed().AssertStderrContains("Dockerfile does not exist") 64 65 }