diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 4554ee2c1b..f9395d8c46 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -8,24 +8,31 @@ on: jobs: unitests: - runs-on: ubuntu-latest + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + runs-on: ${{ matrix.os }} steps: - name: Check out code into the Go module directory uses: actions/checkout@v3 - name: Set up Go 1.x uses: actions/setup-go@v3 with: - go-version: 1.19 + go-version-file: "go.mod" cache: true - run: go mod download - run: go build ./... - name: Run tests + if: matrix.os != 'ubuntu-latest' + run: go test ./... + - name: Run tests + if: matrix.os == 'ubuntu-latest' run: go test -coverprofile=coverage.out ./... - name: Generate coverage report - if: always() + if: always() && matrix.os == 'ubuntu-latest' run: go tool cover -html coverage.out -o coverage.html - uses: actions/upload-artifact@v3 - if: always() + if: always() && matrix.os == 'ubuntu-latest' with: name: Code coverage path: coverage.html diff --git a/clients/destination_test.go b/clients/destination_test.go index a59adbbfb9..2445bcdcf4 100644 --- a/clients/destination_test.go +++ b/clients/destination_test.go @@ -1,3 +1,5 @@ +//go:build !windows + package clients import ( diff --git a/clients/source_test.go b/clients/source_test.go index e1dea405a4..1ae4d5c72d 100644 --- a/clients/source_test.go +++ b/clients/source_test.go @@ -1,3 +1,5 @@ +//go:build !windows + package clients import ( diff --git a/codegen/template_test.go b/codegen/template_test.go index befd1e7d7a..1f900b6832 100644 --- a/codegen/template_test.go +++ b/codegen/template_test.go @@ -1,3 +1,5 @@ +//go:build !windows + package codegen import ( diff --git a/plugins/source_docs_test.go b/plugins/source_docs_test.go index 79fa65ed8b..6a66a28562 100644 --- a/plugins/source_docs_test.go +++ b/plugins/source_docs_test.go @@ -1,3 +1,5 @@ +//go:build !windows + package plugins import ( diff --git a/specs/spec_reader.go b/specs/spec_reader.go index 358708d846..9d9fdb5996 100644 --- a/specs/spec_reader.go +++ b/specs/spec_reader.go @@ -20,7 +20,9 @@ func (r *SpecReader) loadSpecsFromFile(path string) error { data = []byte(os.ExpandEnv(string(data))) // support multiple yamls in one file - for _, doc := range strings.Split(string(data), "\n---\n") { + // this should work both on Windows and Unix + normalizedConfig := strings.ReplaceAll(string(data), "\r\n", "\n") + for _, doc := range strings.Split(normalizedConfig, "\n---\n") { var s Spec if err := SpecUnmarshalYamlStrict([]byte(doc), &s); err != nil { return fmt.Errorf("failed to unmarshal file %s: %w", path, err) diff --git a/specs/spec_reader_test.go b/specs/spec_reader_test.go index 6138df8331..78c6ec0c8e 100644 --- a/specs/spec_reader_test.go +++ b/specs/spec_reader_test.go @@ -1,49 +1,70 @@ package specs import ( + "path" + "runtime" "testing" ) type specLoaderTestCase struct { name string path []string - err string + err func() string sources int destinations int } +func getPath(pathParts ...string) string { + return path.Join("testdata", path.Join(pathParts...)) +} + var specLoaderTestCases = []specLoaderTestCase{ { - name: "success", - path: []string{"testdata/gcp.yml", "testdata/dir"}, - err: "", + name: "success", + path: []string{getPath("gcp.yml"), getPath("dir")}, + err: func() string { + return "" + }, sources: 2, destinations: 2, }, { name: "duplicate_source", - path: []string{"testdata/gcp.yml", "testdata/gcp.yml"}, - err: "duplicate source name gcp", + path: []string{getPath("gcp.yml"), getPath("gcp.yml")}, + err: func() string { + return "duplicate source name gcp" + }, }, { name: "no_such_file", - path: []string{"testdata/dir/no_such_file.yml", "testdata/dir/postgresql.yml"}, - err: "open testdata/dir/no_such_file.yml: no such file or directory", + path: []string{getPath("dir", "no_such_file.yml"), getPath("dir", "postgresql.yml")}, + err: func() string { + if runtime.GOOS == "windows" { + return "open testdata/dir/no_such_file.yml: The system cannot find the file specified." + } + return "open testdata/dir/no_such_file.yml: no such file or directory" + }, }, { name: "duplicate_destination", - path: []string{"testdata/dir/postgresql.yml", "testdata/dir/postgresql.yml"}, - err: "duplicate destination name postgresql", + path: []string{getPath("dir", "postgresql.yml"), getPath("dir", "postgresql.yml")}, + err: func() string { + return "duplicate destination name postgresql" + }, }, { name: "different_versions_for_destinations", - path: []string{"testdata/gcp.yml", "testdata/gcpv2.yml"}, - err: "destination postgresqlv2 is used by multiple sources cloudquery/gcp with different versions", + path: []string{getPath("gcp.yml"), getPath("gcpv2.yml")}, + err: func() string { + return "destination postgresqlv2 is used by multiple sources cloudquery/gcp with different versions" + }, }, { - name: "multiple sources success", - path: []string{"testdata/multiple_sources.yml"}, - err: "", + name: "multiple sources success", + path: []string{getPath("multiple_sources.yml")}, + err: func() string { + return "" + }, sources: 2, destinations: 1, }, @@ -53,14 +74,15 @@ func TestLoadSpecs(t *testing.T) { for _, tc := range specLoaderTestCases { t.Run(tc.name, func(t *testing.T) { specReader, err := NewSpecReader(tc.path) + expectedErr := tc.err() if err != nil { - if err.Error() != tc.err { - t.Fatalf("expected error: '%s', got: '%s'", tc.err, err) + if err.Error() != expectedErr { + t.Fatalf("expected error: '%s', got: '%s'", expectedErr, err) } return } - if tc.err != "" { - t.Fatalf("expected error: %s, got nil", tc.err) + if expectedErr != "" { + t.Fatalf("expected error: %s, got nil", expectedErr) } if len(specReader.Sources) != tc.sources { t.Fatalf("got: %d expected: %d", len(specReader.Sources), tc.sources)