@@ -14,7 +14,7 @@ func TestSyntheticMonitoring(t *testing.T) {
14
14
t .Run ("Check getUID is functioning correctly" , func (t * testing.T ) {
15
15
resource := grizzly.Resource {
16
16
Body : map [string ]any {
17
- "metadata" : map [string ]interface {} {
17
+ "metadata" : map [string ]any {
18
18
"name" : "test" ,
19
19
"type" : "http" ,
20
20
},
@@ -28,6 +28,70 @@ func TestSyntheticMonitoring(t *testing.T) {
28
28
})
29
29
}
30
30
31
+ func TestSyntheticMonitoringPrepare (t * testing.T ) {
32
+ handler := NewSyntheticMonitoringHandler (nil )
33
+
34
+ t .Run ("job is copied from name if not set" , func (t * testing.T ) {
35
+ resource := grizzly.Resource {
36
+ Body : map [string ]any {
37
+ "metadata" : map [string ]any {
38
+ "name" : "test" ,
39
+ "type" : "http" ,
40
+ },
41
+ "spec" : map [string ]any {},
42
+ },
43
+ }
44
+ handler .Prepare (nil , resource )
45
+
46
+ require .Equal (t , "test" , resource .GetSpecValue ("job" ))
47
+ })
48
+
49
+ t .Run ("job is left untouched if set" , func (t * testing.T ) {
50
+ resource := grizzly.Resource {
51
+ Body : map [string ]any {
52
+ "metadata" : map [string ]any {
53
+ "name" : "test" ,
54
+ "type" : "http" ,
55
+ },
56
+ "spec" : map [string ]any {
57
+ "job" : "foo" ,
58
+ },
59
+ },
60
+ }
61
+ handler .Prepare (nil , resource )
62
+
63
+ require .Equal (t , "foo" , resource .GetSpecValue ("job" ))
64
+ })
65
+
66
+ t .Run ("tenantId and id are set from existing resource if available" , func (t * testing.T ) {
67
+ existing := grizzly.Resource {
68
+ Body : map [string ]any {
69
+ "metadata" : map [string ]any {
70
+ "name" : "test" ,
71
+ "type" : "http" ,
72
+ },
73
+ "spec" : map [string ]any {
74
+ "id" : "id" ,
75
+ "tenantId" : "tenantId" ,
76
+ },
77
+ },
78
+ }
79
+ resource := grizzly.Resource {
80
+ Body : map [string ]any {
81
+ "metadata" : map [string ]any {
82
+ "name" : "test" ,
83
+ "type" : "http" ,
84
+ },
85
+ "spec" : map [string ]any {},
86
+ },
87
+ }
88
+ handler .Prepare (& existing , resource )
89
+
90
+ require .Equal (t , "id" , resource .GetSpecValue ("id" ))
91
+ require .Equal (t , "tenantId" , resource .GetSpecValue ("tenantId" ))
92
+ })
93
+ }
94
+
31
95
func TestSyntheticMonitoringCheckUID (t * testing.T ) {
32
96
testCases := []struct {
33
97
name string
0 commit comments