Skip to content

Commit

Permalink
check for nil
Browse files Browse the repository at this point in the history
  • Loading branch information
Tenyo Grozev committed Mar 19, 2022
1 parent 5dbdaf8 commit 6ee5c47
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
4 changes: 4 additions & 0 deletions api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ func timeFormat(t *time.Time) string {
// tzTimeFormat returns the time format with a TZ used in a few places
// TODO get rid of these places
func tzTimeFormat(t *time.Time) string {
if t == nil {
return ""
}

return t.UTC().Format("2006-01-02 15:04:05 MST")
}

Expand Down
43 changes: 42 additions & 1 deletion api/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func Test_toEc2VolumeModificationsResponse(t *testing.T) {
want: nil,
},
{
name: "regular input",
name: "modification completed",
args: args{modifications: []*ec2.VolumeModification{
{
EndTime: aws.Time(testTime),
Expand Down Expand Up @@ -350,7 +350,48 @@ func Test_toEc2VolumeModificationsResponse(t *testing.T) {
},
},
},
{
name: "modification in progress",
args: args{modifications: []*ec2.VolumeModification{
{
ModificationState: aws.String("optimizing"),
OriginalIops: aws.Int64(3000),
OriginalMultiAttachEnabled: aws.Bool(false),
OriginalSize: aws.Int64(8),
OriginalThroughput: aws.Int64(125),
OriginalVolumeType: aws.String("gp3"),
Progress: aws.Int64(0),
StartTime: aws.Time(testTime),
TargetIops: aws.Int64(3000),
TargetMultiAttachEnabled: aws.Bool(false),
TargetSize: aws.Int64(100),
TargetThroughput: aws.Int64(125),
TargetVolumeType: aws.String("gp3"),
VolumeId: aws.String("vol-0123456789abcdef0"),
},
}},
want: []Ec2VolumeModification{
{
EndTime: "",
ModificationState: "optimizing",
OriginalIops: 3000,
OriginalMultiAttachEnabled: false,
OriginalSize: 8,
OriginalThroughput: 125,
OriginalVolumeType: "gp3",
Progress: 0,
StartTime: "2022-02-22 22:22:22 UTC",
TargetIops: 3000,
TargetMultiAttachEnabled: false,
TargetSize: 100,
TargetThroughput: 125,
TargetVolumeType: "gp3",
VolumeId: "vol-0123456789abcdef0",
},
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := toEc2VolumeModificationsResponse(tt.args.modifications); !reflect.DeepEqual(got, tt.want) {
Expand Down

0 comments on commit 6ee5c47

Please sign in to comment.