Skip to content

Commit

Permalink
Adjust gatewayTags tests to account for ShouldOmit
Browse files Browse the repository at this point in the history
  • Loading branch information
titpetric committed Jun 15, 2022
1 parent 493ec32 commit 9c0a1df
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 2 additions & 0 deletions apidef/oas/oas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func TestOAS(t *testing.T) {
t.Parallel()

var nilOASPaths OAS
nilOASPaths.SetTykExtension(&XTykAPIGateway{})

var convertedAPI apidef.APIDefinition
nilOASPaths.ExtractTo(&convertedAPI)
Expand All @@ -44,6 +45,7 @@ func TestOAS(t *testing.T) {

// No paths in base OAS produce empty paths{} when converted back
nilOASPaths.Paths = make(openapi3.Paths)
nilOASPaths.Extensions = nil
assert.Equal(t, nilOASPaths, resultOAS)
})

Expand Down
2 changes: 1 addition & 1 deletion apidef/oas/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *Server) Fill(api apidef.APIDefinition) {
s.GatewayTags = &GatewayTags{}
}
s.GatewayTags.Fill(api)
if len(s.GatewayTags.Tags) == 0 {
if ShouldOmit(s.GatewayTags) {
s.GatewayTags = nil
}

Expand Down
15 changes: 9 additions & 6 deletions apidef/oas/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@ func TestGatewayTags(t *testing.T) {
},
{
input: GatewayTags{Enabled: true},
want: GatewayTags{},
omit: true,
want: GatewayTags{Enabled: true},
},
{
input: GatewayTags{Enabled: true, Tags: []string{}},
want: GatewayTags{},
omit: true,
want: GatewayTags{Enabled: true, Tags: []string{}},
},
{
input: GatewayTags{Enabled: true, Tags: []string{"test"}},
Expand Down Expand Up @@ -281,12 +279,17 @@ func TestTagsExportServer(t *testing.T) {
TagsDisabled: true,
Tags: []string{"a", "b", "c"},
},
nil,
&GatewayTags{
Enabled: false,
Tags: []string{"a", "b", "c"},
},
},
{
"empty segment tags",
apidef.APIDefinition{},
nil,
&GatewayTags{
Enabled: true,
},
},
}

Expand Down

0 comments on commit 9c0a1df

Please sign in to comment.