mirror of https://github.com/knative/func.git
test: adding e2e github oncluster test scenario (#1649)
This commit is contained in:
parent
79430e9542
commit
2a273c98ee
|
@ -0,0 +1,90 @@
|
||||||
|
//go:build oncluster
|
||||||
|
// +build oncluster
|
||||||
|
|
||||||
|
package oncluster
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"gotest.tools/v3/assert"
|
||||||
|
common "knative.dev/func/test/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
Test scenario covered here:
|
||||||
|
- As a Developer I want my function stored on a public GitHub repo to get deployed on my cluster
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
* The function used as input for this scenario is stored in this repository at /test/oncluster/testdata/simplefunc
|
||||||
|
|
||||||
|
* On a CI Pull Request action (env CI="true") the branch used on the on-cluster test is the pull request reference.
|
||||||
|
The equivalent deploy func command would look like this:
|
||||||
|
|
||||||
|
func deploy --remote \
|
||||||
|
--git-url https://github.com/knative/func \
|
||||||
|
--git-dir test/oncluster/testdata/simplefunc \
|
||||||
|
--git-branch refs/pull/1650/head
|
||||||
|
|
||||||
|
* When not on CI, the branch used will be "main" and the repository is https://github.com/knative/func.git
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
func resolveGitVars() (gitRepoUrl string, gitRef string) {
|
||||||
|
var githubRepository = "knative/func"
|
||||||
|
gitRef = "main"
|
||||||
|
if os.Getenv("CI") == "true" {
|
||||||
|
// On a GitHub Action (Pull Request)
|
||||||
|
// https://docs.github.com/en/actions/learn-github-actions/variables
|
||||||
|
githubRepository, _ = os.LookupEnv("GITHUB_REPOSITORY")
|
||||||
|
gitRef, _ = os.LookupEnv("GITHUB_REF")
|
||||||
|
}
|
||||||
|
gitRepoUrl = "https://github.com/" + githubRepository + ".git"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestGitHubFunc tests the following use case:
|
||||||
|
// - As a Developer I want my function stored on a public GitHub repo to get deployed on my cluster
|
||||||
|
func TestGitHubFunc(t *testing.T) {
|
||||||
|
|
||||||
|
var tmpDir = t.TempDir()
|
||||||
|
var tmpRepo = "knative-func"
|
||||||
|
var cloneDir = filepath.Join(tmpDir, tmpRepo)
|
||||||
|
|
||||||
|
var githubRepo, githubRef = resolveGitVars()
|
||||||
|
var funcName = "simplefunc"
|
||||||
|
var funcContextDir = filepath.Join("test", "oncluster", "testdata", funcName)
|
||||||
|
var funcPath = filepath.Join(cloneDir, funcContextDir)
|
||||||
|
|
||||||
|
// -- Clone Func from GITHUB and checkout Branch
|
||||||
|
sh := common.NewShellCmd(t, tmpDir)
|
||||||
|
sh.ShouldFailOnError = true
|
||||||
|
sh.ShouldDumpOnSuccess = false
|
||||||
|
sh.Exec("git init " + tmpRepo)
|
||||||
|
|
||||||
|
sh.SourceDir = cloneDir
|
||||||
|
sh.Exec("git remote add origin " + githubRepo)
|
||||||
|
sh.Exec("git fetch --recurse-submodules=yes --depth=1 origin --update-head-ok --force " + githubRef)
|
||||||
|
sh.Exec("git checkout FETCH_HEAD")
|
||||||
|
|
||||||
|
// -- Deploy Func
|
||||||
|
knFunc := common.NewKnFuncShellCli(t)
|
||||||
|
knFunc.Exec("deploy",
|
||||||
|
"--path", funcPath,
|
||||||
|
"--registry", common.GetRegistry(),
|
||||||
|
"--remote",
|
||||||
|
"--verbose",
|
||||||
|
"--git-url", githubRepo,
|
||||||
|
"--git-branch", githubRef,
|
||||||
|
"--git-dir", funcContextDir,
|
||||||
|
)
|
||||||
|
defer knFunc.Exec("delete", "-p", funcPath)
|
||||||
|
|
||||||
|
// -- Assertions --
|
||||||
|
result := knFunc.Exec("invoke", "-p", funcPath)
|
||||||
|
assert.Assert(t, strings.Contains(result.Out, "simple func"), "Func body does not contain 'simple func'")
|
||||||
|
AssertThatTektonPipelineRunSucceed(t, funcName)
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
# Functions use the .func directory for local runtime data which should
|
||||||
|
# generally not be tracked in source control:
|
||||||
|
/.func
|
|
@ -0,0 +1,23 @@
|
||||||
|
specVersion: 0.35.0
|
||||||
|
name: simplefunc
|
||||||
|
runtime: node
|
||||||
|
registry: ""
|
||||||
|
image: ""
|
||||||
|
imageDigest: ""
|
||||||
|
created: 2023-03-23T14:40:09.370454106-03:00
|
||||||
|
build:
|
||||||
|
buildpacks: []
|
||||||
|
builder: ""
|
||||||
|
buildEnvs: []
|
||||||
|
run:
|
||||||
|
volumes: []
|
||||||
|
envs: []
|
||||||
|
deploy:
|
||||||
|
namespace: ""
|
||||||
|
remote: false
|
||||||
|
annotations: {}
|
||||||
|
options: {}
|
||||||
|
labels: []
|
||||||
|
healthEndpoints:
|
||||||
|
liveness: /health/liveness
|
||||||
|
readiness: /health/readiness
|
|
@ -0,0 +1,4 @@
|
||||||
|
function invoke(context) {
|
||||||
|
return { body: 'simple func' }
|
||||||
|
}
|
||||||
|
module.exports = invoke;
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,22 @@
|
||||||
|
{
|
||||||
|
"name": "http-handler",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"description": "A function which responds to HTTP requests",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "node test/unit.js && node test/integration.js",
|
||||||
|
"start": "FUNC_LOG_LEVEL=info faas-js-runtime ./index.js",
|
||||||
|
"debug": "nodemon --inspect ./node_modules/faas-js-runtime/bin/cli.js ./index.js"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"dependencies": {
|
||||||
|
"faas-js-runtime": "^0.9.7"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"nodemon": "^2.0.4",
|
||||||
|
"supertest": "^6.3.1",
|
||||||
|
"tape": "^5.0.1"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue