Skip to content

Commit

Permalink
Merge pull request #29 from virtru/feature/protoconv-fix
Browse files Browse the repository at this point in the history
protobuf conversion fix
  • Loading branch information
pflynn-virtru committed Nov 13, 2023
2 parents 9329a0d + 9278b2a commit f1e9121
Show file tree
Hide file tree
Showing 7 changed files with 686 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup unit test
run: go install github.com/klmitch/overcover@v1.2.1
- name: Run unit test with coverage
run: go test --coverprofile cover.out ./pdp ./attributes
run: go test --coverprofile cover.out ./pdp ./attributes ./protoconv
- name: Check coverage meets threshold
run: overcover --coverprofile cover.out ./pdp ./attributes --threshold ${{ env.COVERAGE_THRESH_PCT }}
- uses: actions/setup-python@v4
Expand Down
3 changes: 3 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
linters:
run:
skip-files:
- _test.go
# Enable specific linter
# https://golangci-lint.run/usage/linters/#enabled-by-default-linters
enable:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ dockerbuildpush: clean docker-buildx-armsetup
.PHONY: test
test: lint
@echo "Testing Go code"
@go test --coverprofile cover.out ./attributes ./pdp
@overcover --coverprofile cover.out ./attributes ./pdp --threshold $(COVERAGE_THRESH_PCT)
@go test --coverprofile cover.out ./attributes ./pdp ./protoconv
@overcover --coverprofile cover.out ./attributes ./pdp ./protoconv --threshold $(COVERAGE_THRESH_PCT)

.PHONY: lint
lint: localprep
Expand Down
327 changes: 327 additions & 0 deletions attributes/attributeclustering_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,327 @@
package attributes

import (
"reflect"
"testing"
)

func TestAttributeDefinition_GetAuthority(t *testing.T) {
type fields struct {
Authority string
Name string
Rule string
State string
Order []string
GroupBy *AttributeInstance
}
tests := []struct {
name string
fields fields
want string
}{
{
name: "positive",
fields: fields{
Authority: "myauthority",
Name: "",
Rule: "",
State: "",
Order: nil,
GroupBy: nil,
},
want: "myauthority",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
attrdef := AttributeDefinition{
Authority: tt.fields.Authority,
Name: tt.fields.Name,
Rule: tt.fields.Rule,
State: tt.fields.State,
Order: tt.fields.Order,
GroupBy: tt.fields.GroupBy,
}
if got := attrdef.GetAuthority(); got != tt.want {
t.Errorf("GetAuthority() = %v, want %v", got, tt.want)
}
})
}
}

func TestAttributeDefinition_GetCanonicalName(t *testing.T) {
type fields struct {
Authority string
Name string
Rule string
State string
Order []string
GroupBy *AttributeInstance
}
tests := []struct {
name string
fields fields
want string
}{
{
name: "positive",
fields: fields{
Authority: "a",
Name: "b",
Rule: "c",
State: "d",
Order: nil,
GroupBy: nil,
},
want: "a/attr/b",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
attrdef := AttributeDefinition{
Authority: tt.fields.Authority,
Name: tt.fields.Name,
Rule: tt.fields.Rule,
State: tt.fields.State,
Order: tt.fields.Order,
GroupBy: tt.fields.GroupBy,
}
if got := attrdef.GetCanonicalName(); got != tt.want {
t.Errorf("GetCanonicalName() = %v, want %v", got, tt.want)
}
})
}
}

func TestAttributeInstance_GetAuthority(t *testing.T) {
type fields struct {
Authority string
Name string
Value string
}
tests := []struct {
name string
fields fields
want string
}{
{
name: "positive",
fields: fields{
Authority: "a",
Name: "b",
Value: "c",
},
want: "a",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
attrdef := AttributeInstance{
Authority: tt.fields.Authority,
Name: tt.fields.Name,
Value: tt.fields.Value,
}
if got := attrdef.GetAuthority(); got != tt.want {
t.Errorf("GetAuthority() = %v, want %v", got, tt.want)
}
})
}
}

func TestAttributeInstance_GetCanonicalName(t *testing.T) {
type fields struct {
Authority string
Name string
Value string
}
tests := []struct {
name string
fields fields
want string
}{
{
name: "positive",
fields: fields{
Authority: "a",
Name: "b",
Value: "c",
},
want: "a/attr/b",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
attr := AttributeInstance{
Authority: tt.fields.Authority,
Name: tt.fields.Name,
Value: tt.fields.Value,
}
if got := attr.GetCanonicalName(); got != tt.want {
t.Errorf("GetCanonicalName() = %v, want %v", got, tt.want)
}
})
}
}

func TestAttributeInstance_String(t *testing.T) {
type fields struct {
Authority string
Name string
Value string
}
tests := []struct {
name string
fields fields
want string
}{
{
name: "positive",
fields: fields{
Authority: "a",
Name: "b",
Value: "c",
},
want: "a/attr/b/value/c",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
attr := AttributeInstance{
Authority: tt.fields.Authority,
Name: tt.fields.Name,
Value: tt.fields.Value,
}
if got := attr.String(); got != tt.want {
t.Errorf("String() = %v, want %v", got, tt.want)
}
})
}
}

func TestClusterByAuthority(t *testing.T) {
type args[attrCluster Clusterable] struct {
attrs []attrCluster
}
type testCase[attrCluster Clusterable] struct {
name string
args args[attrCluster]
want map[string][]attrCluster
}
tests := []testCase[AttributeDefinition]{
{
name: "positive",
args: args[AttributeDefinition]{},
want: make(map[string][]AttributeDefinition),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ClusterByAuthority(tt.args.attrs); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ClusterByAuthority() = %v, want %v", got, tt.want)
}
})
}
}

func TestClusterByCanonicalName(t *testing.T) {
type args[attrCluster Clusterable] struct {
attrs []attrCluster
}
type testCase[attrCluster Clusterable] struct {
name string
args args[attrCluster]
want map[string][]attrCluster
}
tests := []testCase[AttributeDefinition]{
{
name: "positive",
args: args[AttributeDefinition]{},
want: make(map[string][]AttributeDefinition),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ClusterByCanonicalName(tt.args.attrs); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ClusterByCanonicalName() = %v, want %v", got, tt.want)
}
})
}
}

func TestParseInstanceFromParts(t *testing.T) {
type args struct {
namespace string
name string
value string
}
tests := []struct {
name string
args args
want AttributeInstance
wantErr bool
}{
{
name: "positive",
args: args{
namespace: "https://a",
name: "b",
value: "c",
},
want: AttributeInstance{
Authority: "https://a",
Name: "b",
Value: "c",
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := ParseInstanceFromParts(tt.args.namespace, tt.args.name, tt.args.value)
if (err != nil) != tt.wantErr {
t.Errorf("ParseInstanceFromParts() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("ParseInstanceFromParts() got = %v, want %v", got, tt.want)
}
})
}
}

func TestParseInstanceFromURI(t *testing.T) {
type args struct {
attributeURI string
}
tests := []struct {
name string
args args
want AttributeInstance
wantErr bool
}{
{
name: "positive",
args: args{
attributeURI: "https://a/attr/b/value/c",
},
want: AttributeInstance{
Authority: "https://a",
Name: "b",
Value: "c",
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := ParseInstanceFromURI(tt.args.attributeURI)
if (err != nil) != tt.wantErr {
t.Errorf("ParseInstanceFromURI() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("ParseInstanceFromURI() got = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit f1e9121

Please sign in to comment.