Skip to content

Commit

Permalink
fixed test scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
kofoworola committed Jan 13, 2025
1 parent 16a5570 commit ece6491
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
10 changes: 6 additions & 4 deletions apidef/oas/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,6 @@ func (g *Global) extractTrafficLogsTo(api *apidef.APIDefinition) {
}

g.TrafficLogs.ExtractTo(api)

g.TrafficLogs.RetentionPeriod.ExtractTo(api)
}

func (g *Global) extractRequestSizeLimitTo(api *apidef.APIDefinition) {
Expand Down Expand Up @@ -1607,9 +1605,13 @@ func (t *TrafficLogs) ExtractTo(api *apidef.APIDefinition) {
api.DoNotTrack = !t.Enabled
api.TagHeaders = t.TagHeaders

if t.RetentionPeriod != nil {
t.RetentionPeriod.ExtractTo(api)
if t.RetentionPeriod == nil {
t.RetentionPeriod = &RetentionPeriod{}
defer func() {
t.RetentionPeriod = nil
}()
}
t.RetentionPeriod.ExtractTo(api)
}

// RetentionPeriod holds the configuration for analytics retention.
Expand Down
22 changes: 22 additions & 0 deletions apidef/oas/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,28 @@ func TestTrafficLogs(t *testing.T) {
resultTrafficLogs.Fill(convertedAPI)
assert.Equal(t, trafficLogs, resultTrafficLogs)
})

t.Run("retention header disabled", func(t *testing.T) {
trafficLogs := TrafficLogs{
Enabled: true,
RetentionPeriod: nil,
}

var convertedAPI apidef.APIDefinition
var resultTrafficLogs TrafficLogs

convertedAPI.SetDisabledFlags()
trafficLogs.ExtractTo(&convertedAPI)

assert.Equal(t, true, convertedAPI.DisableExpireAnalytics)
assert.Equal(t, int64(0), convertedAPI.ExpireAnalyticsAfter)

resultTrafficLogs.Fill(convertedAPI)
assert.Equal(t, &RetentionPeriod{
Enabled: false,
Value: 0,
}, resultTrafficLogs.RetentionPeriod)
})
}

func TestPluginConfig(t *testing.T) {
Expand Down

0 comments on commit ece6491

Please sign in to comment.