Skip to content

Commit

Permalink
Add DropQueue (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Pastro committed Aug 10, 2023
1 parent 33221ec commit 9bb10e1
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
name: CI
name: Pull request

on:
pull_request:
push:
branches:
- main

jobs:
lint:
Expand All @@ -19,6 +16,13 @@ jobs:
with:
version: latest

vulncheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: govulncheck
uses: golang/govulncheck-action@v1

test:
runs-on: ubuntu-latest
steps:
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/push_to_main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Push to main

on:
push:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: "./go.mod"
- run: go test -race -coverprofile=coverage.out -covermode=atomic
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Go Reference](https://pkg.go.dev/badge/github.com/craigpastro/pgmq-go.svg)](https://pkg.go.dev/github.com/craigpastro/pgmq-go)
[![Go Report Card](https://goreportcard.com/badge/github.com/craigpastro/pgmq-go)](https://goreportcard.com/report/github.com/craigpastro/pgmq-go)
[![CI](https://github.com/craigpastro/pgmq-go/actions/workflows/ci.yaml/badge.svg)](https://github.com/craigpastro/pgmq-go/actions/workflows/ci.yaml)
[![CI](https://github.com/craigpastro/pgmq-go/actions/workflows/push_to_main.yaml/badge.svg)](https://github.com/craigpastro/pgmq-go/actions/workflows/push_to_main.yaml)
[![codecov](https://codecov.io/github/craigpastro/pgmq-go/branch/main/graph/badge.svg?token=00AJODX77Z)](https://codecov.io/github/craigpastro/pgmq-go)

A Go (Golang) client for
Expand All @@ -11,7 +11,7 @@ A Go (Golang) client for

## Usage

Start a Postgres Instance with the PGMQ extension installed:
Start a Postgres instance with the PGMQ extension installed:

```shell
docker run -d --name postgres -e POSTGRES_PASSWORD=password -p 5432:5432 quay.io/tembo/pgmq-pg:latest
Expand Down
11 changes: 11 additions & 0 deletions pgmq.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ func (p *PGMQ) CreateQueue(ctx context.Context, queue string) error {
return nil
}

// DropQueue deletes the given queue. It deletes the queue's tables, indices,
// and metadata. It will return an error if the queue does not exist.
func (p *PGMQ) DropQueue(ctx context.Context, queue string) error {
_, err := p.pool.Exec(ctx, "select pgmq_drop_queue($1)", queue)
if err != nil {
return wrapPostgresError(err)
}

return nil
}

// Send sends a single message to a queue. The message id, unique to the
// queue, is returned.
func (p *PGMQ) Send(ctx context.Context, queue string, msg map[string]any) (int64, error) {
Expand Down
22 changes: 22 additions & 0 deletions pgmq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,28 @@ func TestMain(m *testing.M) {
os.Exit(code)
}

func TestDropQueue(t *testing.T) {
ctx := context.Background()
queue := t.Name()

err := q.CreateQueue(ctx, queue)
require.NoError(t, err)

err = q.DropQueue(ctx, queue)
require.NoError(t, err)

_, err = q.Send(ctx, queue, testMsg1)
require.Error(t, err)
}

func TestDropQueueWhichDoesNotExist(t *testing.T) {
ctx := context.Background()
queue := t.Name()

err := q.DropQueue(ctx, queue)
require.Error(t, err)
}

func TestSend(t *testing.T) {
ctx := context.Background()
queue := t.Name()
Expand Down

0 comments on commit 9bb10e1

Please sign in to comment.