File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -191,7 +191,7 @@ func setupTemplateReport(r *Report) {
191
191
// report with template output will only have access to ReportTemplateSpec.
192
192
// This function reverts parsedMetadata.String()
193
193
func (t * ReportTemplateSpec ) loadFromKey (key string ) error {
194
- pattern := regexp .MustCompile (`(?P<namespace>[a-z0-9-]+), (?P<name>[a-z0-9-]+), (?P<kind>\w+) \((?P<api>[a-z0-9. ]+)\)` )
194
+ pattern := regexp .MustCompile (`(?P<namespace>[a-z0-9-]+), (?P<name>[a-z0-9. -]+), (?P<kind>\w+) \((?P<api>[^) ]+)\)` )
195
195
matches := pattern .FindStringSubmatch (key )
196
196
if len (matches ) > 1 {
197
197
t .Namespace = matches [1 ]
Original file line number Diff line number Diff line change
1
+ package diff
2
+
3
+ import (
4
+ "testing"
5
+
6
+ "github.com/stretchr/testify/require"
7
+ )
8
+
9
+ func TestLoadFromKey (t * testing.T ) {
10
+ keyToReportTemplateSpec := map [string ]ReportTemplateSpec {
11
+ "default, nginx, Deployment (apps)" : {
12
+ Namespace : "default" ,
13
+ Name : "nginx" ,
14
+ Kind : "Deployment" ,
15
+ API : "apps" ,
16
+ },
17
+ "default, probes.monitoring.coreos.com, CustomResourceDefinition (apiextensions.k8s.io)" : {
18
+ Namespace : "default" ,
19
+ Name : "probes.monitoring.coreos.com" ,
20
+ Kind : "CustomResourceDefinition" ,
21
+ API : "apiextensions.k8s.io" ,
22
+ },
23
+ "default, my-cert, Certificate (cert-manager.io/v1)" : {
24
+ Namespace : "default" ,
25
+ Name : "my-cert" ,
26
+ Kind : "Certificate" ,
27
+ API : "cert-manager.io/v1" ,
28
+ },
29
+ }
30
+
31
+ for key , expectedTemplateSpec := range keyToReportTemplateSpec {
32
+ templateSpec := & ReportTemplateSpec {}
33
+ require .NoError (t , templateSpec .loadFromKey (key ))
34
+ require .Equal (t , expectedTemplateSpec , * templateSpec )
35
+ }
36
+ }
You can’t perform that action at this time.
0 commit comments