|
1 | 1 | package docs |
2 | 2 |
|
3 | | -import "testing" |
| 3 | +import ( |
| 4 | + "bytes" |
| 5 | + "testing" |
| 6 | +) |
| 7 | + |
| 8 | +const ( |
| 9 | + buildStreamTestWant = `openapi: 3.0.1 |
| 10 | +info: |
| 11 | + title: Test |
| 12 | + description: Test object |
| 13 | + termsOfService: "" |
| 14 | + contact: |
| 15 | + email: "" |
| 16 | + license: |
| 17 | + name: "" |
| 18 | + url: "" |
| 19 | + version: "" |
| 20 | +externalDocs: |
| 21 | + description: "" |
| 22 | + url: "" |
| 23 | +servers: [] |
| 24 | +tags: [] |
| 25 | +paths: {} |
| 26 | +components: |
| 27 | + schemas: |
| 28 | + schema_testing: |
| 29 | + properties: |
| 30 | + EnumProp: |
| 31 | + description: short desc |
| 32 | + enum: |
| 33 | + - enum |
| 34 | + - test |
| 35 | + - strSlc |
| 36 | + type: enum |
| 37 | + intProp: |
| 38 | + default: 1337 |
| 39 | + description: short desc |
| 40 | + format: int64 |
| 41 | + type: integer |
| 42 | + type: "" |
| 43 | + xml: |
| 44 | + name: XML entry test |
| 45 | + securitySchemes: |
| 46 | + ses_scheme_testing: |
| 47 | + flows: |
| 48 | + implicit: |
| 49 | + authorizationUrl: http://petstore.swagger.io/oauth/dialog |
| 50 | + scopes: |
| 51 | + read:pets: Read Pets |
| 52 | + write:pets: Write to Pets |
| 53 | + in: not empty |
| 54 | +` |
| 55 | +) |
4 | 56 |
|
5 | 57 | func TestUnitBuild(t *testing.T) { |
6 | 58 | t.Parallel() |
@@ -109,3 +161,68 @@ func TestUnitGetPathFromFirstElem(t *testing.T) { |
109 | 161 | } |
110 | 162 |
|
111 | 163 | // QUICK CHECK TESTS ARE COMING WITH NEXT RELEASE. |
| 164 | + |
| 165 | +func TestOAS_BuildStream(t *testing.T) { |
| 166 | + t.Parallel() |
| 167 | + |
| 168 | + tests := []struct { |
| 169 | + name string |
| 170 | + oas *OAS |
| 171 | + wantW string |
| 172 | + wantErr bool |
| 173 | + }{ |
| 174 | + { |
| 175 | + name: "success", |
| 176 | + oas: &OAS{ |
| 177 | + OASVersion: "3.0.1", |
| 178 | + Info: Info{Title: "Test", Description: "Test object"}, |
| 179 | + Components: Components{ |
| 180 | + Component{ |
| 181 | + Schemas: Schemas{Schema{ |
| 182 | + Name: "schema_testing", |
| 183 | + Properties: SchemaProperties{ |
| 184 | + SchemaProperty{ |
| 185 | + Name: "EnumProp", Type: "enum", Description: "short desc", |
| 186 | + Enum: []string{"enum", "test", "strSlc"}, |
| 187 | + }, |
| 188 | + SchemaProperty{ |
| 189 | + Name: "intProp", Type: "integer", Format: "int64", |
| 190 | + Description: "short desc", Default: 1337, |
| 191 | + }, |
| 192 | + }, |
| 193 | + XML: XMLEntry{Name: "XML entry test"}, |
| 194 | + }}, |
| 195 | + SecuritySchemes: SecuritySchemes{SecurityScheme{ |
| 196 | + Name: "ses_scheme_testing", |
| 197 | + In: "not empty", |
| 198 | + Flows: SecurityFlows{SecurityFlow{ |
| 199 | + Type: "implicit", |
| 200 | + AuthURL: "http://petstore.swagger.io/oauth/dialog", |
| 201 | + Scopes: SecurityScopes{ |
| 202 | + SecurityScope{Name: "write:pets", Description: "Write to Pets"}, |
| 203 | + SecurityScope{Name: "read:pets", Description: "Read Pets"}, |
| 204 | + }, |
| 205 | + }}, |
| 206 | + }}, |
| 207 | + }, |
| 208 | + }, |
| 209 | + }, |
| 210 | + wantErr: false, |
| 211 | + wantW: buildStreamTestWant, |
| 212 | + }, |
| 213 | + } |
| 214 | + |
| 215 | + t.Parallel() |
| 216 | + for _, tt := range tests { |
| 217 | + t.Run(tt.name, func(t *testing.T) { |
| 218 | + w := &bytes.Buffer{} |
| 219 | + if err := tt.oas.BuildStream(w); (err != nil) != tt.wantErr { |
| 220 | + t.Errorf("OAS.BuildStream() error = %v, wantErr %v", err, tt.wantErr) |
| 221 | + return |
| 222 | + } |
| 223 | + if gotW := w.String(); gotW != tt.wantW { |
| 224 | + t.Errorf("OAS.BuildStream() = [%v], want {%v}", gotW, tt.wantW) |
| 225 | + } |
| 226 | + }) |
| 227 | + } |
| 228 | +} |
0 commit comments