From 10f8ad8c05d64f7aab893fdee0b8b52ffdebe222 Mon Sep 17 00:00:00 2001 From: erezrokah Date: Sun, 6 Nov 2022 16:40:56 +0200 Subject: [PATCH] fix: Include source path in dest to source map key --- specs/spec_reader.go | 7 ++++--- specs/spec_reader_test.go | 7 +++++++ specs/testdata/multiple_sources.yml | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 specs/testdata/multiple_sources.yml diff --git a/specs/spec_reader.go b/specs/spec_reader.go index 060262d187..358708d846 100644 --- a/specs/spec_reader.go +++ b/specs/spec_reader.go @@ -83,9 +83,10 @@ func (r *SpecReader) validate() error { if r.Destinations[destination] == nil { return fmt.Errorf("source %s references unknown destination %s", source.Name, destination) } - if destinationSourceMap[destination] == "" { - destinationSourceMap[destination] = source.Path + "@" + source.Version - } else if destinationSourceMap[destination] != source.Path+"@"+source.Version { + destinationToSourceKey := fmt.Sprintf("%s-%s", destination, source.Path) + if destinationSourceMap[destinationToSourceKey] == "" { + destinationSourceMap[destinationToSourceKey] = source.Path + "@" + source.Version + } else if destinationSourceMap[destinationToSourceKey] != source.Path+"@"+source.Version { return fmt.Errorf("destination %s is used by multiple sources %s with different versions", destination, source.Path) } } diff --git a/specs/spec_reader_test.go b/specs/spec_reader_test.go index e791db56ed..6138df8331 100644 --- a/specs/spec_reader_test.go +++ b/specs/spec_reader_test.go @@ -40,6 +40,13 @@ var specLoaderTestCases = []specLoaderTestCase{ path: []string{"testdata/gcp.yml", "testdata/gcpv2.yml"}, err: "destination postgresqlv2 is used by multiple sources cloudquery/gcp with different versions", }, + { + name: "multiple sources success", + path: []string{"testdata/multiple_sources.yml"}, + err: "", + sources: 2, + destinations: 1, + }, } func TestLoadSpecs(t *testing.T) { diff --git a/specs/testdata/multiple_sources.yml b/specs/testdata/multiple_sources.yml new file mode 100644 index 0000000000..b6b198860a --- /dev/null +++ b/specs/testdata/multiple_sources.yml @@ -0,0 +1,20 @@ +kind: source +spec: + name: aws + version: v4.6.1 + destinations: [postgresql] + path: cloudquery/aws +--- +kind: source +spec: + name: azure + version: v1.3.3 + destinations: [postgresql] + path: cloudquery/azure +--- +kind: destination +spec: + name: postgresql + version: v1.6.3 + spec: + connection_string: postgresql://postgres:pass@localhost:5432/postgres