Skip to content

Commit 75c7044

Browse files
addressed PR comments - Part 2
1 parent 8315494 commit 75c7044

File tree

4 files changed

+22
-24
lines changed

4 files changed

+22
-24
lines changed

tools/cli/internal/cli/sunset/list.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ import (
2020
"strings"
2121
"time"
2222

23+
"github.com/mongodb/openapi/tools/cli/internal/openapi"
24+
2325
"github.com/mongodb/openapi/tools/cli/internal/cli/flag"
2426
"github.com/mongodb/openapi/tools/cli/internal/cli/usage"
25-
"github.com/mongodb/openapi/tools/cli/internal/openapi"
27+
"github.com/mongodb/openapi/tools/cli/internal/openapi/sunset"
2628
"github.com/spf13/afero"
2729
"github.com/spf13/cobra"
2830
"gopkg.in/yaml.v3"
@@ -46,7 +48,7 @@ func (o *ListOpts) Run() error {
4648
return err
4749
}
4850

49-
sunsets, err := o.newSunsetInRange(openapi.NewSunsetListFromSpec(specInfo))
51+
sunsets, err := o.newSunsetInRange(sunset.NewSunsetListFromSpec(specInfo))
5052
if err != nil {
5153
return err
5254
}
@@ -63,8 +65,8 @@ func (o *ListOpts) Run() error {
6365
return nil
6466
}
6567

66-
func (o *ListOpts) newSunsetInRange(sunsets []*openapi.Sunset) ([]*openapi.Sunset, error) {
67-
var out []*openapi.Sunset
68+
func (o *ListOpts) newSunsetInRange(sunsets []*sunset.Sunset) ([]*sunset.Sunset, error) {
69+
var out []*sunset.Sunset
6870
if o.from == "" && o.to == "" {
6971
return sunsets, nil
7072
}
@@ -99,7 +101,7 @@ func isDateInRange(date, from, to *time.Time) bool {
99101
return true
100102
}
101103

102-
func (o *ListOpts) newSunsetListBytes(versions []*openapi.Sunset) ([]byte, error) {
104+
func (o *ListOpts) newSunsetListBytes(versions []*sunset.Sunset) ([]byte, error) {
103105
data, err := json.MarshalIndent(versions, "", " ")
104106
if err != nil {
105107
return nil, err

tools/cli/internal/cli/sunset/list_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
"github.com/spf13/afero"
2121
"github.com/stretchr/testify/assert"
22+
"github.com/stretchr/testify/require"
2223
)
2324

2425
func TestList_Run(t *testing.T) {
@@ -29,13 +30,8 @@ func TestList_Run(t *testing.T) {
2930
fs: fs,
3031
}
3132

32-
if err := opts.Run(); err != nil {
33-
t.Fatalf("Run() unexpected error: %v", err)
34-
}
35-
33+
require.NoError(t, opts.Run())
3634
b, err := afero.ReadFile(fs, opts.outputPath)
37-
if err != nil {
38-
t.Fatalf("ReadFile() unexpected error: %v", err)
39-
}
35+
require.NoError(t, err)
4036
assert.NotEmpty(t, b)
4137
}

tools/cli/internal/openapi/sunset.go renamed to tools/cli/internal/openapi/sunset/sunset.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package openapi
15+
package sunset
1616

1717
import (
1818
"github.com/getkin/kin-openapi/openapi3"
@@ -39,8 +39,8 @@ func NewSunsetListFromSpec(spec *load.SpecInfo) []*Sunset {
3939

4040
for path, pathBody := range paths.Map() {
4141
for operationName, operationBody := range pathBody.Operations() {
42-
teamName := newTeamNameFromOperation(operationBody)
43-
extensions := newExtensionsFrom2xxResponse(operationBody.Responses.Map())
42+
teamName := teamName(operationBody)
43+
extensions := successResponseExtensions(operationBody.Responses.Map())
4444
if extensions == nil {
4545
continue
4646
}
@@ -70,31 +70,31 @@ func NewSunsetListFromSpec(spec *load.SpecInfo) []*Sunset {
7070
return sunsets
7171
}
7272

73-
func newTeamNameFromOperation(op *openapi3.Operation) string {
73+
func teamName(op *openapi3.Operation) string {
7474
if value, ok := op.Extensions[teamExtensionName]; ok {
7575
return value.(string)
7676
}
7777
return ""
7878
}
7979

80-
func newExtensionsFrom2xxResponse(responsesMap map[string]*openapi3.ResponseRef) map[string]any {
80+
func successResponseExtensions(responsesMap map[string]*openapi3.ResponseRef) map[string]any {
8181
if val, ok := responsesMap["200"]; ok {
82-
return newExtensionsFromContent(val.Value.Content)
82+
return contentExtensions(val.Value.Content)
8383
}
8484
if val, ok := responsesMap["201"]; ok {
85-
return newExtensionsFromContent(val.Value.Content)
85+
return contentExtensions(val.Value.Content)
8686
}
8787
if val, ok := responsesMap["202"]; ok {
88-
return newExtensionsFromContent(val.Value.Content)
88+
return contentExtensions(val.Value.Content)
8989
}
9090
if val, ok := responsesMap["204"]; ok {
91-
return newExtensionsFromContent(val.Value.Content)
91+
return contentExtensions(val.Value.Content)
9292
}
9393

9494
return nil
9595
}
9696

97-
func newExtensionsFromContent(content openapi3.Content) map[string]any {
97+
func contentExtensions(content openapi3.Content) map[string]any {
9898
for _, v := range content {
9999
return v.Extensions
100100
}

tools/cli/internal/openapi/sunset_test.go renamed to tools/cli/internal/openapi/sunset/sunset_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package openapi
1+
package sunset
22

33
import (
44
"testing"
@@ -167,7 +167,7 @@ func TestNewExtensionsFrom2xxResponse(t *testing.T) {
167167

168168
for _, test := range tests {
169169
t.Run(test.name, func(t *testing.T) {
170-
result := newExtensionsFrom2xxResponse(test.responsesMap)
170+
result := successResponseExtensions(test.responsesMap)
171171
assert.Equal(t, test.expected, result)
172172
})
173173
}

0 commit comments

Comments
 (0)