Skip to content

Commit

Permalink
fix: resolved conflicts and added config test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaurav Sahil authored and Gaurav Sahil committed Oct 11, 2024
2 parents 422aa47 + 124b46e commit 853ee18
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ Creating a source or destination connector will fail in the next cases:
## Useful resources
* [Quotas and limits in Amazon Redshift](https://docs.aws.amazon.com/redshift/latest/mgmt/amazon-redshift-limits.html)

![scarf pixel](https://static.scarf.sh/a.png?x-pxid=617ebf4a-148c-44ad-8f64-6cc5780d34ae)
![scarf pixel](https://static.scarf.sh/a.png?x-pxid=dc0e518d-385c-4e33-bd1c-6b4d2eaebb74)
6 changes: 3 additions & 3 deletions common/configuration.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Meroxa, Inc. & Yalantis
// Copyright © 2024 Meroxa, Inc. & Yalantis
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -16,8 +16,8 @@ package common

const (
MaxConfigStringLength = 127
MinConfigBatchSize = 1
MaxConfigBatchSize = 100000
ConfigTable = "table"
ConfigKeyColumns = "keyColumns"
)

// Configuration contains common for source and destination configurable values.
Expand Down
2 changes: 1 addition & 1 deletion common/error.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Meroxa, Inc. & Yalantis
// Copyright © 2024 Meroxa, Inc. & Yalantis
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion destination/config/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Meroxa, Inc. & Yalantis
// Copyright © 2024 Meroxa, Inc. & Yalantis
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion destination/config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Meroxa, Inc. & Yalantis
// Copyright © 2024 Meroxa, Inc. & Yalantis
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
15 changes: 4 additions & 11 deletions source/config/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Meroxa, Inc. & Yalantis
// Copyright © 2024 Meroxa, Inc. & Yalantis
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,7 +35,7 @@ type Config struct {
// will take a snapshot of the entire table before starting cdc mode.
Snapshot bool `json:"snapshot" default:"true"`
// BatchSize is a size of rows batch.
BatchSize int `json:"batchSize" default:"1000"`
BatchSize int `json:"batchSize" default:"1000" validate:"gt=0,lt=100001"`
}

// Validate executes manual validations beyond what is defined in struct tags.
Expand Down Expand Up @@ -66,7 +66,8 @@ func (c *Config) Validate() error {
}
}

// c.OrderingColumn handling "lowercase", "excludesall= " and "lte=127" validations.
// c.OrderingColumns required validation is handled in stuct tag
// handling "lowercase", "excludesall= " and "lte=127" validations.
for i, col := range c.OrderingColumns {
if col != strings.ToLower(col) {
return common.NewLowercaseError(fmt.Sprintf("orderingColumn[%d]", i))
Expand All @@ -79,14 +80,6 @@ func (c *Config) Validate() error {
}
}

// c.BatchSize handling "gte=1" and "lte=100000" validations.
if c.BatchSize < common.MinConfigBatchSize {
return common.NewGreaterThanError(ConfigBatchSize, common.MinConfigBatchSize)
}
if c.BatchSize > common.MaxConfigBatchSize {
return common.NewLessThanError(ConfigBatchSize, common.MaxConfigBatchSize)
}

return nil
}

Expand Down
46 changes: 21 additions & 25 deletions source/config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Meroxa, Inc. & Yalantis
// Copyright © 2024 Meroxa, Inc. & Yalantis
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -154,30 +154,6 @@ func TestValidateConfig(t *testing.T) {
},
wantErr: common.NewLessThanError("orderingColumn[0]", common.MaxConfigStringLength),
},
{
name: "failure_batch_size_less_than_min_value",
in: &Config{
Configuration: common.Configuration{
DSN: testValueDSN,
},
Tables: []string{"test_table"},
OrderingColumns: []string{"id"},
BatchSize: 0,
},
wantErr: common.NewGreaterThanError(ConfigBatchSize, common.MinConfigBatchSize),
},
{
name: "failure_batch_size_greater_than_max_value",
in: &Config{
Configuration: common.Configuration{
DSN: testValueDSN,
},
Tables: []string{"test_table"},
OrderingColumns: []string{"id"},
BatchSize: 100001,
},
wantErr: common.NewLessThanError(ConfigBatchSize, common.MaxConfigBatchSize),
},
}

for _, tt := range tests {
Expand All @@ -195,3 +171,23 @@ func TestValidateConfig(t *testing.T) {
})
}
}

func TestGetTableOrderingMap(t *testing.T) {
t.Parallel()

is := is.New(t)

config := &Config{
Tables: []string{"table1", "table2"},
OrderingColumns: []string{"id1", "id2"},
}

expectedMap := map[string]string{
"table1": "id1",
"table2": "id2",
}

result := config.GetTableOrderingMap()

is.Equal(result, expectedMap)
}
5 changes: 4 additions & 1 deletion source/config/paramgen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 853ee18

Please sign in to comment.