Skip to content

Commit 8c0eff3

Browse files
LukasParkedaveshanley
authored andcommitted
Add unit tests for underOpenAPIExamplePath function
- Introduced a new test function, TestUnderOpenAPIExamplePath, to validate the behavior of underOpenAPIExamplePath. - Added various test cases to check for correct identification of paths under OpenAPI example and examples segments. - Ensured comprehensive coverage for edge cases, including empty paths and paths not fully under example segments.
1 parent efc5ceb commit 8c0eff3

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

index/extract_refs_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,3 +711,22 @@ components:
711711
func TestSpecIndex_isExternalReference_Nil(t *testing.T) {
712712
assert.False(t, isExternalReference(nil))
713713
}
714+
715+
func TestUnderOpenAPIExamplePath(t *testing.T) {
716+
tests := []struct {
717+
name string
718+
path []string
719+
want bool
720+
}{
721+
{"empty", nil, false},
722+
{"no_example_segments", []string{"paths", "get", "responses", "200", "content", "application/json", "schema"}, false},
723+
{"under_example", []string{"paths", "get", "responses", "200", "content", "application/json", "schema", "example"}, true},
724+
{"under_examples", []string{"content", "application/json", "schema", "examples", "sample", "value"}, true},
725+
{"example_not_whole_segment", []string{"paths", "exampled"}, false},
726+
}
727+
for _, tt := range tests {
728+
t.Run(tt.name, func(t *testing.T) {
729+
assert.Equal(t, tt.want, underOpenAPIExamplePath(tt.path))
730+
})
731+
}
732+
}

0 commit comments

Comments
 (0)