Skip to content

Commit 4554d8b

Browse files
test: windows
1 parent fdaf2f4 commit 4554d8b

File tree

7 files changed

+115
-14
lines changed

7 files changed

+115
-14
lines changed

.github/workflows/commits.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ on:
88
- edited
99
- synchronize
1010
- ready_for_review
11-
1211
jobs:
1312
build:
1413
name: Conventional Commits
1514
runs-on: ubuntu-latest
1615
steps:
17-
- uses: actions/checkout@v4
18-
- uses: webiny/[email protected]
19-
- uses: amannn/[email protected]
16+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
17+
- uses: webiny/action-conventional-commits@8bc41ff4e7d423d56fa4905f6ff79209a78776c7 # v1.3.0
18+
- uses: amannn/action-semantic-pull-request@0723387faaf9b38adef4775cd42cfd5155ed6017 # v5.5.3
2019
env:
2120
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

internal/utils/references_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package utils
22

33
import (
4+
"path/filepath"
45
"testing"
56

67
"github.com/stretchr/testify/assert"
@@ -393,7 +394,8 @@ func TestReferenceClassification_JoinWith_Success(t *testing.T) {
393394

394395
result, err := classification.JoinWith(tt.relative)
395396
require.NoError(t, err)
396-
assert.Equal(t, tt.expected, result)
397+
// Clean both paths to normalize separators for cross-platform compatibility
398+
assert.Equal(t, filepath.Clean(tt.expected), filepath.Clean(result))
397399
})
398400
}
399401
}
@@ -459,7 +461,8 @@ func TestJoinReference_Success(t *testing.T) {
459461
t.Parallel()
460462
result, err := JoinReference(tt.base, tt.relative)
461463
require.NoError(t, err)
462-
assert.Equal(t, tt.expected, result)
464+
// Clean both paths to normalize separators for cross-platform compatibility
465+
assert.Equal(t, filepath.Clean(tt.expected), filepath.Clean(result))
463466
})
464467
}
465468
}

jsonschema/oas3/inline_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"io"
99
"io/fs"
10+
"path/filepath"
1011
"strings"
1112
"testing"
1213

@@ -31,11 +32,15 @@ func NewMockVirtualFS() *MockVirtualFS {
3132
}
3233

3334
func (m *MockVirtualFS) AddFile(path, content string) {
34-
m.files[path] = content
35+
// Normalize path separators for cross-platform compatibility
36+
normalizedPath := filepath.ToSlash(path)
37+
m.files[normalizedPath] = content
3538
}
3639

3740
func (m *MockVirtualFS) Open(name string) (fs.File, error) {
38-
content, exists := m.files[name]
41+
// Normalize path separators for cross-platform compatibility
42+
normalizedName := filepath.ToSlash(name)
43+
content, exists := m.files[normalizedName]
3944
if !exists {
4045
return nil, fmt.Errorf("file not found: %s", name)
4146
}

jsonschema/oas3/resolution_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,15 @@ func NewMockVirtualFS() *MockVirtualFS {
7272
}
7373

7474
func (m *MockVirtualFS) AddFile(path, content string) {
75-
m.files[path] = content
75+
// Normalize path separators for cross-platform compatibility
76+
normalizedPath := filepath.ToSlash(path)
77+
m.files[normalizedPath] = content
7678
}
7779

7880
func (m *MockVirtualFS) Open(name string) (fs.File, error) {
79-
content, exists := m.files[name]
81+
// Normalize path separators for cross-platform compatibility
82+
normalizedName := filepath.ToSlash(name)
83+
content, exists := m.files[normalizedName]
8084
if !exists {
8185
return nil, fmt.Errorf("file not found: %s", name)
8286
}
@@ -856,7 +860,13 @@ func TestJSONSchema_Resolve_FileSystemIntegration(t *testing.T) {
856860
assert.Nil(t, validationErrs)
857861
result := schema.GetResolvedSchema()
858862
assert.Nil(t, result)
859-
assert.Contains(t, err.Error(), "no such file or directory")
863+
// Check for platform-agnostic file not found error
864+
errMsg := err.Error()
865+
assert.True(t,
866+
strings.Contains(errMsg, "no such file or directory") ||
867+
strings.Contains(errMsg, "The system cannot find the file specified") ||
868+
strings.Contains(errMsg, "cannot find the file"),
869+
"Expected file not found error, got: %s", errMsg)
860870
})
861871
}
862872

