Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix for multiple computed alert being send #171

Merged
merged 1 commit into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions pkg/analyser/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ func (a Analyzer) Analyze(remoteResources, resourcesFromState []resource.Resourc
})
}
}
if haveComputedDiff {
a.alerter.SendAlert("",
alerter.Alert{
Message: "You have diffs on computed fields, check the documentation for potential false positive drifts",
})
}
}

if haveComputedDiff {
a.alerter.SendAlert("",
alerter.Alert{
Message: "You have diffs on computed fields, check the documentation for potential false positive drifts",
})
wbeuil marked this conversation as resolved.
Show resolved Hide resolved
}

// Add remaining unmanaged resources
Expand Down
202 changes: 202 additions & 0 deletions pkg/analyser/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,208 @@ func TestAnalyze(t *testing.T) {
},
hasDrifted: true,
},
{
name: "TestDiff with computed field send 1 alert",
iac: []resource.Resource{
&testresource.FakeResource{
Id: "foobar",
Type: "fakeres",
FooBar: "foobar",
BarFoo: "barfoo",
Struct: struct {
Baz string `computed:"true"`
Bar string
}{"baz", "bar"},
},
&testresource.FakeResource{
Id: "resource",
Type: "other",
FooBar: "foobar",
BarFoo: "barfoo",
Struct: struct {
Baz string `computed:"true"`
Bar string
}{"baz", "bar"},
StructSlice: []struct {
String string `computed:"true"`
Array []string `computed:"true"`
}{
{"one", []string{"foo"}},
},
},
},
cloud: []resource.Resource{
&testresource.FakeResource{
Id: "foobar",
Type: "fakeres",
FooBar: "foobar",
BarFoo: "barfoo",
Struct: struct {
Baz string `computed:"true"`
Bar string
}{"bazdiff", "bardiff"},
},
&testresource.FakeResource{
Id: "resource",
Type: "other",
FooBar: "foobar",
BarFoo: "barfoo",
Struct: struct {
Baz string `computed:"true"`
Bar string
}{"bazdiff", "bar"},
StructSlice: []struct {
String string `computed:"true"`
Array []string `computed:"true"`
}{
{"onediff", []string{"foo", "diff"}},
},
},
},
alerts: alerter.Alerts{},
expected: Analysis{
managed: []resource.Resource{
&testresource.FakeResource{
Id: "foobar",
Type: "fakeres",
FooBar: "foobar",
BarFoo: "barfoo",
Struct: struct {
Baz string `computed:"true"`
Bar string
}{"baz", "bar"},
},
&testresource.FakeResource{
Id: "resource",
Type: "other",
FooBar: "foobar",
BarFoo: "barfoo",
Struct: struct {
Baz string `computed:"true"`
Bar string
}{"baz", "bar"},
StructSlice: []struct {
String string `computed:"true"`
Array []string `computed:"true"`
}{
{"one", []string{"foo"}},
},
},
},
summary: Summary{
TotalResources: 2,
TotalDrifted: 2,
TotalManaged: 2,
},
differences: []Difference{
{
Res: &testresource.FakeResource{
Id: "foobar",
Type: "fakeres",
FooBar: "foobar",
BarFoo: "barfoo",
Struct: struct {
Baz string `computed:"true"`
Bar string
}{"baz", "bar"},
},
Changelog: Changelog{
{
Change: diff.Change{
Type: "update",
From: "baz",
To: "bazdiff",
Path: []string{
"Struct",
"Baz",
},
},
Computed: true,
},
{
Change: diff.Change{
Type: "update",
From: "bar",
To: "bardiff",
Path: []string{
"Struct",
"Bar",
},
},
Computed: false,
},
},
},
{
Res: &testresource.FakeResource{
Id: "resource",
Type: "other",
FooBar: "foobar",
BarFoo: "barfoo",
Struct: struct {
Baz string `computed:"true"`
Bar string
}{"baz", "bar"},
StructSlice: []struct {
String string `computed:"true"`
Array []string `computed:"true"`
}{
{"one", []string{"foo"}},
},
},
Changelog: Changelog{
{
Change: diff.Change{
Type: "create",
From: nil,
To: "diff",
Path: []string{
"StructSlice",
"0",
"Array",
"1",
},
},
Computed: true,
},
{
Change: diff.Change{
Type: "update",
From: "baz",
To: "bazdiff",
Path: []string{
"Struct",
"Baz",
},
},
Computed: true,
},
{
Change: diff.Change{
Type: "update",
From: "one",
To: "onediff",
Path: []string{
"StructSlice",
"0",
"String",
},
},
Computed: true,
},
},
},
},
alerts: alerter.Alerts{
"": {
{
Message: "You have diffs on computed fields, check the documentation for potential false positive drifts",
},
},
},
},
hasDrifted: true,
},
}

for _, c := range cases {
Expand Down