Skip to content

Commit

Permalink
test: fix interop test when running on CI push event. (#1892)
Browse files Browse the repository at this point in the history
## What this PR does / why we need it:

When interop tests run on `push` event, the `GITHUB_EVENT_FILE` needs to
be mocked or else previews cannot be created.

## Which issue(s) this PR fixes:

Internal CIs.

## Special notes for your reviewer:

## Does this PR introduce a user-facing change?
```
no
```
  • Loading branch information
i4ki authored Sep 27, 2024
2 parents 7df5a19 + 5c68981 commit 81e0a60
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions e2etests/cloud/interop/interoperability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package interop_test

import (
"encoding/json"
"fmt"
"os"
"path"
Expand All @@ -26,9 +27,23 @@ func TestInteropCloudSyncPreview(t *testing.T) {
} {
t.Run("preview: "+path.Base(stackpath), func(t *testing.T) {
env := os.Environ()
if os.Getenv("GITHUB_EVENT_PATH") == "" {
env = append(env, fmt.Sprintf("GITHUB_EVENT_PATH=%s", datapath(t, "testdata/event_pull_request.json")))

eventFile := os.Getenv("GITHUB_EVENT_PATH")
if eventFile != "" {
// check if exported GITHUB_EVENT_FILE is of type `pull_request`
var obj map[string]interface{}
content, err := os.ReadFile(eventFile)
assert.NoError(t, err)
assert.NoError(t, json.Unmarshal(content, &obj))
if obj["pull_request"] == nil {
eventFile = ""
}
}
if eventFile == "" {
eventFile = datapath(t, "testdata/event_pull_request.json")
env = append(env, fmt.Sprintf("GITHUB_EVENT_PATH=%s", eventFile))
}
t.Logf("using GITHUB_EVENT_FILE=%s", eventFile)
env = append(env, "GITHUB_ACTIONS=1")
tmcli := NewInteropCLI(t, datapath(t, stackpath), env...)
AssertRunResult(t,
Expand Down

0 comments on commit 81e0a60

Please sign in to comment.