-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sanskarzz <sanskar.gur@gmail.com>
- Loading branch information
1 parent
40b8524
commit 9fe6978
Showing
7 changed files
with
460 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package assert | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/jmespath-community/go-jmespath/pkg/binding" | ||
tassert "github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_project(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
key any | ||
value any | ||
bindings binding.Bindings | ||
want *projection | ||
wantErr bool | ||
}{{ | ||
name: "map index not found", | ||
key: "foo", | ||
value: map[string]any{ | ||
"bar": 42, | ||
}, | ||
bindings: nil, | ||
want: nil, | ||
wantErr: false, | ||
}} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := project(context.TODO(), tt.key, tt.value, tt.bindings) | ||
if tt.wantErr { | ||
tassert.Error(t, err) | ||
tassert.Equal(t, tt.want, got) | ||
} else { | ||
tassert.NoError(t, err) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package request | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
authv3 "github.com/envoyproxy/go-control-plane/envoy/service/auth/v3" | ||
) | ||
|
||
func TestConvert(t *testing.T) { | ||
type args struct { | ||
attrs *authv3.AttributeContext | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want map[string]interface{} | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "empty AttributeContext", | ||
args: args{ | ||
attrs: &authv3.AttributeContext{ | ||
Source: nil, | ||
Destination: nil, | ||
Request: nil, | ||
ContextExtensions: nil, | ||
}, | ||
}, | ||
want: map[string]interface{}{}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "non-empty AttributeContext", | ||
args: args{ | ||
attrs: &authv3.AttributeContext{ | ||
Source: &authv3.AttributeContext_Peer{ | ||
Principal: "test-principal", | ||
}, | ||
Destination: &authv3.AttributeContext_Peer{ | ||
Principal: "test-destination", | ||
}, | ||
Request: &authv3.AttributeContext_Request{ | ||
Time: nil, | ||
Http: &authv3.AttributeContext_HttpRequest{ | ||
Method: "GET", | ||
Path: "/test", | ||
}, | ||
}, | ||
ContextExtensions: map[string]string{ | ||
"test-key": "test-value", | ||
}, | ||
}, | ||
}, | ||
want: map[string]interface{}{ | ||
"source": map[string]interface{}{ | ||
"principal": "test-principal", | ||
}, | ||
"destination": map[string]interface{}{ | ||
"principal": "test-destination", | ||
}, | ||
"request": map[string]interface{}{ | ||
"http": map[string]interface{}{ | ||
"method": "GET", | ||
"path": "/test", | ||
}, | ||
}, | ||
"contextExtensions": map[string]interface{}{ | ||
"test-key": "test-value", | ||
}, | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := Convert(tt.args.attrs) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("Convert() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("Convert() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.