Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests cleanup #366

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 2 additions & 8 deletions cmd_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import (
// Test CLIENT *.
func TestClient(t *testing.T) {
t.Run("setname and getname", func(t *testing.T) {
s := RunT(t)
c, err := proto.Dial(s.Addr())
ok(t, err)
defer c.Close()
_, c := runWithClient(t)

// Set the client name
mustDo(t, c,
Expand All @@ -28,10 +25,7 @@ func TestClient(t *testing.T) {
})

t.Run("getname without setname", func(t *testing.T) {
s := RunT(t)
c, err := proto.Dial(s.Addr())
ok(t, err)
defer c.Close()
_, c := runWithClient(t)

// Get the client name without setting it first
mustDo(t, c,
Expand Down
5 changes: 1 addition & 4 deletions cmd_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import (

// Test CLUSTER *.
func TestCluster(t *testing.T) {
s := RunT(t)
c, err := proto.Dial(s.Addr())
ok(t, err)
defer c.Close()
s, c := runWithClient(t)

t.Run("slots", func(t *testing.T) {
port, err := strconv.Atoi(s.Port())
Expand Down
70 changes: 10 additions & 60 deletions cmd_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ import (

func TestAuth(t *testing.T) {
t.Run("default user", func(t *testing.T) {
s, err := Run()
ok(t, err)
defer s.Close()
c, err := proto.Dial(s.Addr())
ok(t, err)
defer c.Close()
s, c := runWithClient(t)

mustDo(t, c,
"AUTH", "foo", "bar", "baz",
Expand All @@ -40,12 +35,7 @@ func TestAuth(t *testing.T) {
})

t.Run("another user", func(t *testing.T) {
s, err := Run()
ok(t, err)
defer s.Close()
c, err := proto.Dial(s.Addr())
ok(t, err)
defer c.Close()
s, c := runWithClient(t)

s.RequireUserAuth("hello", "world")
mustDo(t, c,
Expand All @@ -71,12 +61,7 @@ func TestAuth(t *testing.T) {
})

t.Run("error cases", func(t *testing.T) {
s, err := Run()
ok(t, err)
defer s.Close()
c, err := proto.Dial(s.Addr())
ok(t, err)
defer c.Close()
_, c := runWithClient(t)

mustDo(t, c,
"AUTH",
Expand All @@ -91,12 +76,7 @@ func TestAuth(t *testing.T) {
}

func TestPing(t *testing.T) {
s, err := Run()
ok(t, err)
defer s.Close()
c, err := proto.Dial(s.Addr())
ok(t, err)
defer c.Close()
_, c := runWithClient(t)

t.Run("no args", func(t *testing.T) {
mustDo(t, c,
Expand All @@ -121,12 +101,7 @@ func TestPing(t *testing.T) {
}

func TestEcho(t *testing.T) {
s, err := Run()
ok(t, err)
defer s.Close()
c, err := proto.Dial(s.Addr())
ok(t, err)
defer c.Close()
_, c := runWithClient(t)

mustDo(t, c,
"ECHO", "hello\nworld",
Expand All @@ -140,12 +115,7 @@ func TestEcho(t *testing.T) {
}

func TestSelect(t *testing.T) {
s, err := Run()
ok(t, err)
defer s.Close()
c, err := proto.Dial(s.Addr())
ok(t, err)
defer c.Close()
s, c := runWithClient(t)

mustOK(t, c, "SET", "foo", "bar")
mustOK(t, c, "SELECT", "5")
Expand Down Expand Up @@ -173,12 +143,7 @@ func TestSelect(t *testing.T) {
}

func TestSwapdb(t *testing.T) {
s, err := Run()
ok(t, err)
defer s.Close()
c, err := proto.Dial(s.Addr())
ok(t, err)
defer c.Close()
s, c := runWithClient(t)

mustOK(t, c, "SET", "foo", "bar")
mustOK(t, c, "SELECT", "5")
Expand Down Expand Up @@ -238,12 +203,7 @@ func TestSwapdb(t *testing.T) {
}

func TestQuit(t *testing.T) {
s, err := Run()
ok(t, err)
defer s.Close()
c, err := proto.Dial(s.Addr())
ok(t, err)
defer c.Close()
_, c := runWithClient(t)

mustOK(t, c, "QUIT")

Expand All @@ -253,12 +213,7 @@ func TestQuit(t *testing.T) {
}

func TestSetError(t *testing.T) {
s, err := Run()
ok(t, err)
defer s.Close()
c, err := proto.Dial(s.Addr())
ok(t, err)
defer c.Close()
s, c := runWithClient(t)

mustDo(t, c,
"PING",
Expand All @@ -280,12 +235,7 @@ func TestSetError(t *testing.T) {

func TestHello(t *testing.T) {
t.Run("default user", func(t *testing.T) {
s, err := Run()
ok(t, err)
defer s.Close()
c, err := proto.Dial(s.Addr())
ok(t, err)
defer c.Close()
s, c := runWithClient(t)

payl := proto.Map(
proto.String("server"), proto.String("miniredis"),
Expand Down