Skip to content

Commit

Permalink
add response test for dynamic metadata
Browse files Browse the repository at this point in the history
Signed-off-by: tjons <tyler.schade@solo.io>
  • Loading branch information
tjons committed Nov 6, 2023
1 parent 968acb2 commit 777fd1d
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions envoyauth/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"encoding/json"
"reflect"
"testing"

_structpb "github.com/golang/protobuf/ptypes/struct"
"google.golang.org/protobuf/proto"
)

func TestIsAllowed(t *testing.T) {
Expand Down Expand Up @@ -341,3 +344,40 @@ func TestGetResponseHttpStatus(t *testing.T) {
t.Fatalf("Expected http status code \"BadRequest\" but got %v", result.GetCode().String())
}
}

func TestGetDynamicMetadata(t *testing.T) {
input := make(map[string]interface{})
er := EvalResult{
Decision: input,
}

result, err := er.GetDynamicMetadata()
if err != nil {
t.Fatalf("Expected no error but got %v", err)
}

if result != nil {
t.Fatalf("Expected no dynamic metadata but got %v", result)
}

input["dynamic_metadata"] = map[string]interface{}{
"foo": "bar",
}
result, err = er.GetDynamicMetadata()
if err != nil {
t.Fatalf("Expected no error but got %v", err)
}

expectedDynamicMetadata := &_structpb.Struct{
Fields: map[string]*_structpb.Value{
"foo": {
Kind: &_structpb.Value_StringValue{
StringValue: "bar",
},
},
},
}
if !proto.Equal(result, expectedDynamicMetadata) {
t.Fatalf("Expected result %v but got %v", expectedDynamicMetadata, result)
}
}

0 comments on commit 777fd1d

Please sign in to comment.