-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: remove dependecy for boson-project git repository on e2e tests (#…
- Loading branch information
1 parent
e97a692
commit 59aa11c
Showing
8 changed files
with
188 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
//go:build oncluster | ||
|
||
package oncluster | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
"gotest.tools/v3/assert" | ||
"knative.dev/func/test/common" | ||
"knative.dev/func/test/testhttp" | ||
) | ||
|
||
func setupRemoteRepository(t *testing.T) (reposutoryUrl string) { | ||
|
||
repositoryPath := filepath.Join(t.TempDir(), "repository") | ||
helloTemplatePath := filepath.Join(repositoryPath, "go", "testhello") | ||
|
||
createFolder := func(folderPath string) { | ||
e := os.MkdirAll(folderPath, 0755) | ||
if e != nil { | ||
t.Error(e.Error()) | ||
} | ||
} | ||
createFile := func(path string, content string) { | ||
e := os.WriteFile(path, []byte(content), 0644) | ||
if e != nil { | ||
t.Error(e.Error()) | ||
} | ||
} | ||
|
||
createFolder(helloTemplatePath) | ||
createFolder(filepath.Join(helloTemplatePath, "hello")) | ||
|
||
createFile(filepath.Join(helloTemplatePath, "go.mod"), ` | ||
module function | ||
go 1.21 | ||
`) | ||
createFile(filepath.Join(helloTemplatePath, "handle.go"), ` | ||
package function | ||
import ( | ||
"fmt" | ||
"function/hello" | ||
"net/http" | ||
) | ||
func Handle(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Add("Content-Type", "text/plain") | ||
fmt.Fprintf(w, hello.Hello("TEST")+"\n") // "HELLO TEST"" | ||
} | ||
`) | ||
|
||
createFile(filepath.Join(helloTemplatePath, "hello", "hello.go"), ` | ||
package hello | ||
func Hello(name string) string { | ||
return "HELLO " + name | ||
} | ||
`) | ||
gitServer := common.GetGitServer(t) | ||
remoteRepo := gitServer.CreateRepository("hello") | ||
t.Cleanup(func() { | ||
gitServer.DeleteRepository("hello") | ||
}) | ||
|
||
GitInitialCommitAndPush(t, repositoryPath, remoteRepo.ExternalCloneURL) | ||
|
||
return remoteRepo.ExternalCloneURL | ||
} | ||
|
||
// TestRemoteRepository verifies function created using an | ||
// external template from a git repository | ||
func TestRemoteRepository(t *testing.T) { | ||
|
||
var funcName = "remote-repo-function" | ||
var funcPath = filepath.Join(t.TempDir(), funcName) | ||
|
||
gitRepoUrl := setupRemoteRepository(t) | ||
|
||
knFunc := common.NewKnFuncShellCli(t) | ||
knFunc.Exec("create", | ||
"--language", "go", | ||
"--template", "testhello", | ||
"--repository", gitRepoUrl, | ||
funcPath) | ||
|
||
knFunc.SourceDir = funcPath | ||
|
||
knFunc.Exec("deploy", "--registry", common.GetRegistry()) | ||
defer knFunc.Exec("delete") | ||
_, functionUrl := common.WaitForFunctionReady(t, funcName) | ||
|
||
_, funcResponse := testhttp.TestGet(t, functionUrl) | ||
assert.Assert(t, strings.Contains(funcResponse, "HELLO TEST")) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module function | ||
|
||
go 1.21 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package function | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"strings" | ||
) | ||
|
||
func Handle(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Add("Content-Type", "text/plain") | ||
testEnvVars := []string{} | ||
for _, e := range os.Environ() { | ||
if strings.HasPrefix(e, "TEST_") { | ||
testEnvVars = append(testEnvVars, e) | ||
} | ||
} | ||
fmt.Fprintf(w, "%v\n", strings.Join(testEnvVars, "\n")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module function | ||
|
||
go 1.21 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package function | ||
|
||
/* | ||
This function template read and (optionally) write the content of a file on the server | ||
The template is meant to be used in by `func config volumes` e2e test | ||
*/ | ||
import ( | ||
"fmt" | ||
"net/http" | ||
"os" | ||
) | ||
|
||
func Handle(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Add("Content-Type", "text/plain") | ||
|
||
// v=/test/volume-config/myconfig | ||
// w=hello | ||
path := r.URL.Query().Get("v") | ||
content := r.URL.Query().Get("w") | ||
|
||
if path != "" { | ||
if content != "" { | ||
f, err := os.Create(path) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "error creating file: %v\n", err) | ||
} else { | ||
defer f.Close() | ||
err = os.WriteFile(path, []byte(content), 0644) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "error writing file: %v\n", err) | ||
} | ||
} | ||
} | ||
b, err := os.ReadFile(path) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "error reading file: %v", err) | ||
} | ||
_, err = fmt.Fprintf(w, "%v", string(b)) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "error on response write: %v", err) | ||
} | ||
} | ||
|
||
} |