Skip to content

Commit

Permalink
Add a test with a TODO.
Browse files Browse the repository at this point in the history
  • Loading branch information
preslavgerchev committed Oct 17, 2023
1 parent fd68be6 commit 979290e
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion policy/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ policies:
mql: 1 == 1
- uid: check-pass-2
mql: 2 == 2
queries:
- uid: active-query
title: test
mql: 3 == 3
- uid: policy-inactive
groups:
- filters: "false"
Expand All @@ -359,6 +363,9 @@ policies:
mql: 1 == 1
- uid: inactive-pass-2
mql: 2 == 2
queries:
- uid: inactive-query
mql: 4 == 4
frameworks:
- uid: framework1
name: framework1
Expand Down Expand Up @@ -398,6 +405,8 @@ framework_maps:
- uid: control1
checks:
- uid: check-pass-1
queries:
- uid: active-query
- uid: control2
checks:
- uid: check-pass-2
Expand Down Expand Up @@ -449,12 +458,13 @@ framework_maps:
requireUnique(t, rj.Notify)
}

require.Len(t, rp.ExecutionJob.Queries, 3)
require.Len(t, rp.ExecutionJob.Queries, 4)

rjTester := frameworkReportingJobTester{
t: t,
queryIdToReportingJob: map[string]*policy.ReportingJob{},
rjIdToReportingJob: rp.CollectorJob.ReportingJobs,
rjIdToDatapointJob: rp.CollectorJob.Datapoints,
}

for _, rj := range rjTester.rjIdToReportingJob {
Expand All @@ -470,6 +480,10 @@ framework_maps:
rjTester.requireReportsTo(mrnToQueryId[queryMrn("check-pass-2")], queryMrn("check-pass-2"))
rjTester.requireReportsTo(mrnToQueryId[queryMrn("check-fail")], queryMrn("check-fail"))

// TODO: how do we get a datapoint here so we can assert this more strictly?
control1 := rjTester.queryIdToReportingJob[controlMrn("control1")]
require.Equal(t, 1, len(control1.Datapoints))

rjTester.requireReportsTo(queryMrn("check-pass-1"), controlMrn("control1"))
rjTester.requireReportsTo(queryMrn("check-pass-2"), controlMrn("control2"))
rjTester.requireReportsTo(queryMrn("check-fail"), controlMrn("control2"))
Expand All @@ -485,6 +499,8 @@ framework_maps:
require.Nil(t, rjTester.queryIdToReportingJob[queryMrn("inactive-fail")])
require.Nil(t, rjTester.queryIdToReportingJob[queryMrn("inactive-pass")])
require.Nil(t, rjTester.queryIdToReportingJob[queryMrn("inactive-pass-2")])
require.Nil(t, rjTester.queryIdToReportingJob[queryMrn("inactive-query")])
require.Nil(t, rjTester.queryIdToReportingJob[queryMrn("active-query")])
})

t.Run("test checksumming", func(t *testing.T) {
Expand Down Expand Up @@ -522,6 +538,7 @@ framework_maps:
type frameworkReportingJobTester struct {
t *testing.T
queryIdToReportingJob map[string]*policy.ReportingJob
rjIdToDatapointJob map[string]*policy.DataQueryInfo
rjIdToReportingJob map[string]*policy.ReportingJob
}

Expand Down Expand Up @@ -575,6 +592,17 @@ func (tester *frameworkReportingJobTester) requireReportsTo(childQueryId string,
}
}

func (tester *frameworkReportingJobTester) requireHasADatapoint(parentQueryId string, childId string) {
tester.t.Helper()

_, ok := tester.rjIdToDatapointJob[childId]
require.True(tester.t, ok)
parentRj, ok := tester.queryIdToReportingJob[parentQueryId]
require.True(tester.t, ok)

require.True(tester.t, parentRj.Datapoints[childId])
}

func TestResolve_CheckValidUntil(t *testing.T) {
stillValid := policy.CheckValidUntil(time.Now().Format(time.RFC3339), "test123")
require.False(t, stillValid)
Expand Down

0 comments on commit 979290e

Please sign in to comment.