Skip to content

Commit

Permalink
Address review comments.
Browse files Browse the repository at this point in the history
Signed-off-by: Pushpalanka Jayawardhana <pushpalanka.jayawardhana@zalando.de>
  • Loading branch information
Pushpalanka committed Feb 9, 2024
1 parent c2f054a commit 3635f3f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
12 changes: 1 addition & 11 deletions envoyauth/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ type StopFunc = func()
// TransactionCloser should be called to abort the transaction
type TransactionCloser func(ctx context.Context, err error) error

// An Opt allowing externally setting the decision ID
type Opt func(*EvalResult)

// NewEvalResult creates a new EvalResult and a StopFunc that is used to stop the timer for metrics
func NewEvalResult(opts ...Opt) (*EvalResult, StopFunc, error) {
func NewEvalResult(opts ...func(*EvalResult)) (*EvalResult, StopFunc, error) {
var err error

er := &EvalResult{
Expand Down Expand Up @@ -412,10 +409,3 @@ func transformHTTPHeaderToEnvoyHeaderValueOption(headers http.Header) ([]*ext_co

return responseHeaders, nil
}

// WithDecisionID sets the externally sent decision ID
func WithDecisionID(decisionID string) Opt {
return func(result *EvalResult) {
result.DecisionID = decisionID
}
}
17 changes: 9 additions & 8 deletions envoyauth/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,20 +398,21 @@ func TestGetDynamicMetadataWithBooleanDecision(t *testing.T) {
}

func TestNewEvalResultWithDecisionID(t *testing.T) {
type Opt func(*EvalResult)

withDecisionID := func(decisionID string) Opt {
return func(result *EvalResult) {
result.DecisionID = decisionID
}
}

expectedDecisionID := "some-decision-id"

er, _, err := NewEvalResult(WithDecisionID(expectedDecisionID))
er, _, err := NewEvalResult(withDecisionID(expectedDecisionID))
if err != nil {
t.Fatalf("NewEvalResult() error = %v, wantErr %v", err, false)
}
if er.DecisionID != expectedDecisionID {
t.Errorf("Expected DecisionID to be '%v', got '%v'", expectedDecisionID, er.DecisionID)
}
}

func TestNewEvalResultWithoutOptDecisionID(t *testing.T) {
_, _, err := NewEvalResult()
if err != nil {
t.Fatalf("NewEvalResult() error = %v", err)
}
}

0 comments on commit 3635f3f

Please sign in to comment.