Skip to content

Commit

Permalink
chore: add state test
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Jan 7, 2025
1 parent d483265 commit 4ae50ab
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions pkg/state/state_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package state

import (
"main/pkg/constants"
fetchersPkg "main/pkg/fetchers"
"testing"

"github.com/stretchr/testify/require"
)

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

state := NewState()
value, found := state.Get(constants.FetcherNameCommission)
require.False(t, found)
require.Nil(t, value)
}

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

value, found := Convert[fetchersPkg.CommissionData](nil)
require.False(t, found)
require.Zero(t, value)
}

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

defer func() {
if r := recover(); r == nil {
require.Fail(t, "Expected to have a panic here!")
}
}()

Convert[int64]("string")
}

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

var data *fetchersPkg.CommissionData

value, found := Convert[*fetchersPkg.CommissionData](data)
require.False(t, found)
require.Zero(t, value)
}

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

value, found := Convert[string]("string")
require.True(t, found)
require.Equal(t, "string", value)
}

0 comments on commit 4ae50ab

Please sign in to comment.