mirror of https://github.com/knative/func.git
chore: prepare/update oncluster e2e test for presubmit (#2270)
This commit is contained in:
parent
6292fb7c71
commit
a0b9d358ab
|
@ -12,10 +12,14 @@ import (
|
|||
"k8s.io/client-go/kubernetes"
|
||||
)
|
||||
|
||||
var DefaultGitServer GitProvider
|
||||
|
||||
func GetGitServer(T *testing.T) GitProvider {
|
||||
gitTestServer := GitTestServerProvider{}
|
||||
gitTestServer.Init(T)
|
||||
return &gitTestServer
|
||||
if DefaultGitServer == nil {
|
||||
DefaultGitServer = &GitTestServerKnativeProvider{}
|
||||
}
|
||||
DefaultGitServer.Init(T)
|
||||
return DefaultGitServer
|
||||
}
|
||||
|
||||
type GitRemoteRepo struct {
|
||||
|
@ -34,14 +38,14 @@ type GitProvider interface {
|
|||
// Git Server on Kubernetes as Knative Service (func-git)
|
||||
// ------------------------------------------------------
|
||||
|
||||
type GitTestServerProvider struct {
|
||||
type GitTestServerKnativeProvider struct {
|
||||
PodName string
|
||||
ServiceUrl string
|
||||
Kubectl *TestExecCmd
|
||||
t *testing.T
|
||||
}
|
||||
|
||||
func (g *GitTestServerProvider) Init(T *testing.T) {
|
||||
func (g *GitTestServerKnativeProvider) Init(T *testing.T) {
|
||||
|
||||
g.t = T
|
||||
if g.PodName == "" {
|
||||
|
@ -83,7 +87,7 @@ func (g *GitTestServerProvider) Init(T *testing.T) {
|
|||
T.Logf("Initialized HTTP Func Git Server: Server URL = %v Pod Name = %v\n", g.ServiceUrl, g.PodName)
|
||||
}
|
||||
|
||||
func (g *GitTestServerProvider) CreateRepository(repoName string) *GitRemoteRepo {
|
||||
func (g *GitTestServerKnativeProvider) CreateRepository(repoName string) *GitRemoteRepo {
|
||||
// kubectl exec $podname -c user-container -- git-repo create $reponame
|
||||
cmdResult := g.Kubectl.Exec("exec", g.PodName, "-c", "user-container", "--", "git-repo", "create", repoName)
|
||||
if !strings.Contains(cmdResult.Out, "created") {
|
||||
|
@ -98,7 +102,7 @@ func (g *GitTestServerProvider) CreateRepository(repoName string) *GitRemoteRepo
|
|||
return gitRepo
|
||||
}
|
||||
|
||||
func (g *GitTestServerProvider) DeleteRepository(repoName string) {
|
||||
func (g *GitTestServerKnativeProvider) DeleteRepository(repoName string) {
|
||||
cmdResult := g.Kubectl.Exec("exec", g.PodName, "-c", "user-container", "--", "git-repo", "delete", repoName)
|
||||
if !strings.Contains(cmdResult.Out, "deleted") {
|
||||
g.t.Fatal("unable to delete git bare repository " + repoName)
|
||||
|
|
|
@ -69,8 +69,7 @@ func TestBasicGit(t *testing.T) {
|
|||
var funcPath = filepath.Join(t.TempDir(), funcName)
|
||||
|
||||
func() {
|
||||
gitServer := common.GitTestServerProvider{}
|
||||
gitServer.Init(t)
|
||||
gitServer := common.GetGitServer(t)
|
||||
remoteRepo := gitServer.CreateRepository(funcName)
|
||||
defer gitServer.DeleteRepository(funcName)
|
||||
|
||||
|
|
|
@ -26,8 +26,7 @@ func TestContextDirFunc(t *testing.T) {
|
|||
|
||||
func() {
|
||||
|
||||
gitServer := common.GitTestServerProvider{}
|
||||
gitServer.Init(t)
|
||||
gitServer := common.GetGitServer(t)
|
||||
remoteRepo := gitServer.CreateRepository(gitProjectName)
|
||||
defer gitServer.DeleteRepository(gitProjectName)
|
||||
|
||||
|
|
|
@ -34,8 +34,7 @@ func TestFromCliDefaultBranch(t *testing.T) {
|
|||
var funcName = gitProjectName
|
||||
var funcPath = gitProjectPath
|
||||
|
||||
gitServer := common.GitTestServerProvider{}
|
||||
gitServer.Init(t)
|
||||
gitServer := common.GetGitServer(t)
|
||||
remoteRepo := gitServer.CreateRepository(gitProjectName)
|
||||
defer gitServer.DeleteRepository(gitProjectName)
|
||||
|
||||
|
@ -67,8 +66,7 @@ func TestFromCliFeatureBranch(t *testing.T) {
|
|||
var funcName = "test-func-cli-feature-branch" + rand.String(5)
|
||||
var funcPath = filepath.Join(t.TempDir(), funcName)
|
||||
|
||||
gitServer := common.GitTestServerProvider{}
|
||||
gitServer.Init(t)
|
||||
gitServer := common.GetGitServer(t)
|
||||
remoteRepo := gitServer.CreateRepository(funcName)
|
||||
defer gitServer.DeleteRepository(funcName)
|
||||
|
||||
|
@ -113,8 +111,7 @@ func TestFromCliContextDirFunc(t *testing.T) {
|
|||
var funcContextDir = filepath.Join("functions", funcName)
|
||||
var funcPath = filepath.Join(gitProjectPath, funcContextDir)
|
||||
|
||||
gitServer := common.GitTestServerProvider{}
|
||||
gitServer.Init(t)
|
||||
gitServer := common.GetGitServer(t)
|
||||
remoteRepo := gitServer.CreateRepository(gitProjectName)
|
||||
defer gitServer.DeleteRepository(gitProjectName)
|
||||
|
||||
|
|
|
@ -95,8 +95,7 @@ func GitRevisionCheck(
|
|||
|
||||
var funcPath = filepath.Join(t.TempDir(), funcName)
|
||||
|
||||
gitServer := common.GitTestServerProvider{}
|
||||
gitServer.Init(t)
|
||||
gitServer := common.GetGitServer(t)
|
||||
remoteRepo := gitServer.CreateRepository(funcName)
|
||||
defer gitServer.DeleteRepository(funcName)
|
||||
|
||||
|
|
|
@ -63,8 +63,7 @@ func runtimeImpl(t *testing.T, lang string, builder string) {
|
|||
var funcName = gitProjectName
|
||||
var funcPath = gitProjectPath
|
||||
|
||||
gitServer := common.GitTestServerProvider{}
|
||||
gitServer.Init(t)
|
||||
gitServer := common.GetGitServer(t)
|
||||
remoteRepo := gitServer.CreateRepository(gitProjectName)
|
||||
defer gitServer.DeleteRepository(gitProjectName)
|
||||
|
||||
|
|
Loading…
Reference in New Issue