Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SetBodilessMatcher & SetDefaultMatcher take RecordingOptions #22405

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sdk/internal/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Release History

## 1.5.3 (Unreleased)
## 1.6.0 (Unreleased)

### Features Added
* Options types for `SetBodilessMatcher` and `SetDefaultMatcher` now embed `RecordingOptions`

### Breaking Changes

Expand Down
17 changes: 13 additions & 4 deletions sdk/internal/recording/matchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,30 @@ import (
"fmt"
"io"
"net/http"
"reflect"
"strings"
"testing"
)

// Optional parameters for the SetBodilessMatcher operation
type MatcherOptions struct {
RecordingOptions
}

// SetBodilessMatcher adjusts the "match" operation to exclude the body when matching a request to a recording's entries.
// Pass in `nil` for `t` if you want the bodiless matcher to apply everywhere
func SetBodilessMatcher(t *testing.T, options *MatcherOptions) error {
f := false
return SetDefaultMatcher(t, &SetDefaultMatcherOptions{
CompareBodies: &f,
})
o := SetDefaultMatcherOptions{CompareBodies: &f}
if options != nil {
o.RecordingOptions = options.RecordingOptions
}
return SetDefaultMatcher(t, &o)
}

type SetDefaultMatcherOptions struct {
RecordingOptions

CompareBodies *bool
ExcludedHeaders []string
IgnoredHeaders []string
Expand All @@ -53,6 +59,9 @@ func (s *SetDefaultMatcherOptions) fillOptions() {
if s.IgnoreQueryOrdering == nil {
s.IgnoreQueryOrdering = &f
}
if reflect.ValueOf(s.RecordingOptions).IsZero() {
s.RecordingOptions = *defaultOptions()
}
}

func addDefaults(added []string) []string {
Expand All @@ -77,7 +86,7 @@ func SetDefaultMatcher(t *testing.T, options *SetDefaultMatcherOptions) error {
return nil
}
options.fillOptions()
url := fmt.Sprintf("%s/Admin/SetMatcher", defaultOptions().baseURL())
url := fmt.Sprintf("%s/Admin/SetMatcher", options.baseURL())
req, err := http.NewRequest("POST", url, http.NoBody)
if err != nil {
panic(err)
Expand Down
22 changes: 22 additions & 0 deletions sdk/internal/recording/matchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,35 @@ package recording
import (
"bytes"
"net/http"
"net/url"
"os"
"strconv"
"testing"

"github.com/Azure/azure-sdk-for-go/sdk/internal/mock"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)

func TestSetMatcherRecordingOptions(t *testing.T) {
srv, close := mock.NewServer()
defer close()
srv.SetResponse(mock.WithStatusCode(http.StatusOK))
parsed, err := url.Parse(srv.URL())
require.NoError(t, err)
port, err := strconv.ParseInt(parsed.Port(), 10, 0)
require.NoError(t, err)
ro := RecordingOptions{ProxyPort: int(port)}
t.Run("SetBodilessMatcher", func(t *testing.T) {
err := SetBodilessMatcher(t, &MatcherOptions{RecordingOptions: ro})
require.NoError(t, err)
})
t.Run("SetDefaultMatcher", func(t *testing.T) {
err = SetDefaultMatcher(nil, &SetDefaultMatcherOptions{RecordingOptions: ro})
require.NoError(t, err)
})
}

type matchersTests struct {
suite.Suite
proxy *TestProxyInstance
Expand Down
2 changes: 1 addition & 1 deletion sdk/internal/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ const (
Module = "internal"

// Version is the semantic version (see http://semver.org) of this module.
Version = "v1.5.3"
Version = "v1.6.0"
)