Skip to content

Commit

Permalink
Merge pull request GoogleContainerTools#2892 from tejal29/refactor1
Browse files Browse the repository at this point in the history
Small refactors
  • Loading branch information
tejal29 authored Sep 16, 2019
2 parents 9a29999 + d656933 commit 6ea013e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 28 deletions.
6 changes: 0 additions & 6 deletions pkg/skaffold/deploy/resource/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,3 @@ func NewDeployment(name string, ns string, deadline time.Duration) *Deployment {
status: newStatus("", nil),
}
}

// For testing
func (d *Deployment) WithStatus(details string, err error) *Deployment {
d.UpdateStatus(details, err)
return d
}
4 changes: 2 additions & 2 deletions pkg/skaffold/deploy/status_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func StatusCheck(ctx context.Context, defaultLabeller *DefaultLabeller, runCtx *
defer wg.Done()
pollDeploymentRolloutStatus(ctx, kubectl.NewFromRunContext(runCtx), d)
pending := c.markProcessed()
printStatusCheckSummary(d, pending, c.total, out)
printStatusCheckSummary(out, d, pending, c.total)
}(d)
}

Expand Down Expand Up @@ -166,7 +166,7 @@ func getDeadline(d int) time.Duration {
return defaultStatusCheckDeadline
}

func printStatusCheckSummary(d *resource.Deployment, pending int, total int, out io.Writer) {
func printStatusCheckSummary(out io.Writer, d *resource.Deployment, pending int, total int) {
status := fmt.Sprintf("%s %s", tabHeader, d)
if err := d.Status().Error(); err != nil {
status = fmt.Sprintf("%s failed.%s Error: %s.",
Expand Down
72 changes: 52 additions & 20 deletions pkg/skaffold/deploy/status_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,32 +258,52 @@ func TestGetDeployStatus(t *testing.T) {
{
description: "one error",
deps: []*resource.Deployment{
resource.NewDeployment("dep1", "test", time.Second).
WithStatus("success", nil),
resource.NewDeployment("dep2", "test", time.Second).
WithStatus("error", errors.New("could not return within default timeout")),
withStatus(
resource.NewDeployment("dep1", "test", time.Second),
"success",
nil,
),
withStatus(
resource.NewDeployment("dep2", "test", time.Second),
"error",
errors.New("could not return within default timeout"),
),
},
expectedErrMsg: []string{"dep2 failed due to could not return within default timeout"},
shouldErr: true,
},
{
description: "no error",
deps: []*resource.Deployment{
resource.NewDeployment("dep1", "test", time.Second).
WithStatus("success", nil),
resource.NewDeployment("dep2", "test", time.Second).
WithStatus("running", nil),
withStatus(
resource.NewDeployment("dep1", "test", time.Second),
"success",
nil,
),
withStatus(resource.NewDeployment("dep2", "test", time.Second),
"running",
nil,
),
},
},
{
description: "multiple errors",
deps: []*resource.Deployment{
resource.NewDeployment("dep1", "test", time.Second).
WithStatus("success", nil),
resource.NewDeployment("dep2", "test", time.Second).
WithStatus("error", errors.New("could not return within default timeout")),
resource.NewDeployment("dep3", "test", time.Second).
WithStatus("error", errors.New("ERROR")),
withStatus(
resource.NewDeployment("dep1", "test", time.Second),
"success",
nil,
),
withStatus(
resource.NewDeployment("dep2", "test", time.Second),
"error",
errors.New("could not return within default timeout"),
),
withStatus(
resource.NewDeployment("dep3", "test", time.Second),
"error",
errors.New("ERROR"),
),
},
expectedErrMsg: []string{"dep2 failed due to could not return within default timeout",
"dep3 failed due to ERROR"},
Expand Down Expand Up @@ -385,10 +405,11 @@ func TestPrintSummaryStatus(t *testing.T) {
testutil.Run(t, test.description, func(t *testutil.T) {
out := new(bytes.Buffer)
printStatusCheckSummary(
resource.NewDeployment("dep", "test", 0).WithStatus("", test.err),
out,
withStatus(resource.NewDeployment("dep", "test", 0), "", test.err),
int(test.pending),
10,
out)
)
t.CheckDeepEqual(test.expected, out.String())
})
}
Expand Down Expand Up @@ -431,8 +452,11 @@ func TestPrintStatus(t *testing.T) {
"succes",
nil,
),
resource.NewDeployment("r2", "test", 1).
WithStatus("pending", nil),
withStatus(
resource.NewDeployment("r2", "test", 1),
"pending",
nil,
),
},
expectedOut: " - test:deployment/r2 pending\n",
},
Expand All @@ -444,8 +468,11 @@ func TestPrintStatus(t *testing.T) {
"succes",
nil,
),
resource.NewDeployment("r2", "test", 1).
WithStatus("", fmt.Errorf("context deadline expired")),
withStatus(
resource.NewDeployment("r2", "test", 1),
"",
fmt.Errorf("context deadline expired"),
),
},
expectedOut: " - test:deployment/r2 context deadline expired\n",
},
Expand All @@ -466,3 +493,8 @@ func withDone(d *resource.Deployment, details string, err error) *resource.Deplo
d.MarkDone()
return d
}

func withStatus(d *resource.Deployment, details string, err error) *resource.Deployment {
d.UpdateStatus(details, err)
return d
}

0 comments on commit 6ea013e

Please sign in to comment.