Skip to content

Commit

Permalink
tests: add tests for /go/protoutil/duration
Browse files Browse the repository at this point in the history
Signed-off-by: Manik Rana <manikrana54@gmail.com>
  • Loading branch information
Maniktherana committed Jan 16, 2024
1 parent c1f9c80 commit 3c002be
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions go/protoutil/duration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ func TestDurationFromProto(t *testing.T) {
isOk: true,
shouldErr: true,
},
{
name: "nanoseconds",
in: &vttime.Duration{
Seconds: 1,
Nanos: 500000000,
},
expected: time.Second + 500*time.Millisecond,
isOk: true,
shouldErr: false,
},
}

for _, tt := range tests {
Expand All @@ -80,3 +90,40 @@ func TestDurationFromProto(t *testing.T) {
})
}
}

func TestDurationToProto(t *testing.T) {
t.Parallel()

tests := []struct {
name string
in time.Duration
expected *vttime.Duration
}{
{
name: "success",
in: time.Second * 1000,
expected: &vttime.Duration{Seconds: 1000},
},
{
name: "zero duration",
in: 0,
expected: &vttime.Duration{},
},
{
name: "nanoseconds",
in: time.Second + 500*time.Millisecond,
expected: &vttime.Duration{Seconds: 1, Nanos: 500000000},
},
}

for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

actual := DurationToProto(tt.in)
assert.Equal(t, tt.expected, actual)
})
}
}

0 comments on commit 3c002be

Please sign in to comment.