Skip to content

Commit

Permalink
changed multiple times reported one
Browse files Browse the repository at this point in the history
  • Loading branch information
tejal29 committed May 28, 2020
1 parent eb5cbcb commit a745d28
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
3 changes: 2 additions & 1 deletion pkg/skaffold/deploy/resource/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ func (d *Deployment) IsStatusCheckComplete() bool {
}

func (d *Deployment) ReportSinceLastUpdated() string {
if !d.status.changed {
if d.status.reported && !d.status.changed {
return ""
}
d.status.reported = true
return fmt.Sprintf("%s: %s", d, d.status)
}

Expand Down
35 changes: 23 additions & 12 deletions pkg/skaffold/deploy/resource/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,29 +213,40 @@ func TestReportSinceLastUpdated(t *testing.T) {

func TestReportSinceLastUpdatedMultipleTimes(t *testing.T) {
var tests = []struct {
description string
times int
expected string
description string
statuses []string
reportStatusSeq []bool
expected string
}{
{
description: "report first time should return status",
times: 1,
expected: "test-ns:deployment/test: cannot pull image",
description: "report first time should return status",
statuses: []string{"cannot pull image"},
reportStatusSeq: []bool{true},
expected: "test-ns:deployment/test: cannot pull image",
},
{
description: "report 2nd time should not return when same status",
statuses: []string{"cannot pull image", "cannot pull image"},
reportStatusSeq: []bool{true, true},
expected: "",
},
{
description: "report 2nd time should not return",
times: 2,
expected: "",
description: "report called after multiple changes but last status was not changed.",
statuses: []string{"cannot pull image", "changed but not reported", "changed but not reported", "changed but not reported"},
reportStatusSeq: []bool{true, false, false, true},
expected: "test-ns:deployment/test: changed but not reported",
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
dep := NewDeployment("test", "test-ns", 1)
var actual string
for i := 0; i < test.times; i++ {
for i, status := range test.statuses {
// update to same status
dep.UpdateStatus("cannot pull image", nil)
actual = dep.ReportSinceLastUpdated()
dep.UpdateStatus(status, nil)
if test.reportStatusSeq[i] {
actual = dep.ReportSinceLastUpdated()
}
}
t.CheckDeepEqual(test.expected, actual)
})
Expand Down
7 changes: 4 additions & 3 deletions pkg/skaffold/deploy/resource/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ limitations under the License.
package resource

type Status struct {
err error
details string
changed bool
err error
details string
changed bool
reported bool
}

func (rs Status) Error() error {
Expand Down

0 comments on commit a745d28

Please sign in to comment.