marshaller/unmarshaller.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ type Unmarshallable interface {
3131

3232
// Unmarshal will unmarshal the provided document into the specified model.
3333
func Unmarshal[T any](ctx context.Context, doc io.Reader, out CoreAccessor[T]) ([]error, error) {
34+
if out == nil || reflect.ValueOf(out).IsNil() {
35+
return nil, errors.New("out parameter cannot be nil")
36+
}
37+
3438
data, err := io.ReadAll(doc)
3539
if err != nil {
3640
return nil, fmt.Errorf("failed to read document: %w", err)
@@ -58,6 +62,10 @@ func Unmarshal[T any](ctx context.Context, doc io.Reader, out CoreAccessor[T]) (
5862
// UnmarshalNode will unmarshal the provided node into the provided model.
5963
// This method is useful for unmarshaling partial documents, for a full document use Unmarshal as it will retain the full document structure.
6064
func UnmarshalNode[T any](ctx context.Context, node *yaml.Node, out CoreAccessor[T]) ([]error, error) {
65+
if out == nil || reflect.ValueOf(out).IsNil() {
66+
return nil, errors.New("out parameter cannot be nil")
67+
}
68+
6169
core := out.GetCore()
6270

6371
validationErrs, err := UnmarshalCore(ctx, node, core)

marshaller/unmarshalling_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"testing"
77

88
"github.com/speakeasy-api/openapi/marshaller"
9+
"github.com/speakeasy-api/openapi/marshaller/tests"
910
"github.com/speakeasy-api/openapi/marshaller/tests/core"
1011
"github.com/stretchr/testify/require"
1112
"gopkg.in/yaml.v3"
@@ -897,6 +898,70 @@ put:
897898
require.Equal(t, "PUT operation", putOp.Value.StringField.Value)
898899
}
899900

901+
func TestUnmarshal_NilOut_Error(t *testing.T) {
902+
t.Parallel()
903+
904+
tts := []struct {
905+
name string
906+
yml string
907+
}{
908+
{
909+
name: "simple yaml with nil out",
910+
yml: `
911+
stringField: "test string"
912+
boolField: true
913+
intField: 42
914+
float64Field: 3.14
915+
`,
916+
},
917+
{
918+
name: "empty yaml with nil out",
919+
yml: `{}`,
920+
},
921+
}
922+
923+
for _, tt := range tts {
924+
t.Run(tt.name, func(t *testing.T) {
925+
t.Parallel()
926+
927+
// Define a nil pointer to a high-level model
928+
var model *tests.TestPrimitiveHighModel
929+
930+
// This should not panic and should return a proper error
931+
validationErrs, err := marshaller.Unmarshal(context.Background(), strings.NewReader(tt.yml), model)
932+
933+
// We expect an error, not a panic
934+
require.Error(t, err, "should return error when out is nil")
935+
require.Nil(t, validationErrs, "validation errors should be nil when there's a fundamental error")
936+
require.Contains(t, err.Error(), "out parameter cannot be nil", "error should indicate nil out parameter")
937+
})
938+
}
939+
}
940+
941+
func TestUnmarshalNode_NilOut_Error(t *testing.T) {
942+
t.Parallel()
943+
944+
yml := `
945+
stringField: "test string"
946+
boolField: true
947+
intField: 42
948+
float64Field: 3.14
949+
`
950+
951+
node := parseYAML(t, yml)
952+
953+
// Define a nil pointer to a high-level model
954+
var model *tests.TestPrimitiveHighModel
955+
956+
// This should not panic and should return a proper error
957+
validationErrs, err := marshaller.UnmarshalNode(context.Background(), node, model)
958+
959+
// We expect an error, not a panic
960+
require.Error(t, err, "should return error when out is nil")
961+
require.Nil(t, validationErrs, "validation errors should be nil when there's a fundamental error")
962+
require.Contains(t, err.Error(), "out parameter cannot be nil", "error should indicate nil out parameter")
963+
}
964+
900965
// Helper functions
901966
func parseYAML(t *testing.T, yml string) *yaml.Node {
902967
var node yaml.Node

references/resolution_test.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http"
99
"net/http/httptest"
1010
"os"
11+
"path/filepath"
1112
"strings"
1213
"testing"
1314

@@ -69,11 +70,15 @@ func NewMockVirtualFS() *MockVirtualFS {
6970
}
7071

7172
func (m *MockVirtualFS) AddFile(path, content string) {
72-
m.files[path] = content
73+
// Normalize path separators for cross-platform compatibility
74+
normalizedPath := filepath.ToSlash(path)
75+
m.files[normalizedPath] = content
7376
}
7477

7578
func (m *MockVirtualFS) Open(name string) (fs.File, error) {
76-
content, exists := m.files[name]
79+
// Normalize path separators for cross-platform compatibility
80+
normalizedName := filepath.ToSlash(name)
81+
content, exists := m.files[normalizedName]
7782
if !exists {
7883
return nil, fmt.Errorf("file not found: %s", name)
7984
}
@@ -597,7 +602,13 @@ func TestResolve_FileSystemIntegration(t *testing.T) {
597602
require.Error(t, err)
598603
assert.Nil(t, validationErrs)
599604
assert.Nil(t, result)
600-
assert.Contains(t, err.Error(), "no such file or directory")
605+
// Check for platform-agnostic file not found error
606+
errMsg := err.Error()
607+
assert.True(t,
608+
strings.Contains(errMsg, "no such file or directory") ||
609+
strings.Contains(errMsg, "The system cannot find the file specified") ||
610+
strings.Contains(errMsg, "cannot find the file"),
611+
"Expected file not found error, got: %s", errMsg)
601612
})
602613
}
603614

0 commit comments

Comments
 (0)