@@ -15,17 +15,80 @@ import (
1515)
1616
1717func TestLoadMetadataForAgents (t * testing.T ) {
18- t .Setenv ("INPUT_AGENT_TYPE" , "myagenttype" )
19- t .Setenv ("INPUT_VERSION" , "1.2.3" )
20-
21- metadata := LoadMetadataForAgents ("1.2.3" )
22- assert .Equal (t , "1.2.3" , metadata ["version" ])
23- assert .Empty (t , metadata ["features" ])
24- assert .Empty (t , metadata ["bugs" ])
25- assert .Empty (t , metadata ["security" ])
26- assert .Empty (t , metadata ["deprecations" ])
27- assert .Empty (t , metadata ["supportedOperatingSystems" ])
28- assert .Empty (t , metadata ["eol" ])
18+ tests := []struct {
19+ name string
20+ version string
21+ monitoringType string
22+ expectMonitoringType bool
23+ expectedMonitoringVal string
24+ }{
25+ {
26+ name : "no monitoringType - only version key present" ,
27+ version : "1.2.3" ,
28+ monitoringType : "" ,
29+ expectMonitoringType : false ,
30+ },
31+ {
32+ name : "APM monitoringType" ,
33+ version : "1.2.3" ,
34+ monitoringType : "APM" ,
35+ expectMonitoringType : true ,
36+ expectedMonitoringVal : "APM" ,
37+ },
38+ {
39+ name : "INFRA monitoringType" ,
40+ version : "1.2.3" ,
41+ monitoringType : "INFRA" ,
42+ expectMonitoringType : true ,
43+ expectedMonitoringVal : "INFRA" ,
44+ },
45+ }
46+
47+ for _ , tt := range tests {
48+ t .Run (tt .name , func (t * testing.T ) {
49+ t .Setenv ("INPUT_MONITORING_TYPE" , tt .monitoringType )
50+ metadata := LoadMetadataForAgents (tt .version )
51+ assert .Equal (t , tt .version , metadata ["version" ])
52+ if tt .expectMonitoringType {
53+ assert .Equal (t , tt .expectedMonitoringVal , metadata ["monitoringType" ])
54+ } else {
55+ assert .NotContains (t , metadata , "monitoringType" )
56+ }
57+ })
58+ }
59+ }
60+
61+ func TestLoadMetadataForAgents_DisplayName (t * testing.T ) {
62+ tests := []struct {
63+ name string
64+ displayName string
65+ expectKey bool
66+ expectedVal string
67+ }{
68+ {
69+ name : "no displayName - key absent" ,
70+ displayName : "" ,
71+ expectKey : false ,
72+ },
73+ {
74+ name : "displayName set" ,
75+ displayName : "Java Agent" ,
76+ expectKey : true ,
77+ expectedVal : "Java Agent" ,
78+ },
79+ }
80+
81+ for _ , tt := range tests {
82+ t .Run (tt .name , func (t * testing.T ) {
83+ t .Setenv ("INPUT_DISPLAY_NAME" , tt .displayName )
84+ metadata := LoadMetadataForAgents ("1.2.3" )
85+ if tt .expectKey {
86+ assert .Equal (t , tt .expectedVal , metadata ["displayName" ])
87+ } else {
88+ assert .NotContains (t , metadata , "displayName" )
89+ }
90+ })
91+ }
2992}
3093
3194func TestLoadMetadata_WithMDXFiles_Success (t * testing.T ) {
0 commit comments