Skip to content

Commit

Permalink
unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Reuven committed Jan 22, 2024
1 parent 4193174 commit bc58315
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
12 changes: 6 additions & 6 deletions diff/parameters_diff_by_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ type ParamNamesByLocation map[string]utils.StringList

// Len returns the number of all params in all locations
func (params ParamNamesByLocation) Len() int {
result := 0
for _, l := range params {
result += l.Len()
}
return result
return lenNested(params)
}

// ParamDiffByLocation maps param location (path, query, header or cookie) to param diffs in this location
type ParamDiffByLocation map[string]ParamDiffs

// Len returns the number of all params in all locations
func (params ParamDiffByLocation) Len() int {
return lenNested(params)
}

func lenNested[T utils.StringList | ParamDiffs](mapOfList map[string]T) int {
result := 0
for _, l := range params {
for _, l := range mapOfList {
result += len(l)
}
return result
Expand Down
23 changes: 23 additions & 0 deletions diff/parameters_diff_by_location_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package diff_test

import (
"testing"

"github.com/stretchr/testify/require"
"github.com/tufin/oasdiff/diff"
"github.com/tufin/oasdiff/utils"
)

func TestParamNamesByLocation_Len(t *testing.T) {
require.Equal(t, 3, diff.ParamNamesByLocation{
"query": utils.StringList{"name"},
"header": utils.StringList{"id", "organization"},
}.Len())
}

func TestParamDiffByLocation_Len(t *testing.T) {
require.Equal(t, 3, diff.ParamDiffByLocation{
"query": diff.ParamDiffs{"query": &diff.ParameterDiff{}},
"header": diff.ParamDiffs{"id": &diff.ParameterDiff{}, "organization": &diff.ParameterDiff{}},
}.Len())
}

0 comments on commit bc58315

Please sign in to comment.