Skip to content

Commit cdea16b

Browse files
authored
Merge pull request #171 from cloudskiff/hotfix/multiple_alert_computed
hotfix for multiple computed alert being send
2 parents 97f992a + 95777b4 commit cdea16b

2 files changed

Lines changed: 209 additions & 6 deletions

File tree

pkg/analyser/analyzer.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,13 @@ func (a Analyzer) Analyze(remoteResources, resourcesFromState []resource.Resourc
7575
})
7676
}
7777
}
78-
if haveComputedDiff {
79-
a.alerter.SendAlert("",
80-
alerter.Alert{
81-
Message: "You have diffs on computed fields, check the documentation for potential false positive drifts",
82-
})
83-
}
78+
}
79+
80+
if haveComputedDiff {
81+
a.alerter.SendAlert("",
82+
alerter.Alert{
83+
Message: "You have diffs on computed fields, check the documentation for potential false positive drifts",
84+
})
8485
}
8586

8687
// Add remaining unmanaged resources

pkg/analyser/analyzer_test.go

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,208 @@ func TestAnalyze(t *testing.T) {
680680
},
681681
hasDrifted: true,
682682
},
683+
{
684+
name: "TestDiff with computed field send 1 alert",
685+
iac: []resource.Resource{
686+
&testresource.FakeResource{
687+
Id: "foobar",
688+
Type: "fakeres",
689+
FooBar: "foobar",
690+
BarFoo: "barfoo",
691+
Struct: struct {
692+
Baz string `computed:"true"`
693+
Bar string
694+
}{"baz", "bar"},
695+
},
696+
&testresource.FakeResource{
697+
Id: "resource",
698+
Type: "other",
699+
FooBar: "foobar",
700+
BarFoo: "barfoo",
701+
Struct: struct {
702+
Baz string `computed:"true"`
703+
Bar string
704+
}{"baz", "bar"},
705+
StructSlice: []struct {
706+
String string `computed:"true"`
707+
Array []string `computed:"true"`
708+
}{
709+
{"one", []string{"foo"}},
710+
},
711+
},
712+
},
713+
cloud: []resource.Resource{
714+
&testresource.FakeResource{
715+
Id: "foobar",
716+
Type: "fakeres",
717+
FooBar: "foobar",
718+
BarFoo: "barfoo",
719+
Struct: struct {
720+
Baz string `computed:"true"`
721+
Bar string
722+
}{"bazdiff", "bardiff"},
723+
},
724+
&testresource.FakeResource{
725+
Id: "resource",
726+
Type: "other",
727+
FooBar: "foobar",
728+
BarFoo: "barfoo",
729+
Struct: struct {
730+
Baz string `computed:"true"`
731+
Bar string
732+
}{"bazdiff", "bar"},
733+
StructSlice: []struct {
734+
String string `computed:"true"`
735+
Array []string `computed:"true"`
736+
}{
737+
{"onediff", []string{"foo", "diff"}},
738+
},
739+
},
740+
},
741+
alerts: alerter.Alerts{},
742+
expected: Analysis{
743+
managed: []resource.Resource{
744+
&testresource.FakeResource{
745+
Id: "foobar",
746+
Type: "fakeres",
747+
FooBar: "foobar",
748+
BarFoo: "barfoo",
749+
Struct: struct {
750+
Baz string `computed:"true"`
751+
Bar string
752+
}{"baz", "bar"},
753+
},
754+
&testresource.FakeResource{
755+
Id: "resource",
756+
Type: "other",
757+
FooBar: "foobar",
758+
BarFoo: "barfoo",
759+
Struct: struct {
760+
Baz string `computed:"true"`
761+
Bar string
762+
}{"baz", "bar"},
763+
StructSlice: []struct {
764+
String string `computed:"true"`
765+
Array []string `computed:"true"`
766+
}{
767+
{"one", []string{"foo"}},
768+
},
769+
},
770+
},
771+
summary: Summary{
772+
TotalResources: 2,
773+
TotalDrifted: 2,
774+
TotalManaged: 2,
775+
},
776+
differences: []Difference{
777+
{
778+
Res: &testresource.FakeResource{
779+
Id: "foobar",
780+
Type: "fakeres",
781+
FooBar: "foobar",
782+
BarFoo: "barfoo",
783+
Struct: struct {
784+
Baz string `computed:"true"`
785+
Bar string
786+
}{"baz", "bar"},
787+
},
788+
Changelog: Changelog{
789+
{
790+
Change: diff.Change{
791+
Type: "update",
792+
From: "baz",
793+
To: "bazdiff",
794+
Path: []string{
795+
"Struct",
796+
"Baz",
797+
},
798+
},
799+
Computed: true,
800+
},
801+
{
802+
Change: diff.Change{
803+
Type: "update",
804+
From: "bar",
805+
To: "bardiff",
806+
Path: []string{
807+
"Struct",
808+
"Bar",
809+
},
810+
},
811+
Computed: false,
812+
},
813+
},
814+
},
815+
{
816+
Res: &testresource.FakeResource{
817+
Id: "resource",
818+
Type: "other",
819+
FooBar: "foobar",
820+
BarFoo: "barfoo",
821+
Struct: struct {
822+
Baz string `computed:"true"`
823+
Bar string
824+
}{"baz", "bar"},
825+
StructSlice: []struct {
826+
String string `computed:"true"`
827+
Array []string `computed:"true"`
828+
}{
829+
{"one", []string{"foo"}},
830+
},
831+
},
832+
Changelog: Changelog{
833+
{
834+
Change: diff.Change{
835+
Type: "create",
836+
From: nil,
837+
To: "diff",
838+
Path: []string{
839+
"StructSlice",
840+
"0",
841+
"Array",
842+
"1",
843+
},
844+
},
845+
Computed: true,
846+
},
847+
{
848+
Change: diff.Change{
849+
Type: "update",
850+
From: "baz",
851+
To: "bazdiff",
852+
Path: []string{
853+
"Struct",
854+
"Baz",
855+
},
856+
},
857+
Computed: true,
858+
},
859+
{
860+
Change: diff.Change{
861+
Type: "update",
862+
From: "one",
863+
To: "onediff",
864+
Path: []string{
865+
"StructSlice",
866+
"0",
867+
"String",
868+
},
869+
},
870+
Computed: true,
871+
},
872+
},
873+
},
874+
},
875+
alerts: alerter.Alerts{
876+
"": {
877+
{
878+
Message: "You have diffs on computed fields, check the documentation for potential false positive drifts",
879+
},
880+
},
881+
},
882+
},
883+
hasDrifted: true,
884+
},
683885
}
684886

685887
for _, c := range cases {

0 commit comments

Comments
 (0)