From bf6e7f367e498c285f1c695496ce00705070fd35 Mon Sep 17 00:00:00 2001 From: Charles Lowell <10964656+chlowell@users.noreply.github.com> Date: Tue, 20 Feb 2024 14:34:49 -0800 Subject: [PATCH] SetBodilessMatcher & SetDefaultMatcher take RecordingOptions (#22405) --- sdk/internal/CHANGELOG.md | 3 ++- sdk/internal/recording/matchers.go | 17 +++++++++++++---- sdk/internal/recording/matchers_test.go | 22 ++++++++++++++++++++++ sdk/internal/version.go | 2 +- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/sdk/internal/CHANGELOG.md b/sdk/internal/CHANGELOG.md index 571a740a4b8c..a31046c07fb3 100644 --- a/sdk/internal/CHANGELOG.md +++ b/sdk/internal/CHANGELOG.md @@ -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 diff --git a/sdk/internal/recording/matchers.go b/sdk/internal/recording/matchers.go index cc5bb24121ac..8b377eb023fe 100644 --- a/sdk/internal/recording/matchers.go +++ b/sdk/internal/recording/matchers.go @@ -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 @@ -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 { @@ -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) diff --git a/sdk/internal/recording/matchers_test.go b/sdk/internal/recording/matchers_test.go index bf4d1f53fbcb..f0529f33ae8c 100644 --- a/sdk/internal/recording/matchers_test.go +++ b/sdk/internal/recording/matchers_test.go @@ -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 diff --git a/sdk/internal/version.go b/sdk/internal/version.go index ed4061532a6f..014c761316f6 100644 --- a/sdk/internal/version.go +++ b/sdk/internal/version.go @@ -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" )