Skip to content

Commit 0617ff6

Browse files
authored
test: fix bug in test and update test manifest (#17)
This fixes a bug in the test where if multiple files are to be validated by the test, the test incorrectly `returns` from a `for` loop that asserts the correctness of multiple expected files when the first expected file succeeds validation. As a result, the manifest for testpkg2.json was never updated as the code evolved, and is incorrect in its current form. Signed-off-by: Shashank Ram <[email protected]>
1 parent c748e10 commit 0617ff6

File tree

3 files changed

+50
-49
lines changed

3 files changed

+50
-49
lines changed

changelog/v0.1.2/fix-test.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
changelog:
2+
- type: FIX
3+
description: Fix bug in test pertaining to incorrect validation of expected files.
4+
issueLink: https://github.com/solo-io/protoc-gen-openapi/issues/18
5+
resolvesIssue: true

integration_test.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package main
1616

1717
import (
1818
"bytes"
19-
"io/ioutil"
2019
"os"
2120
"os/exec"
2221
"path/filepath"
@@ -27,7 +26,7 @@ import (
2726
const goldenDir = "testdata/golden/"
2827

2928
func TestOpenAPIGeneration(t *testing.T) {
30-
var testcases = []struct {
29+
testcases := []struct {
3130
name string
3231
perPackage bool
3332
genOpts string
@@ -55,7 +54,7 @@ func TestOpenAPIGeneration(t *testing.T) {
5554

5655
for _, tc := range testcases {
5756
t.Run(tc.name, func(t *testing.T) {
58-
tempDir, err := ioutil.TempDir("", "openapi-temp")
57+
tempDir, err := os.MkdirTemp("", "openapi-temp")
5958
if err != nil {
6059
t.Fatal(err)
6160
}
@@ -93,7 +92,7 @@ func TestOpenAPIGeneration(t *testing.T) {
9392
wantPath := goldenDir + file
9493
// we are looking for the same file name in the generated path
9594
genPath := filepath.Join(tempDir, filepath.Base(wantPath))
96-
got, err := ioutil.ReadFile(genPath)
95+
got, err := os.ReadFile(genPath)
9796
if err != nil {
9897
if os.IsNotExist(err) {
9998
t.Fatalf("expected generated file %v does not exist: %v", genPath, err)
@@ -102,13 +101,13 @@ func TestOpenAPIGeneration(t *testing.T) {
102101
}
103102
}
104103

105-
want, err := ioutil.ReadFile(wantPath)
104+
want, err := os.ReadFile(wantPath)
106105
if err != nil {
107106
t.Errorf("error reading the golden file: %v", err)
108107
}
109108

110109
if bytes.Equal(got, want) {
111-
return
110+
continue
112111
}
113112

114113
cmd := exec.Command("diff", "-u", wantPath, genPath)

testdata/golden/testpkg2.json

+40-43
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,54 @@
44
"schemas": {
55
"testpkg2.AEnum": {
66
"enum": [
7-
[
8-
"ONE",
9-
"TWO",
10-
"THREE"
11-
]
7+
"ONE",
8+
"TWO",
9+
"THREE"
1210
],
1311
"type": "string"
1412
},
1513
"testpkg2.MessageOneOf": {
1614
"properties": {
17-
"port": {
18-
"oneOf": [
19-
{
20-
"description": "Valid port number",
21-
"format": "int32",
22-
"type": "integer"
23-
},
24-
{
25-
"type": "string"
26-
}
27-
]
15+
"name": {
16+
"type": "string"
17+
},
18+
"number": {
19+
"description": "Valid port number",
20+
"format": "int32",
21+
"type": "integer"
2822
}
2923
},
3024
"type": "object"
3125
},
3226
"testpkg2.Test3": {
3327
"description": "Test3 is a message that I use for testing.",
3428
"properties": {
35-
"OneofField": {
36-
"oneOf": [
37-
{
38-
"type": "string"
39-
},
40-
{
41-
"type": "string"
42-
}
43-
]
44-
},
4529
"aEnum": {
4630
"enum": [
47-
[
48-
"ONE",
49-
"TWO",
50-
"THREE"
51-
]
31+
"ONE",
32+
"TWO",
33+
"THREE"
5234
],
5335
"type": "string"
5436
},
37+
"deprecate": {
38+
"type": "string"
39+
},
5540
"field1": {
5641
"description": "field1 is a field",
5742
"format": "int32",
5843
"type": "integer"
5944
},
45+
"field17": {
46+
"format": "int64",
47+
"type": "integer",
48+
"x-kubernetes-int-or-string": true
49+
},
50+
"field18": {
51+
"format": "int64",
52+
"type": "integer",
53+
"x-kubernetes-int-or-string": true
54+
},
6055
"field3": {
6156
"type": "number"
6257
},
@@ -98,21 +93,23 @@
9893
"messageOneOfField": {
9994
"description": "messageoneof comment",
10095
"properties": {
101-
"port": {
102-
"oneOf": [
103-
{
104-
"description": "Valid port number",
105-
"format": "int32",
106-
"type": "integer"
107-
},
108-
{
109-
"type": "string"
110-
}
111-
]
96+
"name": {
97+
"type": "string"
98+
},
99+
"number": {
100+
"description": "Valid port number",
101+
"format": "int32",
102+
"type": "integer"
112103
}
113104
},
114105
"type": "object"
115106
},
107+
"oneoffield1": {
108+
"type": "string"
109+
},
110+
"oneoffield2": {
111+
"type": "string"
112+
},
116113
"str": {
117114
"description": "an array of strings",
118115
"items": {
@@ -150,7 +147,7 @@
150147
},
151148
"info": {
152149
"title": "OpenAPI Spec for Solo APIs.",
153-
"version": ""
150+
"version": "testpkg2"
154151
},
155152
"paths": null
156153
}

0 commit comments

Comments
 (0)