Skip to content

Commit 74ebc80

Browse files
committed
Test utils.Checksum()
1 parent 8f96351 commit 74ebc80

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

utils/utils_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package utils
22

33
import (
44
"context"
5+
"encoding/hex"
56
"fmt"
67
"github.com/stretchr/testify/assert"
78
"github.com/stretchr/testify/require"
@@ -60,6 +61,44 @@ func TestBatchSliceOfStrings(t *testing.T) {
6061
}
6162
}
6263

64+
func TestChecksum(t *testing.T) {
65+
subtests := []struct {
66+
name string
67+
input any
68+
output string
69+
}{
70+
{"empty_string", "", "da39a3ee5e6b4b0d3255bfef95601890afd80709"},
71+
{"empty_bytes", []byte(nil), "da39a3ee5e6b4b0d3255bfef95601890afd80709"},
72+
{"space_string", " ", "b858cb282617fb0956d960215c8e84d1ccf909c6"},
73+
{"space_bytes", []byte(" "), "b858cb282617fb0956d960215c8e84d1ccf909c6"},
74+
}
75+
76+
for _, st := range subtests {
77+
t.Run(st.name, func(t *testing.T) {
78+
require.Equal(t, st.output, hex.EncodeToString(Checksum(st.input)))
79+
})
80+
}
81+
82+
unsupported := []struct {
83+
name string
84+
input any
85+
}{
86+
{"nil", nil},
87+
{"bool", false},
88+
{"int", 0},
89+
{"float", 0.0},
90+
{"struct", struct{}{}},
91+
{"slice", []string{}},
92+
{"map", map[string]string{}},
93+
}
94+
95+
for _, st := range unsupported {
96+
t.Run(st.name, func(t *testing.T) {
97+
require.Panics(t, func() { Checksum(st.input) })
98+
})
99+
}
100+
}
101+
63102
func TestChanFromSlice(t *testing.T) {
64103
t.Run("Nil", func(t *testing.T) {
65104
ch := ChanFromSlice[int](nil)

0 commit comments

Comments
 (0)