aboutsummaryrefslogtreecommitdiffstats
path: root/encoding_test.go
diff options
context:
space:
mode:
authorMarc Pervaz Boocha <marcpervaz@qburst.com>2025-02-25 09:46:37 +0530
committerMarc Pervaz Boocha <marcpervaz@qburst.com>2025-02-27 13:38:02 +0530
commit4e6d37095c6c75632ca9c4af2cbb3276364c2e5a (patch)
tree22540501437a80f8c36d3075eb8372444f513ad4 /encoding_test.go
parentAdded examples and documentation (diff)
downloadcache-4e6d37095c6c75632ca9c4af2cbb3276364c2e5a.tar
cache-4e6d37095c6c75632ca9c4af2cbb3276364c2e5a.tar.gz
cache-4e6d37095c6c75632ca9c4af2cbb3276364c2e5a.tar.bz2
cache-4e6d37095c6c75632ca9c4af2cbb3276364c2e5a.tar.lz
cache-4e6d37095c6c75632ca9c4af2cbb3276364c2e5a.tar.xz
cache-4e6d37095c6c75632ca9c4af2cbb3276364c2e5a.tar.zst
cache-4e6d37095c6c75632ca9c4af2cbb3276364c2e5a.zip
Add additional test cases to improve coverage and robustness
Diffstat (limited to '')
-rw-r--r--encoding_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/encoding_test.go b/encoding_test.go
index 5fc4c9a..bac148c 100644
--- a/encoding_test.go
+++ b/encoding_test.go
@@ -40,6 +40,40 @@ func TestEncodeDecodeUint64(t *testing.T) {
assert.Equal(t, tt.value, decodedValue)
})
}
+func TestDecodeUint64Error(t *testing.T) {
+ var buf bytes.Buffer
+ buf.Write([]byte{0xFF}) // Invalid data for uint64
+ decoder := newDecoder(&buf)
+
+ _, err := decoder.DecodeUint64()
+ assert.Error(t, err)
+func TestEncodeDecodeTimeBoundary(t *testing.T) {
+ tests := []struct {
+ name string
+ value time.Time
+ }{
+ {name: "Unix Epoch", value: time.Unix(0, 0)},
+ {name: "Far Future", value: time.Unix(1<<63-1, 0)},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ var buf bytes.Buffer
+ e := newEncoder(&buf)
+
+ err := e.EncodeTime(tt.value)
+ assert.NoError(t, err)
+ err = e.Flush()
+ assert.NoError(t, err)
+
+ decoder := newDecoder(bytes.NewReader(buf.Bytes()))
+
+ decodedValue, err := decoder.DecodeTime()
+ assert.NoError(t, err)
+
+ assert.Equal(t, tt.value, decodedValue)
+ })
+ }
}
func TestEncodeDecodeTime(t *testing.T) {