Skip to content

Commit

Permalink
changes after PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
syordanov94 authored and prochac committed Jan 26, 2024
1 parent aa2a455 commit 2607344
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
5 changes: 2 additions & 3 deletions consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"golang.org/x/sync/semaphore"

"go.dataddo.com/pgq/internal/pg"
"go.dataddo.com/pgq/validator"
)

type fatalError struct {
Expand Down Expand Up @@ -305,14 +304,14 @@ func (c *Consumer) verifyTable(ctx context.Context) error {

// --- (1) ----
// Validate the queue mandatory fields
err := validator.ValidateFields(c.db, c.queueName)
err := ValidateFields(c.db, c.queueName)
if err != nil {
return errors.Wrap(err, "error validating queue mandatory fields")
}

// --- (2) ----
// Validate the queue mandatory indexes
err = validator.ValidateIndexes(c.db, c.queueName)
err = ValidateIndexes(c.db, c.queueName)
if err != nil {
return errors.Wrap(err, "error validating queue mandatory indexes")
}
Expand Down
2 changes: 1 addition & 1 deletion validator/validator.go → validator.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package validator
package pgq

import (
"database/sql"
Expand Down
33 changes: 16 additions & 17 deletions validator/validator_test.go → validator_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package validator
package pgq

import (
"context"
"crypto/rand"
"database/sql"
"encoding/base64"
"fmt"
"os"
"testing"

"go.dataddo.com/pgq/internal/pg"
Expand Down Expand Up @@ -97,25 +98,14 @@ func TestValidator_ValidateIndexesIncorrectSchema(t *testing.T) {
require.Error(t, err)
}

func generateRandomString(length int) string {
b := make([]byte, length)
_, err := rand.Read(b)
if err != nil {
panic(err)
}
return base64.StdEncoding.EncodeToString(b)
}

// TODO: This was recovered from the consumer_test.go file. We can make a common testing package and add all these common
// functionalities will be included
func openDB(t *testing.T) *sql.DB {
// dsn, ok := os.LookupEnv("TEST_POSTGRES_DSN")
// if !ok {
// t.Skip("Skipping integration test, TEST_POSTGRES_DSN is not set")
// }
// db, err := sql.Open("pgx", dsn)
connectionStr := "postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable"
db, err := sql.Open("postgres", connectionStr)
dsn, ok := os.LookupEnv("TEST_POSTGRES_DSN")
if !ok {
t.Skip("Skipping integration test, TEST_POSTGRES_DSN is not set")
}
db, err := sql.Open("pgx", dsn)
require.NoError(t, err)
t.Cleanup(func() {
err := db.Close()
Expand All @@ -138,6 +128,15 @@ func ensureUUIDExtension(t *testing.T, db *sql.DB) {
require.NoError(t, err)
}

func generateRandomString(length int) string {
b := make([]byte, length)
_, err := rand.Read(b)
if err != nil {
panic(err)
}
return base64.StdEncoding.EncodeToString(b)
}

func generateInvalidQueueQuery(queueName string) string {
quotedTableName := pg.QuoteIdentifier(queueName)
return fmt.Sprintf(` CREATE TABLE IF NOT EXISTS %[1]s
Expand Down

0 comments on commit 2607344

Please sign in to comment.