-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* a template for a clean tests * vendor: update ginkgo,gomega,testify * e2e template: Remove Before/AfterSuite and rename file * gofmt * don't ignore .odo
- Loading branch information
1 parent
ffa2756
commit 7c81a21
Showing
400 changed files
with
15,148 additions
and
4,122 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
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.
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
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
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 | ||
} |
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 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) | ||
} |
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,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 { | ||
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 "" | ||
} |
Oops, something went wrong.