Skip to content

Commit

Permalink
fixed unit tests (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
kristinapathak committed Feb 6, 2020
1 parent f79358f commit 2807fc6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
19 changes: 12 additions & 7 deletions basculeValidators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,31 @@ import (
func TestRequirePartnerIDs(t *testing.T) {
var tests = []struct {
name string
attributes bascule.Attributes
attrMap map[string]interface{}
shouldPass bool
}{
{
name: "partnerIDs",
attributes: map[string]interface{}{
attrMap: map[string]interface{}{
"allowedResources": map[string]interface{}{
"allowedPartners": []string{"partner0", "partner1"},
}},
shouldPass: true,
},

{
name: "no partnerIDs",
attributes: nil,
name: "no partnerIDs",
attrMap: map[string]interface{}{
"allowedResources": map[string]interface{}{
"allowedPartners": []string{},
},
},
},
{
name: "malformed partnerIDs field",
attributes: map[string]interface{}{
attrMap: map[string]interface{}{
"allowedResources": map[string]interface{}{
"allowedPartners": "partner0",
"allowedPartners": []int{0, 1, 2},
}},
},
}
Expand All @@ -41,7 +45,8 @@ func TestRequirePartnerIDs(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
assert := assert.New(t)
token := bascule.NewToken("bearer", "client0", test.attributes)
attrs := bascule.NewAttributesFromMap(test.attrMap)
token := bascule.NewToken("bearer", "client0", attrs)

err := requirePartnerIDs(ctx, token)
if test.shouldPass {
Expand Down
10 changes: 6 additions & 4 deletions primaryHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@ package main

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/xmidt-org/bascule"
"github.com/xmidt-org/webpa-common/logging"
"github.com/xmidt-org/wrp-go/wrp"
"testing"
)

func TestPopulateMessagePartners(t *testing.T) {
var tests = []struct {
name string
attributes bascule.Attributes
attrMap map[string]interface{}
expectedPartnerIDs []string
}{
{
name: "partnerIDs",
attributes: map[string]interface{}{
attrMap: map[string]interface{}{
"allowedResources": map[string]interface{}{
"allowedPartners": []string{"partner0", "partner1"},
}},
Expand All @@ -29,8 +30,9 @@ func TestPopulateMessagePartners(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
assert := assert.New(t)

attrs := bascule.NewAttributesFromMap(test.attrMap)
auth := bascule.Authentication{
Token: bascule.NewToken("bearer", "client0", test.attributes),
Token: bascule.NewToken("bearer", "client0", attrs),
}

ctx := bascule.WithAuthentication(context.Background(), auth)
Expand Down

0 comments on commit 2807fc6

Please sign in to comment.