github.com/fnproject/cli@v0.0.0-20240508150455-e5d88bd86117/test/cli_invoke_test.go (about) 1 /* 2 * Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package test 18 19 import ( 20 "github.com/fnproject/cli/testharness" 21 "strings" 22 "testing" 23 ) 24 25 func TestFnInvokeInvalidImage(t *testing.T) { 26 t.Parallel() 27 28 h := testharness.Create(t) 29 defer h.Cleanup() 30 31 appName1 := h.NewAppName() 32 funcName1 := h.NewFuncName(appName1) 33 h.Fn("create", "app", appName1).AssertSuccess() 34 h.Fn("create", "function", appName1, funcName1, "foo/duffimage:0.0.1").AssertSuccess() 35 h.Fn("invoke", appName1, funcName1).AssertStdoutContains("Failed to pull image") 36 } 37 38 func TestFnInvokeValidImage(t *testing.T) { 39 t.Parallel() 40 41 h := testharness.Create(t) 42 defer h.Cleanup() 43 44 h.MkDir("fn") 45 h.Cd("fn") 46 withGoFunction(h) 47 h.WithFile("Dockerfile", dockerFile, 0644) 48 h.Docker("build", "-t", "fnproject/hello:latest", ".").AssertSuccess() 49 50 h.Cd("") 51 appName1 := h.NewAppName() 52 funcName1 := h.NewFuncName(appName1) 53 h.Fn("create", "app", appName1).AssertSuccess() 54 h.Fn("create", "function", appName1, funcName1, "fnproject/hello:latest").AssertSuccess() 55 h.Fn("invoke", appName1, funcName1).AssertSuccess() 56 } 57 58 func TestFnInvokeViaDirectUrl(t *testing.T) { 59 t.Parallel() 60 61 h := testharness.Create(t) 62 defer h.Cleanup() 63 64 h.MkDir("fn") 65 h.Cd("fn") 66 withGoFunction(h) 67 h.WithFile("Dockerfile", dockerFile, 0644) 68 h.Docker("build", "-t", "fnproject/hello:latest", ".").AssertSuccess() 69 70 appName1 := h.NewAppName() 71 funcName1 := h.NewFuncName(appName1) 72 h.Fn("create", "app", appName1).AssertSuccess() 73 h.Fn("create", "function", appName1, funcName1, "fnproject/hello:latest").AssertSuccess() 74 75 res := h.Fn("inspect", "function", appName1, funcName1, "--endpoint").AssertSuccess() 76 77 url := strings.TrimSpace(res.Stdout) 78 79 h.Fn("invoke", "--endpoint", url).AssertSuccess() 80 }