@@ -75,7 +75,7 @@ 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 {
8181 basePath : "../../../test/data/base_spec_with_private_preview.json" ,
@@ -95,14 +95,14 @@ func TestVersion_RunStabilityLevelPreview(t *testing.T) {
9595 assert .Contains (t , string (b ), "private-preview" )
9696}
9797
98- func TestVersion_RunStabilityLevelStable (t * testing.T ) {
98+ func TestVersion_PreviewAndPublicPreview (t * testing.T ) {
9999 fs := afero .NewMemMapFs ()
100100 opts := & Opts {
101- basePath : "../../../test/data/base_spec_with_private_preview .json" ,
101+ basePath : "../../../test/data/base_spec_with_public_preview .json" ,
102102 outputPath : "foas.json" ,
103103 fs : fs ,
104104 env : "staging" ,
105- stabilityLevel : "STABLE " ,
105+ stabilityLevel : "PREVIEW " ,
106106 }
107107
108108 require .NoError (t , opts .Run ())
@@ -111,18 +111,18 @@ func TestVersion_RunStabilityLevelStable(t *testing.T) {
111111
112112 // Check initial versions
113113 assert .NotEmpty (t , b )
114- assert .Contains (t , string (b ), "2023-02-01 " )
115- assert .NotContains (t , string (b ), "private-review " )
114+ assert .NotContains (t , string (b ), "private-preview " )
115+ assert .Contains (t , string (b ), "preview " )
116116}
117117
118- func TestVersion_PreviewAndPublicPreview (t * testing.T ) {
118+ func TestVersion_RunStabilityLevelStable (t * testing.T ) {
119119 fs := afero .NewMemMapFs ()
120120 opts := & Opts {
121- basePath : "../../../test/data/base_spec_with_public_preview .json" ,
121+ basePath : "../../../test/data/base_spec_with_private_preview .json" ,
122122 outputPath : "foas.json" ,
123123 fs : fs ,
124124 env : "staging" ,
125- stabilityLevel : "PREVIEW " ,
125+ stabilityLevel : "STABLE " ,
126126 }
127127
128128 require .NoError (t , opts .Run ())
@@ -133,5 +133,87 @@ func TestVersion_PreviewAndPublicPreview(t *testing.T) {
133133 assert .NotEmpty (t , b )
134134 assert .Contains (t , string (b ), "2023-02-01" )
135135 assert .NotContains (t , string (b ), "private-preview" )
136- assert .Contains (t , string (b ), "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+ })
137219}
0 commit comments