This repository has been archived by the owner on Jan 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add integration tests for global configuration (#346)
* test: Add integration tests for global configuration Signed-off-by: Raphael Ludwig <raphael.ludwig@dynatrace.com> * chore: Make reviewdog happy Signed-off-by: Raphael Ludwig <raphael.ludwig@dynatrace.com> Signed-off-by: Raphael Ludwig <raphael.ludwig@dynatrace.com>
- Loading branch information
Showing
8 changed files
with
194 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: v2 | ||
actions: | ||
- name: "Hello World e2e test" | ||
events: | ||
- name: "sh.keptn.event.deployment.triggered" | ||
tasks: | ||
- name: "Greet the world" | ||
image: "alpine" | ||
cmd: | ||
- echo | ||
args: | ||
- "Hello World" |
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,12 @@ | ||
apiVersion: v2 | ||
actions: | ||
- name: "Hello World e2e test" | ||
events: | ||
- name: "sh.keptn.event.deployment.triggered" | ||
tasks: | ||
- name: "Greet the world" | ||
image: "alpine" | ||
cmd: | ||
- echo | ||
args: | ||
- "Hallo Welt" |
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,12 @@ | ||
apiVersion: v2 | ||
actions: | ||
- name: "Hello World e2e test" | ||
events: | ||
- name: "sh.keptn.event.deployment.triggered" | ||
tasks: | ||
- name: "Greet the world" | ||
image: "alpine" | ||
cmd: | ||
- echo | ||
args: | ||
- "Buon Giorno" |
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,111 @@ | ||
package e2e | ||
|
||
import ( | ||
"github.com/keptn/go-utils/pkg/api/models" | ||
api "github.com/keptn/go-utils/pkg/api/utils" | ||
"github.com/stretchr/testify/require" | ||
"os" | ||
"strings" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestJobConfig(t *testing.T) { | ||
if !isE2ETestingAllowed() { | ||
t.Skipf("Skipping %s, not allowed by environment", t.Name()) | ||
} | ||
|
||
/* const */ | ||
var jobConfigURI = "job/config.yaml" | ||
|
||
testEnv, err := newTestEnvironment( | ||
"../events/e2e/jobconfig.dev-1.triggered.json", | ||
"../shipyard/e2e/jobconfig.deployment.yaml", | ||
"../data/e2e/jobconfig.service-1.config.yaml", | ||
) | ||
|
||
require.NoError(t, err) | ||
|
||
err = testEnv.SetupTestEnvironment() | ||
require.NoError(t, err) | ||
|
||
// Make sure project is delete after the tests are completed | ||
defer testEnv.Cleanup() | ||
|
||
// Upload the stage configuration | ||
stageConfig, err := os.ReadFile("../data/e2e/jobconfig.stage-dev.config.yaml") | ||
require.NoError(t, err) | ||
|
||
stageScope := api.NewResourceScope() | ||
stageScope.Project(testEnv.EventData.Project) | ||
stageScope.Stage("dev") | ||
|
||
_, err = testEnv.API.ResourceHandler.CreateResource([]*models.Resource{ | ||
{ | ||
ResourceContent: string(stageConfig), | ||
ResourceURI: &jobConfigURI, | ||
}, | ||
}, *stageScope) | ||
require.NoError(t, err) | ||
|
||
// Upload the project configuration | ||
projectConfig, err := os.ReadFile("../data/e2e/jobconfig.project.config.yaml") | ||
require.NoError(t, err) | ||
|
||
projectScope := api.NewResourceScope() | ||
projectScope.Project(testEnv.EventData.Project) | ||
|
||
_, err = testEnv.API.ResourceHandler.CreateResource([]*models.Resource{ | ||
{ | ||
ResourceContent: string(projectConfig), | ||
ResourceURI: &jobConfigURI, | ||
}, | ||
}, *projectScope) | ||
require.NoError(t, err) | ||
|
||
tests := []struct { | ||
Name string | ||
Event string | ||
ExpectedResult string | ||
}{ | ||
{ | ||
Name: "Service job configuration", | ||
Event: "../events/e2e/jobconfig.dev-1.triggered.json", | ||
ExpectedResult: "Hallo Welt", | ||
}, | ||
{ | ||
Name: "Stage job configuration", | ||
Event: "../events/e2e/jobconfig.dev-2.triggered.json", | ||
ExpectedResult: "Buon Giorno", | ||
}, | ||
{ | ||
Name: "Project job configuration", | ||
Event: "../events/e2e/jobconfig.prod.triggered.json", | ||
ExpectedResult: "Hello World", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.Name, func(t *testing.T) { | ||
keptnEvent, err := readKeptnContextExtendedCE(test.Event) | ||
require.NoError(t, err) | ||
|
||
keptnContext, err := testEnv.API.SendEvent(keptnEvent) | ||
require.NoError(t, err) | ||
|
||
requireWaitForEvent(t, | ||
testEnv.API, | ||
1*time.Minute, | ||
1*time.Second, | ||
keptnContext, | ||
"sh.keptn.event.deployment.finished", | ||
func(event *models.KeptnContextExtendedCE) bool { | ||
responseEventData, err := parseKeptnEventData(event) | ||
require.NoError(t, err) | ||
|
||
return strings.Contains(responseEventData.Message, test.ExpectedResult) | ||
}, | ||
) | ||
}) | ||
} | ||
} |
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,10 @@ | ||
{ | ||
"data": { | ||
"project": "e2e-project", | ||
"service": "service-1", | ||
"stage": "dev" | ||
}, | ||
"source": "e2e-test", | ||
"specversion": "1.0", | ||
"type": "sh.keptn.event.dev.jes.triggered" | ||
} |
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,10 @@ | ||
{ | ||
"data": { | ||
"project": "e2e-project", | ||
"service": "service-2", | ||
"stage": "dev" | ||
}, | ||
"source": "e2e-test", | ||
"specversion": "1.0", | ||
"type": "sh.keptn.event.dev.jes.triggered" | ||
} |
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,10 @@ | ||
{ | ||
"data": { | ||
"project": "e2e-project", | ||
"service": "service-1", | ||
"stage": "prod" | ||
}, | ||
"source": "e2e-test", | ||
"specversion": "1.0", | ||
"type": "sh.keptn.event.prod.jes.triggered" | ||
} |
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,17 @@ | ||
apiVersion: "spec.keptn.sh/0.2.2" | ||
kind: "Shipyard" | ||
metadata: | ||
name: "e2e-deployment-shipyard" | ||
spec: | ||
stages: | ||
- name: "dev" | ||
sequences: | ||
- name: "jes" | ||
tasks: | ||
- name: "deployment" | ||
|
||
- name: "prod" | ||
sequences: | ||
- name: "jes" | ||
tasks: | ||
- name: "deployment" |