Skip to content

Commit

Permalink
chore: prepare/update oncluster e2e test for presubmit (#2270)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrangelramos committed Apr 12, 2024
1 parent 6292fb7 commit a0b9d35
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 21 deletions.
18 changes: 11 additions & 7 deletions test/common/gitserver.go
Expand Up @@ -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 {
Expand All @@ -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 == "" {
Expand Down Expand Up @@ -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") {
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions test/oncluster/scenario_basic_test.go
Expand Up @@ -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)

Expand Down
3 changes: 1 addition & 2 deletions test/oncluster/scenario_context-dir_test.go
Expand Up @@ -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)

Expand Down
9 changes: 3 additions & 6 deletions test/oncluster/scenario_from-cli_test.go
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
3 changes: 1 addition & 2 deletions test/oncluster/scenario_revision_test.go
Expand Up @@ -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)

Expand Down
3 changes: 1 addition & 2 deletions test/oncluster/scenario_runtime_test.go
Expand Up @@ -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)

Expand Down

0 comments on commit a0b9d35

Please sign in to comment.