Skip to content

Commit

Permalink
Update to add test for GenerateMarkdownSummary
Browse files Browse the repository at this point in the history
  • Loading branch information
seanconroy2021 committed Oct 2, 2023
1 parent 0c3a3cf commit a69b08f
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 0 deletions.
60 changes: 60 additions & 0 deletions internal/applicationsnapshot/__snapshots__/report_test.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

[Test_GenerateMarkdownSummary/One_Warning_and_One_Success - 1]
| Field | Value |Status|
|-----------|-------|-------|
| Time | 1970-01-01 00:00:00 | |
| Name | | |
| Successes | 1 | :white_check_mark: |
| Failures | 0 | :white_check_mark: |
| Warnings | 1 | :x: |
| Result | true | :white_check_mark: |

---

[Test_GenerateMarkdownSummary/One_Failure_and_One_Violation - 1]
| Field | Value |Status|
|-----------|-------|-------|
| Time | 1970-01-01 00:00:00 | |
| Name | | |
| Successes | 0 | :x: |
| Failures | 1 | :x: |
| Warnings | 1 | :x: |
| Result | false | :x: |

---

[Test_GenerateMarkdownSummary/Multiple_Failure_and_One_Violation - 1]
| Field | Value |Status|
|-----------|-------|-------|
| Time | 1970-01-01 00:00:00 | |
| Name | | |
| Successes | 0 | :x: |
| Failures | 3 | :x: |
| Warnings | 2 | :x: |
| Result | false | :x: |

---

[Test_GenerateMarkdownSummary/With_success - 1]
| Field | Value |Status|
|-----------|-------|-------|
| Time | 1970-01-01 00:00:00 | |
| Name | | |
| Successes | 3 | :white_check_mark: |
| Failures | 0 | :white_check_mark: |
| Warnings | 0 | :white_check_mark: |
| Result | true | :white_check_mark: |

---

[Test_GenerateMarkdownSummary/With_Snapshot - 1]
| Field | Value |Status|
|-----------|-------|-------|
| Time | 1970-01-01 00:00:00 | |
| Name | | |
| Successes | 0 | :x: |
| Failures | 2 | :x: |
| Warnings | 2 | :x: |
| Result | false | :x: |

---
99 changes: 99 additions & 0 deletions internal/applicationsnapshot/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"testing"
"time"

"github.com/gkampitakis/go-snaps/snaps"
"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -152,6 +153,104 @@ policy:
assert.False(t, report.Success)
}

func Test_GenerateMarkdownSummary(t *testing.T) {
cases := []struct {
name string
snapshot string
components []Component
}{
{
name: "One Warning and One Success",
components: []Component{
{
Successes: []evaluator.Result{
{Message: "Success1"},
},
Warnings: []evaluator.Result{
{Message: "Warning1"},
},
Success: true,
},
},
},
{
name: "One Failure and One Violation",
components: []Component{
{
Violations: []evaluator.Result{
{Message: "failure1"},
},
Warnings: []evaluator.Result{
{Message: "Warning1"},
},
Success: false,
},
},
},
{
name: "Multiple Failure and One Violation",
components: []Component{
{
Violations: []evaluator.Result{
{Message: "failure1"},
{Message: "failure2"},
{Message: "failure3"},
},
Warnings: []evaluator.Result{
{Message: "Warning1"},
{Message: "Warning2"},
},
Success: false,
},
},
},
{
name: "With success",
components: []Component{
{
Successes: []evaluator.Result{
{Message: "Success1"},
{Message: "Success2"},
{Message: "Success3"},
},
Success: true,
},
},
},
{
name: "With Snapshot",
snapshot: "snappy",
components: []Component{
{
Violations: []evaluator.Result{
{Message: "failure1"},
{Message: "failure2"},
},
Warnings: []evaluator.Result{
{Message: "Warning1"},
{Message: "Warning2"},
},
Success: false,
},
},
},
}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {

ctx := context.Background()
report, err := NewReport(c.snapshot, c.components, createTestPolicy(t, ctx), nil, nil)
assert.NoError(t, err)
report.created = time.Unix(0, 0).UTC()

markdownSummary, err := generateMarkdownSummary(&report)
assert.NoError(t, err)
snaps.MatchSnapshot(t, string(markdownSummary))
})
}
}

func Test_ReportSummary(t *testing.T) {
tests := []struct {
name string
Expand Down

0 comments on commit a69b08f

Please sign in to comment.