-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(v2/rabbittest): add helper for creating client
- Loading branch information
Showing
2 changed files
with
37 additions
and
19 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
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,29 @@ | ||
package rabbittest | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/heureka/gorabbit/v2" | ||
) | ||
|
||
// NewClient creates a new RabbitMQ client. | ||
// Closes the client on test cleanup. | ||
func NewClient(t *testing.T, ops ...gorabbit.Option) *gorabbit.Client { | ||
t.Helper() | ||
|
||
url := os.Getenv("RABBITMQ_URL") | ||
if url == "" { | ||
t.Fatal("please provide rabbitMQ URL via RABBITMQ_URL environment variable") | ||
} | ||
|
||
client := gorabbit.New(url, ops...) | ||
|
||
t.Cleanup(func() { | ||
if err := client.Close(); err != nil { | ||
t.Fatalf("close client: %s", err) | ||
} | ||
}) | ||
|
||
return client | ||
} |