From 260734496d55d0cc12aee2c4264305e70a3b8268 Mon Sep 17 00:00:00 2001 From: syordanov94 Date: Fri, 26 Jan 2024 12:10:45 +0100 Subject: [PATCH] changes after PR review --- consumer.go | 5 ++- validator/validator.go => validator.go | 2 +- .../validator_test.go => validator_test.go | 33 +++++++++---------- 3 files changed, 19 insertions(+), 21 deletions(-) rename validator/validator.go => validator.go (99%) rename validator/validator_test.go => validator_test.go (91%) diff --git a/consumer.go b/consumer.go index 73067ae..f2aa495 100644 --- a/consumer.go +++ b/consumer.go @@ -27,7 +27,6 @@ import ( "golang.org/x/sync/semaphore" "go.dataddo.com/pgq/internal/pg" - "go.dataddo.com/pgq/validator" ) type fatalError struct { @@ -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") } diff --git a/validator/validator.go b/validator.go similarity index 99% rename from validator/validator.go rename to validator.go index 7d92bbd..356ca8f 100644 --- a/validator/validator.go +++ b/validator.go @@ -1,4 +1,4 @@ -package validator +package pgq import ( "database/sql" diff --git a/validator/validator_test.go b/validator_test.go similarity index 91% rename from validator/validator_test.go rename to validator_test.go index 473c394..46a4c66 100644 --- a/validator/validator_test.go +++ b/validator_test.go @@ -1,4 +1,4 @@ -package validator +package pgq import ( "context" @@ -6,6 +6,7 @@ import ( "database/sql" "encoding/base64" "fmt" + "os" "testing" "go.dataddo.com/pgq/internal/pg" @@ -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() @@ -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