Skip to content

test/e2e/memcached_test.go: make tests work on forks #864

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

Merged
merged 3 commits into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
# Build and test go
- <<: *test
name: Go on OpenShift
script: make test/ci-go
script: make test/ci-go ARGS="-v"

# Build and test ansible
- <<: *test
Expand Down
20 changes: 13 additions & 7 deletions test/e2e/memcached_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,16 @@ func TestMemcached(t *testing.T) {
ctx.AddCleanupFn(func() error { return os.RemoveAll(absProjectPath) })

os.Chdir("memcached-operator")
prSlug, ok := os.LookupEnv("TRAVIS_PULL_REQUEST_SLUG")
if ok && prSlug != "" {
prSha, ok := os.LookupEnv("TRAVIS_PULL_REQUEST_SHA")
if ok && prSha != "" {
repo, ok := os.LookupEnv("TRAVIS_PULL_REQUEST_SLUG")
if repo == "" {
repo, ok = os.LookupEnv("TRAVIS_REPO_SLUG")
}
if ok && repo != "" && repo != "operator-framework/operator-sdk" {
commitSha, ok := os.LookupEnv("TRAVIS_PULL_REQUEST_SHA")
if commitSha == "" {
commitSha, ok = os.LookupEnv("TRAVIS_COMMIT")
}
if ok && commitSha != "" {
gopkg, err := ioutil.ReadFile("Gopkg.toml")
if err != nil {
t.Fatal(err)
Expand All @@ -111,7 +117,7 @@ func TestMemcached(t *testing.T) {
// correctly.
gopkgString := string(gopkg)
gopkgLoc := strings.LastIndex(gopkgString, "\n name = \"github.com/operator-framework/operator-sdk\"\n")
gopkgString = gopkgString[:gopkgLoc] + "\n source = \"https://github.com/" + prSlug + "\"\n revision = \"" + prSha + "\"\n" + gopkgString[gopkgLoc+1:]
gopkgString = gopkgString[:gopkgLoc] + "\n source = \"https://github.com/" + repo + "\"\n revision = \"" + commitSha + "\"\n" + gopkgString[gopkgLoc+1:]
err = ioutil.WriteFile("Gopkg.toml", []byte(gopkgString), fileutil.DefaultFileMode)
if err != nil {
t.Fatalf("failed to write updated Gopkg.toml: %v", err)
Expand All @@ -124,7 +130,7 @@ func TestMemcached(t *testing.T) {
}
cmdOut, err = exec.Command("dep", "ensure").CombinedOutput()
if err != nil {
t.Fatalf("error: %v\nCommand Output: %s\n", err, string(cmdOut))
t.Fatalf("error after modifying Gopkg.toml: %v\nCommand Output: %s\n", err, string(cmdOut))
}

// Set replicas to 2 to test leader election. In production, this should
Expand Down Expand Up @@ -217,7 +223,7 @@ func TestMemcached(t *testing.T) {
t.Fatalf("dep ensure failed: %v\nCommand Output:\n%v", err, string(cmdOut))
}
// link local sdk to vendor if not in travis
if prSlug == "" {
if repo == "" {
os.RemoveAll("vendor/github.com/operator-framework/operator-sdk/pkg")
os.Symlink(filepath.Join(gopath, "src/github.com/operator-framework/operator-sdk/pkg"),
"vendor/github.com/operator-framework/operator-sdk/pkg")
Expand Down