@@ -59,7 +59,7 @@ func TestVersion_RunWithEnv(t *testing.T) {
5959func TestVersion_RunWithPreview (t * testing.T ) {
6060 fs := afero .NewMemMapFs ()
6161 opts := & Opts {
62- basePath : "../../../test/data/base_spec_with_preview .json" ,
62+ basePath : "../../../test/data/base_spec_with_private_preview .json" ,
6363 outputPath : "foas.json" ,
6464 fs : fs ,
6565 env : "staging" ,
@@ -75,10 +75,10 @@ func TestVersion_RunWithPreview(t *testing.T) {
7575 assert .Contains (t , string (b ), "preview" )
7676}
7777
78- func TestVersion_RunStabilityLevelPreview (t * testing.T ) {
78+ func TestVersion_RunStabilityLevelPreviewAndPrivatePreview (t * testing.T ) {
7979 fs := afero .NewMemMapFs ()
8080 opts := & Opts {
81- basePath : "../../../test/data/base_spec_with_preview .json" ,
81+ basePath : "../../../test/data/base_spec_with_private_preview .json" ,
8282 outputPath : "foas.json" ,
8383 fs : fs ,
8484 env : "staging" ,
@@ -92,13 +92,33 @@ func TestVersion_RunStabilityLevelPreview(t *testing.T) {
9292 // Check initial versions
9393 assert .NotEmpty (t , b )
9494 assert .NotContains (t , string (b ), "2023-02-01" )
95+ assert .Contains (t , string (b ), "private-preview" )
96+ }
97+
98+ func TestVersion_PreviewAndPublicPreview (t * testing.T ) {
99+ fs := afero .NewMemMapFs ()
100+ opts := & Opts {
101+ basePath : "../../../test/data/base_spec_with_public_preview.json" ,
102+ outputPath : "foas.json" ,
103+ fs : fs ,
104+ env : "staging" ,
105+ stabilityLevel : "PREVIEW" ,
106+ }
107+
108+ require .NoError (t , opts .Run ())
109+ b , err := afero .ReadFile (fs , opts .outputPath )
110+ require .NoError (t , err )
111+
112+ // Check initial versions
113+ assert .NotEmpty (t , b )
114+ assert .NotContains (t , string (b ), "private-preview" )
95115 assert .Contains (t , string (b ), "preview" )
96116}
97117
98118func TestVersion_RunStabilityLevelStable (t * testing.T ) {
99119 fs := afero .NewMemMapFs ()
100120 opts := & Opts {
101- basePath : "../../../test/data/base_spec_with_preview .json" ,
121+ basePath : "../../../test/data/base_spec_with_private_preview .json" ,
102122 outputPath : "foas.json" ,
103123 fs : fs ,
104124 env : "staging" ,
@@ -112,5 +132,88 @@ func TestVersion_RunStabilityLevelStable(t *testing.T) {
112132 // Check initial versions
113133 assert .NotEmpty (t , b )
114134 assert .Contains (t , string (b ), "2023-02-01" )
115- assert .NotContains (t , string (b ), "preview" )
135+ assert .NotContains (t , string (b ), "private-preview" )
136+ }
137+
138+ func TestVersion_PreRun (t * testing.T ) {
139+ t .Run ("NoBasePath" , func (t * testing.T ) {
140+ opts := & Opts {}
141+ err := opts .PreRunE (nil )
142+ require .Error (t , err )
143+ assert .Contains (t , err .Error (), "no OAS detected" )
144+ })
145+
146+ t .Run ("InvalidOutputPath" , func (t * testing.T ) {
147+ opts := & Opts {
148+ basePath : "base" ,
149+ outputPath : "output" ,
150+ }
151+ err := opts .PreRunE (nil )
152+ require .Error (t , err )
153+ assert .Contains (t , err .Error (), "output file must be either a JSON or YAML file" )
154+ })
155+
156+ t .Run ("InvalidFormat" , func (t * testing.T ) {
157+ opts := & Opts {
158+ basePath : "base" ,
159+ outputPath : "output.json" ,
160+ format : "invalid" ,
161+ }
162+ err := opts .PreRunE (nil )
163+ require .Error (t , err )
164+ assert .Contains (t , err .Error (), "output format must be either 'json' or 'yaml'" )
165+ })
166+
167+ t .Run ("ValidFormat" , func (t * testing.T ) {
168+ opts := & Opts {
169+ basePath : "base" ,
170+ outputPath : "output.json" ,
171+ format : "json" ,
172+ }
173+ err := opts .PreRunE (nil )
174+ require .NoError (t , err )
175+ })
176+
177+ t .Run ("ValidFormatYAML" , func (t * testing.T ) {
178+ opts := & Opts {
179+ basePath : "base" ,
180+ outputPath : "output.yaml" ,
181+ format : "yaml" ,
182+ }
183+ err := opts .PreRunE (nil )
184+ require .NoError (t , err )
185+ })
186+
187+ t .Run ("InvalidStabilityLevel" , func (t * testing.T ) {
188+ opts := & Opts {
189+ basePath : "base" ,
190+ outputPath : "output.yaml" ,
191+ format : "yaml" ,
192+ stabilityLevel : "invalid" ,
193+ }
194+ err := opts .PreRunE (nil )
195+ require .Error (t , err )
196+ assert .Contains (t , err .Error (), "stability level must be" )
197+ })
198+ t .Run ("ValidStabilityLevelPreview" , func (t * testing.T ) {
199+ opts := & Opts {
200+ basePath : "base" ,
201+ outputPath : "output.yaml" ,
202+ format : "yaml" ,
203+ stabilityLevel : "preview" ,
204+ }
205+ err := opts .PreRunE (nil )
206+ require .NoError (t , err )
207+ })
208+
209+ t .Run ("ValidStabilityLevelPreviewUppercase" , func (t * testing.T ) {
210+ opts := & Opts {
211+ basePath : "base" ,
212+ outputPath : "output.yaml" ,
213+ format : "yaml" ,
214+ stabilityLevel : "PREVIEW" ,
215+ }
216+ err := opts .PreRunE (nil )
217+ require .NoError (t , err )
218+ })
116219}
0 commit comments