Skip to content
Merged
15 changes: 11 additions & 4 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions clients/destination_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !windows
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See issue #354


package clients

import (
Expand Down
2 changes: 2 additions & 0 deletions clients/source_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !windows
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue #354


package clients

import (
Expand Down
2 changes: 2 additions & 0 deletions codegen/template_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !windows
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want cross platform snapshot tests 🐰 πŸ•³οΈ


package codegen

import (
Expand Down
2 changes: 2 additions & 0 deletions plugins/source_docs_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !windows
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want cross platform snapshot tests 🐰 πŸ•³οΈ


package plugins

import (
Expand Down
4 changes: 3 additions & 1 deletion specs/spec_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
60 changes: 41 additions & 19 deletions specs/spec_reader_test.go
Original file line number Diff line number Diff line change
@@ -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,
},
Expand All @@ -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)
Expand Down