Skip to content

Commit

Permalink
chore: test Duration
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Mar 3, 2024
1 parent c9fd6dd commit 5fb901a
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions pkg/types/responses/responses_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package responses_test

import (
"encoding/json"
"github.com/stretchr/testify/require"

Check failure on line 5 in pkg/types/responses/responses_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed (goimports)
"main/pkg/types/responses"
"testing"
"time"
)

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

var duration responses.Duration
err := json.Unmarshal([]byte("\"invalid\""), &duration)

require.Error(t, err)
require.Zero(t, duration.Duration)
}

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

var duration responses.Duration
err := json.Unmarshal([]byte("invalid"), &duration)

require.Error(t, err)
require.Zero(t, duration.Duration)
}

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

var duration responses.Duration
err := json.Unmarshal([]byte("\"20s\""), &duration)

require.NoError(t, err)
require.Equal(t, 20*time.Second, duration.Duration)
}

0 comments on commit 5fb901a

Please sign in to comment.