Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
test: Add integration tests for global configuration (#346)
Browse files Browse the repository at this point in the history
* 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
Raffy23 authored Aug 16, 2022
1 parent e9aefac commit cab59f0
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/data/e2e/jobconfig.project.config.yaml
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"
12 changes: 12 additions & 0 deletions test/data/e2e/jobconfig.service-1.config.yaml
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"
12 changes: 12 additions & 0 deletions test/data/e2e/jobconfig.stage-dev.config.yaml
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"
111 changes: 111 additions & 0 deletions test/e2e/jobconfig_test.go
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)
},
)
})
}
}
10 changes: 10 additions & 0 deletions test/events/e2e/jobconfig.dev-1.triggered.json
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"
}
10 changes: 10 additions & 0 deletions test/events/e2e/jobconfig.dev-2.triggered.json
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"
}
10 changes: 10 additions & 0 deletions test/events/e2e/jobconfig.prod.triggered.json
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"
}
17 changes: 17 additions & 0 deletions test/shipyard/e2e/jobconfig.deployment.yaml
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"

0 comments on commit cab59f0

Please sign in to comment.