Skip to content

Commit

Permalink
#73: testcase for DEL command (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rits1272 authored Aug 11, 2024
1 parent 5416a77 commit c25c000
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/del_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package tests

import (
"testing"

"gotest.tools/v3/assert"
)

func TestDel(t *testing.T) {
conn := getLocalConnection()
defer conn.Close()

testCases := []struct {
name string
commands []string
expected []interface{}
}{
{
name: "DEL with set key",
commands: []string{"SET k1 v1", "DEL k1", "GET k1"},
expected: []interface{}{"OK", int64(1), "(nil)"},
},
{
name: "DEL with multiple keys",
commands: []string{"SET k1 v1", "SET k2 v2", "DEL k1 k2", "GET k1", "GET k2"},
expected: []interface{}{"OK", "OK", int64(2), "(nil)", "(nil)"},
},
{
name: "DEL with key not set",
commands: []string{"GET k3", "DEL k3"},
expected: []interface{}{"(nil)", int64(0)},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
deleteTestKeys([]string{"k1", "k2", "k3"})
for i, cmd := range tc.commands {
result := fireCommand(conn, cmd)
assert.Equal(t, tc.expected[i], result, "Value mismatch for cmd %s", cmd)
}
})
}
}

0 comments on commit c25c000

Please sign in to comment.