Skip to content

Commit

Permalink
ISSUE 79: Rewrite humanString statement in console.go
Browse files Browse the repository at this point in the history
  • Loading branch information
lotoussa committed Feb 8, 2021
1 parent 04039f7 commit d28dd21
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
25 changes: 11 additions & 14 deletions pkg/cmd/scan/output/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ func (c *Console) Write(analysis *analyser.Analysis) error {
for ty, resources := range deletedByType {
fmt.Printf(" %s:\n", ty)
for _, res := range resources {
stringer, ok := res.(fmt.Stringer)
fmt.Printf(" - %s", res.TerraformId())
if ok {
fmt.Printf(" (%s)", stringer.String())
humanString := res.TerraformId()
if stringer, ok := res.(fmt.Stringer); ok {
humanString = stringer.String()
}
fmt.Println()
fmt.Printf(" - %s\n", humanString)
}
}
}
Expand All @@ -50,25 +49,23 @@ func (c *Console) Write(analysis *analyser.Analysis) error {
for ty, resource := range unmanagedByType {
fmt.Printf(" %s:\n", ty)
for _, res := range resource {
stringer, ok := res.(fmt.Stringer)
fmt.Printf(" - %s", res.TerraformId())
if ok {
fmt.Printf(" (%s)", stringer.String())
humanString := res.TerraformId()
if stringer, ok := res.(fmt.Stringer); ok {
humanString = stringer.String()
}
fmt.Println()
fmt.Printf(" - %s\n", humanString)
}
}
}

if analysis.Summary().TotalDrifted > 0 {
fmt.Printf("Found drifted resources:\n")
for _, difference := range analysis.Differences() {
stringer, ok := difference.Res.(fmt.Stringer)
humanString := difference.Res.TerraformType()
if ok {
humanString := difference.Res.TerraformId()
if stringer, ok := difference.Res.(fmt.Stringer); ok {
humanString = stringer.String()
}
fmt.Printf(" - %s (%s):\n", difference.Res.TerraformId(), humanString)
fmt.Printf(" - %s (%s):\n", humanString, difference.Res.TerraformType())
for _, change := range difference.Changelog {
path := strings.Join(change.Path, ".")
pref := fmt.Sprintf("%s %s:", color.YellowString("~"), path)
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/scan/output/testdata/output_stringer_resources.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Found deleted resources:
FakeResourceStringer:
- dfjkgnbsgj (Name: 'deleted resource')
- Name: 'deleted resource'
Found unmanaged resources:
FakeResourceStringer:
- duysgkfdjfdgfhd (Name: 'unmanaged resource')
- Name: 'unmanaged resource'
Found drifted resources:
- gdsfhgkbn (Name: 'resource with diff'):
- Name: 'resource with diff' (FakeResourceStringer):
~ Name: "" => "resource with diff"
Found 3 resource(s)
- 33% coverage
Expand Down

0 comments on commit d28dd21

Please sign in to comment.