-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}) | ||
} | ||
} |