Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
398 additions
and
30 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 |
---|---|---|
|
@@ -15,4 +15,10 @@ | |
# vendor/ | ||
|
||
*.log | ||
|
||
# golangci-lint | ||
bin/ | ||
|
||
# golang migrate | ||
migrate.darwin-amd64 | ||
migrate.linux-amd64 |
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 @@ | ||
DROP TABLE IF EXISTS webhooks; |
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,21 @@ | ||
-- webhooks table | ||
|
||
CREATE TABLE IF NOT EXISTS webhooks( | ||
id uuid PRIMARY KEY, | ||
name VARCHAR NOT NULL, | ||
url VARCHAR NOT NULL, | ||
content_type VARCHAR NOT NULL, | ||
valid_status_codes SMALLINT[] NOT NULL, | ||
secret_token VARCHAR NOT NULL, | ||
active BOOLEAN NOT NULL, | ||
max_delivery_attempts SMALLINT NOT NULL, | ||
delivery_attempt_timeout SMALLINT NOT NULL, | ||
retry_min_backoff SMALLINT NOT NULL, | ||
retry_max_backoff SMALLINT NOT NULL, | ||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), | ||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS webhooks_name_idx ON webhooks (name); | ||
CREATE INDEX IF NOT EXISTS webhooks_active_idx ON webhooks (active); | ||
CREATE INDEX IF NOT EXISTS webhooks_created_at_idx ON webhooks USING BRIN(created_at); |
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
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
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,23 @@ | ||
package postmand | ||
|
||
// RepositoryGetOptions contains options used in the Get methods. | ||
type RepositoryGetOptions struct { | ||
Filters map[string]interface{} | ||
} | ||
|
||
// RepositoryListOptions contains options used in the List methods. | ||
type RepositoryListOptions struct { | ||
Filters map[string]interface{} | ||
Limit int | ||
Offset int | ||
OrderBy string | ||
} | ||
|
||
// WebhookRepository is the interface that will be used to iterate with the Webhook data. | ||
type WebhookRepository interface { | ||
Get(getOptions *RepositoryGetOptions) (*Webhook, error) | ||
List(listOptions *RepositoryListOptions) ([]*Webhook, error) | ||
Create(webhook *Webhook) error | ||
Update(webhook *Webhook) error | ||
Delete(id ID) error | ||
} |
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,31 @@ | ||
package repository | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
"os" | ||
"time" | ||
|
||
"github.com/DATA-DOG/go-txdb" | ||
"github.com/jmoiron/sqlx" | ||
_ "github.com/lib/pq" | ||
) | ||
|
||
func init() { | ||
txdb.Register("pgx", "postgres", os.Getenv("POSTMAND_DATABASE_URL")) | ||
rand.Seed(time.Now().UnixNano()) | ||
} | ||
|
||
type testHelper struct { | ||
db *sqlx.DB | ||
webhookRepository *Webhook | ||
} | ||
|
||
func newTestHelper() testHelper { | ||
cName := fmt.Sprintf("connection_%d", time.Now().UnixNano()) | ||
db, _ := sqlx.Open("pgx", cName) | ||
return testHelper{ | ||
db: db, | ||
webhookRepository: NewWebhook(db), | ||
} | ||
} |
Oops, something went wrong.