@@ -43,90 +43,68 @@ func (m *mockResolvedResource) RefSource() *v1.RefSource {
4343}
4444
4545func TestNewAnnotatedResource (t * testing.T ) {
46- tests := []struct {
47- name string
48- resolverType string
49- hasExisting bool
50- }{
51- {
52- name : "with existing annotations" ,
53- resolverType : "bundles" ,
54- hasExisting : true ,
55- },
56- {
57- name : "without existing annotations" ,
58- resolverType : "git" ,
59- hasExisting : false ,
46+ // Create mock resource with existing annotations to test preservation
47+ mockAnnotations := map [string ]string {
48+ "existing-key" : "existing-value" ,
49+ }
50+
51+ mockResource := & mockResolvedResource {
52+ data : []byte ("test data" ),
53+ annotations : mockAnnotations ,
54+ refSource : & v1.RefSource {
55+ URI : "test-uri" ,
6056 },
6157 }
6258
63- for _ , tt := range tests {
64- t .Run (tt .name , func (t * testing.T ) {
65- // Create mock resource
66- mockAnnotations := make (map [string ]string )
67- if tt .hasExisting {
68- mockAnnotations ["existing-key" ] = "existing-value"
69- }
70-
71- mockResource := & mockResolvedResource {
72- data : []byte ("test data" ),
73- annotations : mockAnnotations ,
74- refSource : & v1.RefSource {
75- URI : "test-uri" ,
76- },
77- }
78-
79- // Create fake clock with fixed time for deterministic testing
80- fixedTime := time .Date (2025 , 1 , 15 , 10 , 30 , 0 , 0 , time .UTC )
81- fc := & fakeClock {now : fixedTime }
82-
83- // Create annotated resource
84- annotated := newAnnotatedResource (mockResource , tt .resolverType , cacheOperationStore , fc )
85-
86- // Verify data is preserved
87- if string (annotated .Data ()) != "test data" {
88- t .Errorf ("Expected data 'test data', got '%s'" , string (annotated .Data ()))
89- }
90-
91- // Verify annotations are added
92- annotations := annotated .Annotations ()
93- if annotations [cacheAnnotationKey ] != "true" {
94- t .Errorf ("Expected cache annotation to be 'true', got '%s'" , annotations [cacheAnnotationKey ])
95- }
96-
97- if annotations [cacheResolverTypeKey ] != tt .resolverType {
98- t .Errorf ("Expected resolver type '%s', got '%s'" , tt .resolverType , annotations [cacheResolverTypeKey ])
99- }
100-
101- // Verify timestamp is as expected
102- expectedTimestamp := fixedTime .Format (time .RFC3339 )
103- timestamp := annotations [cacheTimestampKey ]
104- if timestamp != expectedTimestamp {
105- t .Errorf ("Expected cache timestamp to be %s, got %s" , expectedTimestamp , timestamp )
106- }
107-
108- // Verify timestamp is valid RFC3339 format
109- _ , err := time .Parse (time .RFC3339 , timestamp )
110- if err != nil {
111- t .Errorf ("Expected valid RFC3339 timestamp, got error: %v" , err )
112- }
113-
114- // Verify cache operation is set
115- if annotations [cacheOperationKey ] != cacheOperationStore {
116- t .Errorf ("Expected cache operation '%s', got '%s'" , cacheOperationStore , annotations [cacheOperationKey ])
117- }
118-
119- // Verify existing annotations are preserved
120- if tt .hasExisting {
121- if annotations ["existing-key" ] != "existing-value" {
122- t .Errorf ("Expected existing annotation to be preserved, got '%s'" , annotations ["existing-key" ])
123- }
124- }
125-
126- // Verify RefSource is preserved
127- if annotated .RefSource ().URI != "test-uri" {
128- t .Errorf ("Expected RefSource URI 'test-uri', got '%s'" , annotated .RefSource ().URI )
129- }
130- })
59+ // Create fake clock with fixed time for deterministic testing
60+ fixedTime := time .Date (2025 , 1 , 15 , 10 , 30 , 0 , 0 , time .UTC )
61+ fc := & fakeClock {now : fixedTime }
62+
63+ resolverType := "bundles"
64+
65+ // Create annotated resource
66+ annotated := newAnnotatedResource (mockResource , resolverType , cacheOperationStore , fc )
67+
68+ // Verify data is preserved
69+ if string (annotated .Data ()) != "test data" {
70+ t .Errorf ("Expected data 'test data', got '%s'" , string (annotated .Data ()))
71+ }
72+
73+ // Verify annotations are added
74+ annotations := annotated .Annotations ()
75+ if annotations [cacheAnnotationKey ] != "true" {
76+ t .Errorf ("Expected cache annotation to be 'true', got '%s'" , annotations [cacheAnnotationKey ])
77+ }
78+
79+ if annotations [cacheResolverTypeKey ] != resolverType {
80+ t .Errorf ("Expected resolver type '%s', got '%s'" , resolverType , annotations [cacheResolverTypeKey ])
81+ }
82+
83+ // Verify timestamp is as expected
84+ expectedTimestamp := fixedTime .Format (time .RFC3339 )
85+ timestamp := annotations [cacheTimestampKey ]
86+ if timestamp != expectedTimestamp {
87+ t .Errorf ("Expected cache timestamp to be %s, got %s" , expectedTimestamp , timestamp )
88+ }
89+
90+ // Verify timestamp is valid RFC3339 format
91+ _ , err := time .Parse (time .RFC3339 , timestamp )
92+ if err != nil {
93+ t .Errorf ("Expected valid RFC3339 timestamp, got error: %v" , err )
94+ }
95+
96+ // Verify cache operation is set
97+ if annotations [cacheOperationKey ] != cacheOperationStore {
98+ t .Errorf ("Expected cache operation '%s', got '%s'" , cacheOperationStore , annotations [cacheOperationKey ])
99+ }
100+
101+ // Verify existing annotations are preserved
102+ if annotations ["existing-key" ] != "existing-value" {
103+ t .Errorf ("Expected existing annotation to be preserved, got '%s'" , annotations ["existing-key" ])
104+ }
105+
106+ // Verify RefSource is preserved
107+ if annotated .RefSource ().URI != "test-uri" {
108+ t .Errorf ("Expected RefSource URI 'test-uri', got '%s'" , annotated .RefSource ().URI )
131109 }
132110}
0 commit comments