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

chore: Update tests for errors in get-sli.triggered handling #980

Merged
merged 1 commit into from
Dec 20, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,24 @@ func TestQueryDynatraceDashboardForSLIs(t *testing.T) {
createSuccessfulSLIResultAssertionsFunc("problems", 0, expectedProblemsV2Request),
}

runGetSLIsFromDashboardTestWithDashboardParameterAndCheckSLIsAndSLOs(t, handler, testGetSLIEventData, "query", getSLIFinishedEventSuccessAssertionsFunc, uploadedSLOsAssertionsFunc, sliResultsAssertionsFuncs...)
runGetSLIsFromDashboardTestWithDashboardParameterAndCheckSLIsAndSLOs(t, handler, testGetSLIEventData, testDashboardQuery, getSLIFinishedEventSuccessAssertionsFunc, uploadedSLOsAssertionsFunc, sliResultsAssertionsFuncs...)
}

// TestErrorWhenNothingMatchesQueryForDynatraceDashboard tests that an appropriate error is return when querying for a dashboard (i.e. dashboard=query) does not find anything.
func TestErrorWhenNothingMatchesQueryForDynatraceDashboard(t *testing.T) {
const testDataFolder = "./testdata/dashboards/basic/dashboard_query_error/"

const noDashboardNameMatches = "no dashboard name matches"

handler := test.NewFileBasedURLHandler(t)
handler.AddExact(dynatrace.DashboardsPath, filepath.Join(testDataFolder, "dashboards_query.json"))

getSLIFinishedEventAssertionsFunc := func(t *testing.T, actual *getSLIFinishedEventData) {
assert.EqualValues(t, keptnv2.ResultFailed, actual.Result)
assert.Contains(t, actual.Message, noDashboardNameMatches)
}

runGetSLIsFromDashboardTestWithDashboardParameterAndCheckSLIs(t, handler, testGetSLIEventData, testDashboardQuery, getSLIFinishedEventAssertionsFunc, createFailedSLIResultAssertionsFunc(testIndicatorNoMetric, noDashboardNameMatches))
}

// TestRetrieveDashboardWithUnknownButValidID tests requesting a dashboard with a valid but unknown ID fails as expected.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/stretchr/testify/assert"
)

const testCouldNotRetrieveSLODefinitionsSubstring = "could not retrieve SLO definitions"

// In case we do not use the dashboard for defining SLIs we can use the file 'dynatrace/sli.yaml'.
//
// prerequisites:
Expand Down Expand Up @@ -690,22 +692,29 @@ const expectedSLOResourceURI = "slo.yaml"

// TestCustomSLIsGivesErrorIfNoSLOFileExistsButIndicatorRequested tests that an error is produced if no slo.yaml file exists for a sli.yaml-based request if even indicators are requested (unlikely but possible).
func TestCustomSLIsGivesErrorIfNoSLOFileExistsButIndicatorRequested(t *testing.T) {
const testDataFolder = "./testdata/sli_files/basic/no_slo_file"

handler := test.NewCombinedURLHandler(t)
_ = addRequestsToHandlerForSuccessfulMetricsQueryWithResolutionInf(handler,
testDataFolder,
newMetricsV2QueryRequestBuilder("builtin:service.response.time:merge(\"dt.entity.service\"):percentile(95)").copyWithEntitySelector("type(SERVICE),tag(keptn_project:sockshop),tag(keptn_stage:staging)"),
)

configClient := newConfigClientMockWithSLIsThatErrorsGetSLOs(t,
map[string]string{
testIndicatorResponseTimeP95: "metricSelector=builtin:service.response.time:merge(\"dt.entity.service\"):percentile(95)&entitySelector=type(SERVICE),tag(keptn_project:sockshop),tag(keptn_stage:staging)",
},
keptn.NewResourceNotFoundError(expectedSLOResourceURI, testProject, testStage, testService),
)

runGetSLIsFromFilesTestWithOneIndicatorRequestedAndCheckSLIs(t, handler, configClient, testIndicatorResponseTimeP95, getSLIFinishedEventFailureAssertionsFunc, createFailedSLIResultAssertionsFunc(testIndicatorResponseTimeP95, "could not retrieve SLO definitions"))
runGetSLIsFromFilesTestWithOneIndicatorRequestedAndCheckSLIs(t, test.NewEmptyURLHandler(t), configClient, testIndicatorResponseTimeP95, getSLIFinishedEventFailureAssertionsFunc, createFailedSLIResultAssertionsFunc(testIndicatorResponseTimeP95, testCouldNotRetrieveSLODefinitionsSubstring))
}

// TestCustomSLIsGivesMultipleErrorsIfMultipleIndicatorsRequested tests that an error is produced if no slo.yaml file exists for a sli.yaml-based request if even indicators are requested (unlikely but possible).
func TestCustomSLIsGivesMultipleErrorsIfMultipleIndicatorsRequested(t *testing.T) {
configClient := newConfigClientMockWithSLIsThatErrorsGetSLOs(t,
map[string]string{},
keptn.NewResourceNotFoundError(expectedSLOResourceURI, testProject, testStage, testService),
)

sliResultAssertionsFuncs := []func(t *testing.T, actual sliResult){
createFailedSLIResultAssertionsFunc(testIndicatorResponseTimeP95, testCouldNotRetrieveSLODefinitionsSubstring),
createFailedSLIResultAssertionsFunc(testIndicatorStaticSLOPass, testCouldNotRetrieveSLODefinitionsSubstring),
}

runGetSLIsFromFilesTestAndCheckSLIs(t, test.NewEmptyURLHandler(t), configClient, []string{testIndicatorResponseTimeP95, testIndicatorStaticSLOPass}, getSLIFinishedEventFailureAssertionsFunc, sliResultAssertionsFuncs...)
}

// TestCustomSLIsGivesErrorIfWrongIndicatorRequested tests that no query is performed and an error is returned if an indicator is requested that has an SLI defined but not SLO objective.
Expand Down
1 change: 1 addition & 0 deletions internal/sli/test_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const testIndicatorStaticSLOPass = "static_slo_-_pass"
const testIndicatorNoMetric = "no_metric"
const testDynatraceAPIToken = "dtOc01.ST2EY72KQINMH574WMNVI7YN.G3DFPBEJYMODIDAEX454M7YWBUVEFOWKPRVMWFASS64NFH52PX6BNDVFFM572RZM"
const testDashboardID = "12345678-1111-4444-8888-123456789012"
const testDashboardQuery = "query"
const testSLIStart = "2022-09-28T00:00:00.000Z"
const testSLIEnd = "2022-09-29T00:00:00.000Z"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"dashboards": [
{
"id": "12345678-1111-4444-8888-123456789012",
"name": "some dashboard",
"owner": "anybody"
},
{
"id": "04993649-4a93-457f-991c-cc076d9fafef",
"name": "some other dashboard",
"owner": "somebodyelse"
}
]
}

This file was deleted.

Loading