Skip to content

Commit 6f05c60

Browse files
authored
test(describe): fix flaky pipeline show test (#1048)
Related: #918 <!-- Provide summary of changes --> <!-- Issue number, if available. E.g. "Fixes #31", "Addresses #42, 77" --> By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent 75d7715 commit 6f05c60

3 files changed

Lines changed: 18 additions & 9 deletions

File tree

internal/pkg/describe/describe.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"github.com/aws/aws-sdk-go/aws"
99
"github.com/aws/aws-sdk-go/service/cloudformation"
10+
"github.com/dustin/go-humanize"
1011
"io"
1112
)
1213

@@ -19,6 +20,9 @@ const (
1920
noAdditionalFormatting = 0
2021
)
2122

23+
// humanizeTime is overriden in tests so that its output is constant as time passes.
24+
var humanizeTime = humanize.Time
25+
2226
// HumanJSONStringer contains methods that stringify app info for output.
2327
type HumanJSONStringer interface {
2428
HumanString() string

internal/pkg/describe/pipeline_test.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/aws/amazon-ecs-cli-v2/internal/pkg/describe/mocks"
1414
"github.com/aws/aws-sdk-go/aws"
1515
"github.com/aws/aws-sdk-go/service/cloudformation"
16+
"github.com/dustin/go-humanize"
1617
"github.com/golang/mock/gomock"
1718
"github.com/stretchr/testify/require"
1819
)
@@ -188,6 +189,14 @@ func TestPipelineDescriber_Describe(t *testing.T) {
188189
}
189190

190191
func TestPipelineDescriber_String(t *testing.T) {
192+
oldHumanize := humanizeTime
193+
humanizeTime = func(then time.Time) string {
194+
now, _ := time.Parse(time.RFC3339, "2020-06-19T00:00:00+00:00")
195+
return humanize.RelTime(then, now, "ago", "from now")
196+
}
197+
defer func() {
198+
humanizeTime = oldHumanize
199+
}()
191200
testCases := map[string]struct {
192201
inPipeline *Pipeline
193202
expectedHumanString string
@@ -200,8 +209,8 @@ func TestPipelineDescriber_String(t *testing.T) {
200209
Name pipeline-dinder-badgoose-repo
201210
Region us-west-2
202211
AccountID 1234567890
203-
Created At 3 months ago
204-
Updated At 3 months ago
212+
Created At 4 months ago
213+
Updated At 4 months ago
205214
206215
Stages
207216
@@ -228,8 +237,8 @@ Resources
228237
Name pipeline-dinder-badgoose-repo
229238
Region us-west-2
230239
AccountID 1234567890
231-
Created At 3 months ago
232-
Updated At 3 months ago
240+
Created At 4 months ago
241+
Updated At 4 months ago
233242
234243
Stages
235244
@@ -246,7 +255,7 @@ Stages
246255
human := tc.inPipeline.HumanString()
247256
json, _ := tc.inPipeline.JSONString()
248257

249-
require.NotEmpty(t, tc.expectedHumanString, human, "expected human output to not be empty")
258+
require.Equal(t, tc.expectedHumanString, human, "expected human output to match")
250259
require.Equal(t, tc.expectedJSONString, json, "expected JSON output to match")
251260
}
252261
}

internal/pkg/describe/status.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@ import (
1616
"github.com/aws/amazon-ecs-cli-v2/internal/pkg/config"
1717
"github.com/aws/amazon-ecs-cli-v2/internal/pkg/deploy/cloudformation/stack"
1818
"github.com/aws/amazon-ecs-cli-v2/internal/pkg/term/color"
19-
"github.com/dustin/go-humanize"
2019
)
2120

22-
// humanizeTime is overriden in tests so that its output is constant as time passes.
23-
var humanizeTime = humanize.Time
24-
2521
type alarmStatusGetter interface {
2622
GetAlarmsWithTags(tags map[string]string) ([]cloudwatch.AlarmStatus, error)
2723
}

0 commit comments

Comments
 (0)