@@ -7,21 +7,22 @@ import (
77 "testing"
88
99 "github.com/google/go-cmp/cmp"
10+ "github.com/infracost/go-proto/pkg/diagnostic"
1011 "github.com/infracost/go-proto/pkg/event"
1112 "github.com/infracost/go-proto/pkg/rat"
12- "github.com/infracost/proto/gen/go/infracost/parser"
13+ parserpb "github.com/infracost/proto/gen/go/infracost/parser"
1314 "github.com/infracost/proto/gen/go/infracost/provider"
1415)
1516
1617var update = flag .Bool ("update" , false , "update golden files" )
1718
1819func TestRender (t * testing.T ) {
1920 tests := []struct {
20- name string
21- isGithub bool
22- maxCommentSize int
23- data Data
24- goldenFile string
21+ name string
22+ isGithub bool
23+ maxCommentSize int
24+ data Data
25+ goldenFile string
2526 }{
2627 {
2728 name : "minimal_empty" ,
@@ -47,15 +48,15 @@ func TestRender(t *testing.T) {
4748 },
4849 Projects : []ProjectResult {
4950 {
50- Name : "my-project" ,
51- TotalMonthlyCost : rat .New (250 ),
52- PastTotalMonthlyCost : rat .New (200 ),
53- TotalMonthlyUsageCost : rat .New (10 ),
51+ Name : "my-project" ,
52+ TotalMonthlyCost : rat .New (250 ),
53+ PastTotalMonthlyCost : rat .New (200 ),
54+ TotalMonthlyUsageCost : rat .New (10 ),
5455 PastTotalMonthlyUsageCost : rat .New (5 ),
5556 Resources : []* provider.Resource {
5657 {
57- Name : "aws_instance.web" ,
58- Action : provider .ResourceAction_CREATE ,
58+ Name : "aws_instance.web" ,
59+ Action : provider .ResourceAction_CREATE ,
5960 IsSupported : true ,
6061 },
6162 },
@@ -127,15 +128,15 @@ func TestRender(t *testing.T) {
127128 Projects : []ProjectResult {
128129 {
129130 Name : "broken-project" ,
130- Diagnostics : []* parser .Diagnostic {
131- {Critical : true , Error : "Failed to parse: invalid HCL" },
131+ Diagnostics : []* diagnostic .Diagnostic {
132+ {Critical : true , Type : parserpb . DiagnosticType_DIAGNOSTIC_TYPE_HCL_PARSE_ERROR , Error : "Failed to parse: invalid HCL" },
132133 },
133134 },
134135 {
135136 Name : "another-broken-project" ,
136- Diagnostics : []* parser .Diagnostic {
137- {Critical : true , Error : "Module not found: ./modules/vpc" },
138- {Critical : true , Error : "Provider error: timeout" },
137+ Diagnostics : []* diagnostic .Diagnostic {
138+ {Critical : true , Type : parserpb . DiagnosticType_DIAGNOSTIC_TYPE_MODULE_FETCH_ERROR , Error : "Module not found: ./modules/vpc" },
139+ {Critical : true , Type : parserpb . DiagnosticType_DIAGNOSTIC_TYPE_INVALID_TERRAFORM_CONFIGURATION , Error : "Provider error: timeout" },
139140 },
140141 },
141142 },
@@ -251,21 +252,21 @@ func TestRender(t *testing.T) {
251252 PastTotalMonthlyCost : rat .New (100 ),
252253 GuardrailResults : []* event.GuardrailResult {
253254 {
254- GuardrailID : "guardrail-1" ,
255- GuardrailName : "Cost increase > $100" ,
256- Triggered : true ,
257- PRComment : true ,
258- BlockPR : true ,
259- Increase : rat .New (400 ),
260- PercentIncrease : rat .New (400 ),
255+ GuardrailID : "guardrail-1" ,
256+ GuardrailName : "Cost increase > $100" ,
257+ Triggered : true ,
258+ PRComment : true ,
259+ BlockPR : true ,
260+ Increase : rat .New (400 ),
261+ PercentIncrease : rat .New (400 ),
261262 TriggeringProjectNames : []string {"my-project" },
262263 },
263264 },
264265 Projects : []ProjectResult {
265266 {
266- Name : "my-project" ,
267- TotalMonthlyCost : rat .New (500 ),
268- PastTotalMonthlyCost : rat .New (100 ),
267+ Name : "my-project" ,
268+ TotalMonthlyCost : rat .New (500 ),
269+ PastTotalMonthlyCost : rat .New (100 ),
269270 Resources : []* provider.Resource {
270271 {
271272 Name : "aws_instance.big" ,
@@ -373,17 +374,17 @@ func TestRender(t *testing.T) {
373374 CommitSHA : "abc123" ,
374375 TaggingPolicyResults : []* event.TaggingPolicyResult {
375376 {
376- Name : "Require env tag" ,
377+ Name : "Require env tag" ,
377378 TagPolicyID : "tp-1" ,
378- Message : "All resources must have an env tag." ,
379- BlockPR : true ,
380- PRComment : true ,
379+ Message : "All resources must have an env tag." ,
380+ BlockPR : true ,
381+ PRComment : true ,
381382 FailingResources : []event.TagPolicyResultResource {
382383 {
383- Address : "aws_instance.web" ,
384- Path : "main.tf" ,
385- Line : 10 ,
386- ProjectNames : []string {"my-project" },
384+ Address : "aws_instance.web" ,
385+ Path : "main.tf" ,
386+ Line : 10 ,
387+ ProjectNames : []string {"my-project" },
387388 MissingMandatoryTags : []string {"env" },
388389 },
389390 {
@@ -553,9 +554,9 @@ func TestRender(t *testing.T) {
553554 },
554555 Projects : []ProjectResult {
555556 {
556- Name : "project-a" ,
557- TotalMonthlyCost : rat .New (600 ),
558- PastTotalMonthlyCost : rat .New (300 ),
557+ Name : "project-a" ,
558+ TotalMonthlyCost : rat .New (600 ),
559+ PastTotalMonthlyCost : rat .New (300 ),
559560 Resources : []* provider.Resource {
560561 {Name : "aws_instance.a" , Action : provider .ResourceAction_CREATE , IsSupported : true },
561562 },
@@ -585,9 +586,9 @@ func TestRender(t *testing.T) {
585586 },
586587 },
587588 {
588- Name : "project-b" ,
589- TotalMonthlyCost : rat .New (400 ),
590- PastTotalMonthlyCost : rat .New (200 ),
589+ Name : "project-b" ,
590+ TotalMonthlyCost : rat .New (400 ),
591+ PastTotalMonthlyCost : rat .New (200 ),
591592 Resources : []* provider.Resource {
592593 {Name : "aws_instance.b" , Action : provider .ResourceAction_MODIFY , IsSupported : true },
593594 },
@@ -648,4 +649,4 @@ func TestRender(t *testing.T) {
648649 }
649650 })
650651 }
651- }
652+ }
0 commit comments