-
Notifications
You must be signed in to change notification settings - Fork 22
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
10 changed files
with
222 additions
and
14 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
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
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,59 @@ | ||
package main | ||
|
||
import "testing" | ||
|
||
func TestShouldSyncTable(t *testing.T) { | ||
t.Run("returns true when no filters are set", func(t *testing.T) { | ||
config := &Config{ | ||
Pg: PgConfig{ | ||
DatabaseUrl: "postgres://user:pass@localhost:5432/db", | ||
}, | ||
} | ||
syncer := NewSyncer(config) | ||
table := SchemaTable{Schema: "public", Table: "users"} | ||
|
||
if !syncer.shouldSyncTable(table) { | ||
t.Error("Expected shouldSyncTable to return true when no filters are set") | ||
} | ||
}) | ||
|
||
t.Run("respects include filter", func(t *testing.T) { | ||
config := &Config{ | ||
Pg: PgConfig{ | ||
DatabaseUrl: "postgres://user:pass@localhost:5432/db", | ||
IncludeTables: NewSet([]string{"public.users", "public.orders"}), | ||
}, | ||
} | ||
syncer := NewSyncer(config) | ||
|
||
included := SchemaTable{Schema: "public", Table: "users"} | ||
if !syncer.shouldSyncTable(included) { | ||
t.Error("Expected shouldSyncTable to return true for included table") | ||
} | ||
|
||
excluded := SchemaTable{Schema: "public", Table: "secrets"} | ||
if syncer.shouldSyncTable(excluded) { | ||
t.Error("Expected shouldSyncTable to return false for non-included table") | ||
} | ||
}) | ||
|
||
t.Run("respects exclude filter", func(t *testing.T) { | ||
config := &Config{ | ||
Pg: PgConfig{ | ||
DatabaseUrl: "postgres://user:pass@localhost:5432/db", | ||
ExcludeTables: NewSet([]string{"public.secrets", "public.cache"}), | ||
}, | ||
} | ||
syncer := NewSyncer(config) | ||
|
||
included := SchemaTable{Schema: "public", Table: "users"} | ||
if !syncer.shouldSyncTable(included) { | ||
t.Error("Expected shouldSyncTable to return true for non-excluded table") | ||
} | ||
|
||
excluded := SchemaTable{Schema: "public", Table: "secrets"} | ||
if syncer.shouldSyncTable(excluded) { | ||
t.Error("Expected shouldSyncTable to return false for excluded table") | ||
} | ||
}) | ||
} |