-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean e2e test example #1535
Clean e2e test example #1535
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,3 @@ tags | |
# VSCode specific | ||
.vscode | ||
|
||
# local .odo config directory | ||
.odo | ||
*/**/.odo |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,11 +44,11 @@ func TestOdo(t *testing.T) { | |
RunSpecs(t, "odo test suite") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the suite function in a separate file to isolate it form the actual test For example: Create a file
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR is intended to provide just a clean direction and template how we can structure our tests. |
||
} | ||
|
||
var _ = BeforeSuite(func() { | ||
// Save the current project | ||
// commenting this out to resolve e2e tests failures on OC 4 | ||
// curProj = runCmdShouldPass("oc project -q") | ||
}) | ||
//var _ = BeforeSuite(func() { | ||
// Save the current project | ||
// commenting this out to resolve e2e tests failures on OC 4 | ||
// curProj = runCmdShouldPass("oc project -q") | ||
//}) | ||
|
||
func VerifyAppNameOfComponent(cmpName string, appName string) { | ||
session := runCmdShouldPass(fmt.Sprintf("oc get dc %s-%s --template={{.metadata.labels.'app'}}", cmpName, appName)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package helper | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
// CreateNewContext create new empty temporary directory | ||
func CreateNewContext() string { | ||
directory, err := ioutil.TempDir("", "") | ||
Expect(err).NotTo(HaveOccurred()) | ||
fmt.Fprintf(GinkgoWriter, "Created dir: %s\n", directory) | ||
return directory | ||
} | ||
|
||
// DeleteDir delete directory | ||
func DeleteDir(dir string) { | ||
fmt.Fprintf(GinkgoWriter, "Deleating dir: %s\n", dir) | ||
err := os.RemoveAll(dir) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
} | ||
|
||
// Chdir change current working dir | ||
func Chdir(dir string) { | ||
fmt.Fprintf(GinkgoWriter, "Setting current dir to: %s\n", dir) | ||
err := os.Chdir(dir) | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
} | ||
|
||
// Getwd retruns current working dir | ||
func Getwd() string { | ||
dir, err := os.Getwd() | ||
Expect(err).NotTo(HaveOccurred()) | ||
fmt.Fprintf(GinkgoWriter, "Current working dir: %s\n", dir) | ||
return dir | ||
} | ||
|
||
// CopyExample copies an example from tests/e2e/examples/<exampleName> into targetDir | ||
func CopyExample(exampleName string, targetDir string) { | ||
// filename of this file | ||
_, filename, _, _ := runtime.Caller(0) | ||
// path to the examples directory | ||
examplesDir := filepath.Join(filepath.Dir(filename), "..", "examples") | ||
|
||
src := filepath.Join(examplesDir, exampleName) | ||
info, err := os.Stat(src) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
err = copyDir(src, targetDir, info) | ||
Expect(err).NotTo(HaveOccurred()) | ||
} | ||
|
||
// copyDir copy one directory to the other | ||
// this function is called recursively info should start as os.Stat(src) | ||
func copyDir(src string, dst string, info os.FileInfo) error { | ||
|
||
if info.IsDir() { | ||
files, err := ioutil.ReadDir(src) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, file := range files { | ||
dsrt := filepath.Join(src, file.Name()) | ||
ddst := filepath.Join(dst, file.Name()) | ||
if err := copyDir(dsrt, ddst, file); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
if err := os.MkdirAll(filepath.Dir(dst), os.ModePerm); err != nil { | ||
return err | ||
} | ||
|
||
dFile, err := os.Create(dst) | ||
if err != nil { | ||
return err | ||
} | ||
defer dFile.Close() | ||
|
||
sFile, err := os.Open(src) | ||
if err != nil { | ||
return err | ||
} | ||
defer sFile.Close() | ||
|
||
if err = os.Chmod(dFile.Name(), info.Mode()); err != nil { | ||
return err | ||
} | ||
|
||
_, err = io.Copy(dFile, sFile) | ||
return err | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package helper | ||
|
||
import ( | ||
"math/rand" | ||
"time" | ||
) | ||
|
||
func init() { | ||
rand.Seed(time.Now().UTC().UnixNano()) | ||
} | ||
|
||
func randString(n int) string { | ||
const letterBytes = "abcdefghijklmnopqrstuvwxyz" | ||
b := make([]byte, n) | ||
for i := range b { | ||
b[i] = letterBytes[rand.Intn(len(letterBytes))] | ||
} | ||
return string(b) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package helper | ||
|
||
import ( | ||
"fmt" | ||
|
||
. "github.com/onsi/ginkgo" | ||
//. "github.com/onsi/gomega" | ||
) | ||
|
||
// CreateRandProject create new project with random name (10 letters) | ||
// without writing to the config file (without switching project) | ||
func OcCreateRandProject() string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
projectName := randString(10) | ||
fmt.Fprintf(GinkgoWriter, "Creating a new project: %s\n", projectName) | ||
CmdShouldPass(fmt.Sprintf("oc new-project %s --skip-config-write", projectName)) | ||
return projectName | ||
} | ||
|
||
// OcSwitchProject switch to the project | ||
func OcSwitchProject(project string) { | ||
CmdShouldPass(fmt.Sprintf("oc project %s ", project)) | ||
} | ||
|
||
// DeleteProject deletes a specified project | ||
func OcDeleteProject(project string) { | ||
fmt.Fprintf(GinkgoWriter, "Deleting project: %s\n", project) | ||
CmdShouldPass(fmt.Sprintf("oc delete project %s --now", project)) | ||
} | ||
|
||
// OcCurrentProject get currently active project in oc | ||
// returns empty string if there no active project, or no access to the project | ||
func OcGetCurrentProject() string { | ||
stdout, _, exitCode := cmdRunner("oc project -q") | ||
if exitCode == 0 { | ||
return stdout | ||
} | ||
return "" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1