@@ -15,60 +15,60 @@ import (
1515 "github.com/DataDog/datadog-agent/pkg/privateactionrunner/types"
1616)
1717
18- func makeConnectivityTask (inputs map [string ]any ) * types.Task {
19- task := & types.Task {}
20- task .Data .Attributes = & types.Attributes {Inputs : inputs }
21- return task
22- }
23-
2418func TestConnectivityCheckHandlerRun (t * testing.T ) {
2519 cases := []struct {
26- name string
27- inputs map [string ]any
28- wantErr string
20+ name string
21+ taskInputs map [string ]any
22+ expectedResults interface {}
23+ expectedErr string
2924 }{
3025 {
3126 name : "fails when inputs are malformed" ,
32- inputs : map [string ]any {
27+ taskInputs : map [string ]any {
3328 "targetIPs" : "not-a-list" ,
3429 },
35- wantErr : "failed to parse connectivityCheck inputs" ,
30+ expectedErr : "failed to parse connectivityCheck inputs" ,
3631 },
3732 {
3833 name : "fails when ping options are missing" ,
39- inputs : map [string ]any {
34+ taskInputs : map [string ]any {
4035 "targetIPs" : []string {"10.0.0.1" },
4136 "checks" : []string {"ping" },
4237 },
43- wantErr : "failed to run connectivity checks" ,
38+ expectedErr : "failed to run connectivity checks" ,
4439 },
4540 {
4641 name : "fails when snmp options are missing" ,
47- inputs : map [string ]any {
42+ taskInputs : map [string ]any {
4843 "targetIPs" : []string {"10.0.0.1" },
4944 "checks" : []string {"snmp" },
5045 },
51- wantErr : "failed to run connectivity checks" ,
46+ expectedErr : "failed to run connectivity checks" ,
5247 },
5348 {
5449 name : "fails when secret inputs cannot be decrypted" ,
55- inputs : map [string ]any {
50+ taskInputs : map [string ]any {
5651 "targetIPs" : []string {},
5752 "checks" : []string {},
5853 "encryptedCredentials" : "not-decryptable" ,
5954 },
60- wantErr : "failed to decrypt secret inputs" ,
55+ expectedErr : "failed to decrypt secret inputs" ,
6156 },
6257 }
6358
6459 for _ , tc := range cases {
6560 t .Run (tc .name , func (t * testing.T ) {
6661 handler := NewConnectivityCheckHandler (encryptioncontext .NewStore ())
6762
68- output , err := handler .Run (context .Background (), makeConnectivityTask (tc .inputs ), nil )
69-
70- require .ErrorContains (t , err , tc .wantErr )
71- require .Nil (t , output )
63+ res , err := handler .Run (context .Background (), makeConnectivityTask (tc .taskInputs ), nil )
64+ require .Equal (t , tc .expectedResults , res )
65+ require .ErrorContains (t , err , tc .expectedErr )
7266 })
7367 }
7468}
69+
70+ func makeConnectivityTask (taskInputs map [string ]any ) * types.Task {
71+ task := & types.Task {}
72+ task .Data .Attributes = & types.Attributes {Inputs : taskInputs }
73+ return task
74+ }
0 commit comments