@@ -19,26 +19,25 @@ var update = flag.Bool("update", false, "update golden files")
1919func TestRender (t * testing.T ) {
2020 tests := []struct {
2121 name string
22- isGithub bool
2322 maxCommentSize int
2423 data Data
2524 goldenFile string
2625 }{
2726 {
2827 name : "minimal_empty" ,
29- isGithub : true ,
3028 maxCommentSize : 65000 ,
3129 data : Data {
30+ IsGithubApp : true ,
3231 Currency : "USD" ,
3332 TotalMonthlyCost : rat .Zero ,
3433 },
3534 goldenFile : "minimal_empty.md" ,
3635 },
3736 {
3837 name : "cost_increase" ,
39- isGithub : true ,
4038 maxCommentSize : 65000 ,
4139 data : Data {
40+ IsGithubApp : true ,
4241 Currency : "USD" ,
4342 TotalMonthlyCost : rat .New (250 ),
4443 PastTotalMonthlyCost : rat .New (200 ),
@@ -120,9 +119,9 @@ func TestRender(t *testing.T) {
120119 },
121120 {
122121 name : "project_errors" ,
123- isGithub : true ,
124122 maxCommentSize : 65000 ,
125123 data : Data {
124+ IsGithubApp : true ,
126125 Currency : "USD" ,
127126 TotalMonthlyCost : rat .Zero ,
128127 Projects : []ProjectResult {
@@ -145,9 +144,9 @@ func TestRender(t *testing.T) {
145144 },
146145 {
147146 name : "governance_finops" ,
148- isGithub : true ,
149147 maxCommentSize : 65000 ,
150148 data : Data {
149+ IsGithubApp : true ,
151150 Currency : "USD" ,
152151 TotalMonthlyCost : rat .New (100 ),
153152 RepoURL : "https://github.com/my-org/my-repo" ,
@@ -178,7 +177,6 @@ func TestRender(t *testing.T) {
178177 },
179178 {
180179 name : "fixed_issues" ,
181- isGithub : false ,
182180 maxCommentSize : 140000 ,
183181 data : Data {
184182 Currency : "USD" ,
@@ -207,9 +205,9 @@ func TestRender(t *testing.T) {
207205 },
208206 {
209207 name : "preexisting_issues" ,
210- isGithub : true ,
211208 maxCommentSize : 65000 ,
212209 data : Data {
210+ IsGithubApp : true ,
213211 Currency : "USD" ,
214212 TotalMonthlyCost : rat .New (100 ),
215213 OrgSlug : "my-org" ,
@@ -242,15 +240,61 @@ func TestRender(t *testing.T) {
242240 },
243241 goldenFile : "preexisting_issues.md" ,
244242 },
243+ {
244+ name : "mixed_preexisting_and_new_issues" ,
245+ maxCommentSize : 65000 ,
246+ data : Data {
247+ IsGithubApp : true ,
248+ Currency : "USD" ,
249+ TotalMonthlyCost : rat .New (200 ),
250+ RepoURL : "https://github.com/my-org/my-repo" ,
251+ CommitSHA : "abc123" ,
252+ PreviousFinOpsPolicyResults : []* provider.FinopsPolicyResult {
253+ {
254+ PolicySlug : "use-gp3" ,
255+ PolicyName : "Use GP3 volumes" ,
256+ IncludeInPullRequestComment : true ,
257+ FailingResources : []* provider.FinopsPolicyFailingResource {
258+ {Id : "aws_ebs_volume.old" },
259+ },
260+ },
261+ },
262+ FinOpsPolicyResults : []* provider.FinopsPolicyResult {
263+ {
264+ PolicySlug : "use-gp3" ,
265+ PolicyName : "Use GP3 volumes" ,
266+ PolicyMessage : "Use GP3 volumes instead of GP2 for better performance." ,
267+ IncludeInPullRequestComment : true ,
268+ FailingResources : []* provider.FinopsPolicyFailingResource {
269+ {
270+ Id : "aws_ebs_volume.old" ,
271+ CauseAddress : "aws_ebs_volume.old" ,
272+ Issues : []* provider.FinopsResourceIssue {
273+ {Description : "This volume uses GP2, consider upgrading to GP3" },
274+ },
275+ },
276+ {
277+ Id : "aws_ebs_volume.new" ,
278+ CauseAddress : "aws_ebs_volume.new" ,
279+ Issues : []* provider.FinopsResourceIssue {
280+ {Description : "This volume uses GP2, consider upgrading to GP3" },
281+ },
282+ },
283+ },
284+ },
285+ },
286+ },
287+ goldenFile : "mixed_preexisting_and_new_issues.md" ,
288+ },
245289 {
246290 name : "guardrail_blocks" ,
247- isGithub : true ,
248291 maxCommentSize : 65000 ,
249292 data : Data {
293+ IsGithubApp : true ,
250294 Currency : "USD" ,
251295 TotalMonthlyCost : rat .New (500 ),
252296 PastTotalMonthlyCost : rat .New (100 ),
253- GuardrailResults : []* event.GuardrailResult {
297+ GuardrailResults : []event.GuardrailResult {
254298 {
255299 GuardrailID : "guardrail-1" ,
256300 GuardrailName : "Cost increase > $100" ,
@@ -299,9 +343,9 @@ func TestRender(t *testing.T) {
299343 },
300344 {
301345 name : "environmental_metrics" ,
302- isGithub : true ,
303346 maxCommentSize : 65000 ,
304347 data : Data {
348+ IsGithubApp : true ,
305349 EnableEnvironmentalMetrics : true ,
306350 Currency : "USD" ,
307351 TotalMonthlyCost : rat .New (300 ),
@@ -365,14 +409,14 @@ func TestRender(t *testing.T) {
365409 },
366410 {
367411 name : "governance_tagging" ,
368- isGithub : true ,
369412 maxCommentSize : 65000 ,
370413 data : Data {
414+ IsGithubApp : true ,
371415 Currency : "USD" ,
372416 TotalMonthlyCost : rat .New (100 ),
373417 RepoURL : "https://github.com/my-org/my-repo" ,
374418 CommitSHA : "abc123" ,
375- TaggingPolicyResults : []* event.TaggingPolicyResult {
419+ TaggingPolicyResults : []event.TaggingPolicyResult {
376420 {
377421 Name : "Require env tag" ,
378422 TagPolicyID : "tp-1" ,
@@ -404,7 +448,6 @@ func TestRender(t *testing.T) {
404448 },
405449 {
406450 name : "rich_cost_details" ,
407- isGithub : false ,
408451 maxCommentSize : 65000 ,
409452 data : Data {
410453 Currency : "EUR" ,
@@ -542,9 +585,9 @@ func TestRender(t *testing.T) {
542585 },
543586 {
544587 name : "truncated_cost_details" ,
545- isGithub : true ,
546588 maxCommentSize : 2800 ,
547589 data : Data {
590+ IsGithubApp : true ,
548591 Currency : "USD" ,
549592 TotalMonthlyCost : rat .New (1000 ),
550593 PastTotalMonthlyCost : rat .New (500 ),
@@ -625,7 +668,7 @@ func TestRender(t *testing.T) {
625668
626669 for _ , tt := range tests {
627670 t .Run (tt .name , func (t * testing.T ) {
628- got , err := Render (DefaultTemplate , tt .isGithub , tt . maxCommentSize , tt .data )
671+ got , err := Render (DefaultTemplate , tt .maxCommentSize , tt .data )
629672 if err != nil {
630673 t .Fatalf ("Render() error: %v" , err )
631674 }
0 commit comments