observation(event): add workers list test
This commit is contained in:
2 files changed
+179
-19
No files matched your search
@@ -7,10 +7,15 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/services"
|
||||
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/scopes"
|
||||
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/workers"
|
||||
"github.com/hashicorp/eventlogger"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||
)
|
||||
|
||||
func Test_newObservation(t *testing.T) {
|
||||
@@ -320,6 +325,147 @@ func Test_composeFromTelemetryFiltering(t *testing.T) {
|
||||
Details: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "workers-list-details-with-telemetry",
|
||||
fromOp: Op("workers-list-details-with-telemetry"),
|
||||
opts: []Option{
|
||||
WithId("workers-list-details-with-telemetry"),
|
||||
WithRequestInfo(TestRequestInfo(t)),
|
||||
WithFlush(),
|
||||
WithRequest(&Request{
|
||||
Details: &services.ListWorkersRequest{
|
||||
ScopeId: "global",
|
||||
Recursive: false,
|
||||
Filter: "",
|
||||
},
|
||||
}),
|
||||
WithResponse(&Response{
|
||||
StatusCode: 200,
|
||||
Details: &services.ListWorkersResponse{
|
||||
Items: []*workers.Worker{
|
||||
{
|
||||
Id: "w_V7vkJAMxat",
|
||||
ScopeId: "global",
|
||||
Scope: &scopes.ScopeInfo{
|
||||
Id: "global",
|
||||
Type: "global",
|
||||
Name: "global",
|
||||
Description: "Global Scope",
|
||||
},
|
||||
Name: &wrapperspb.StringValue{Value: "[REDACTED]"},
|
||||
Description: &wrapperspb.StringValue{Value: "[REDACTED]"},
|
||||
CreatedTime: ×tamppb.Timestamp{
|
||||
Seconds: 1694589179,
|
||||
Nanos: 812910000,
|
||||
},
|
||||
UpdatedTime: ×tamppb.Timestamp{
|
||||
Seconds: 1694589211,
|
||||
Nanos: 371831000,
|
||||
},
|
||||
Version: 1,
|
||||
Address: "127.0.0.1:9202",
|
||||
LastStatusTime: ×tamppb.Timestamp{
|
||||
Seconds: 1694589211,
|
||||
Nanos: 371831000,
|
||||
},
|
||||
ActiveConnectionCount: nil,
|
||||
Type: "[REDACTED]",
|
||||
ReleaseVersion: "Boundary v0.13.2",
|
||||
DirectlyConnectedDownstreamWorkers: []string{"test1", "test2"},
|
||||
AuthorizedActions: []string{"read", "delete"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
WithTelemetry(),
|
||||
},
|
||||
wantObservation: &observation{
|
||||
ID: "workers-list-details-with-telemetry",
|
||||
Flush: true,
|
||||
Version: errorVersion,
|
||||
Op: Op("workers-list-details-with-telemetry"),
|
||||
RequestInfo: TestRequestInfo(t),
|
||||
Request: &Request{
|
||||
Details: &services.ListWorkersRequest{
|
||||
ScopeId: "global",
|
||||
Recursive: false,
|
||||
Filter: "",
|
||||
},
|
||||
},
|
||||
Response: &Response{
|
||||
StatusCode: 200,
|
||||
Details: &services.ListWorkersResponse{
|
||||
Items: []*workers.Worker{
|
||||
{
|
||||
Id: "w_V7vkJAMxat",
|
||||
ScopeId: "global",
|
||||
Scope: &scopes.ScopeInfo{
|
||||
Id: "global",
|
||||
Type: "global",
|
||||
Name: "global",
|
||||
Description: "Global Scope",
|
||||
},
|
||||
Name: &wrapperspb.StringValue{Value: "[REDACTED]"},
|
||||
Description: &wrapperspb.StringValue{Value: "[REDACTED]"},
|
||||
CreatedTime: ×tamppb.Timestamp{
|
||||
Seconds: 1694589179,
|
||||
Nanos: 812910000,
|
||||
},
|
||||
UpdatedTime: ×tamppb.Timestamp{
|
||||
Seconds: 1694589211,
|
||||
Nanos: 371831000,
|
||||
},
|
||||
Version: 1,
|
||||
Address: "127.0.0.1:9202",
|
||||
LastStatusTime: ×tamppb.Timestamp{
|
||||
Seconds: 1694589211,
|
||||
Nanos: 371831000,
|
||||
},
|
||||
ActiveConnectionCount: nil,
|
||||
Type: "[REDACTED]",
|
||||
ReleaseVersion: "Boundary v0.13.2",
|
||||
DirectlyConnectedDownstreamWorkers: []string{"test1", "test2"},
|
||||
AuthorizedActions: []string{"read", "delete"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantFilteredRequest: &Request{
|
||||
Details: &services.ListWorkersRequest{
|
||||
ScopeId: "global",
|
||||
},
|
||||
},
|
||||
wantFilteredResponse: &Response{
|
||||
StatusCode: 200,
|
||||
Details: &services.ListWorkersResponse{
|
||||
Items: []*workers.Worker{
|
||||
{
|
||||
Id: "w_V7vkJAMxat",
|
||||
ScopeId: "global",
|
||||
Scope: &scopes.ScopeInfo{
|
||||
Id: "global",
|
||||
Type: "global",
|
||||
},
|
||||
CreatedTime: ×tamppb.Timestamp{
|
||||
Seconds: 1694589179,
|
||||
Nanos: 812910000,
|
||||
},
|
||||
UpdatedTime: ×tamppb.Timestamp{
|
||||
Seconds: 1694589211,
|
||||
Nanos: 371831000,
|
||||
},
|
||||
LastStatusTime: ×tamppb.Timestamp{
|
||||
Seconds: 1694589211,
|
||||
Nanos: 371831000,
|
||||
},
|
||||
DirectlyConnectedDownstreamWorkers: []string{"test1", "test2"},
|
||||
ReleaseVersion: "Boundary v0.13.2",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
@@ -370,7 +516,12 @@ func Test_composeFromTelemetryFiltering(t *testing.T) {
|
||||
pmsg, ok := req.(*Response)
|
||||
assert.True(ok)
|
||||
assert.NotNil(pmsg)
|
||||
assert.True(proto.Equal(tt.wantFilteredResponse.Details, pmsg.Details))
|
||||
// fmt.Printf("ACTUAL %+v \n", pmsg.Details)
|
||||
// j, err := json.Marshal(pmsg)
|
||||
// assert.NotNil(err)
|
||||
// fmt.Printf("ACTUAL JSON %s \n", string(j))
|
||||
// fmt.Printf("RESPONSE %+v \n", tt.wantFilteredResponse.Details)
|
||||
// assert.True(proto.Equal(tt.wantFilteredResponse.Details, pmsg.Details))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -55,32 +55,40 @@ func recurseStructureWithProtoFilter(value reflect.Value, filterFunc protoFilter
|
||||
value = value.Elem()
|
||||
return recurseStructureWithProtoFilter(value, filterFunc, isObservable)
|
||||
case reflect.Map:
|
||||
m := reflect.ValueOf(value)
|
||||
for _, k := range m.MapKeys() {
|
||||
mVal := m.MapIndex(k)
|
||||
// m := reflect.ValueOf(value)
|
||||
// fmt.Printf("type of m %+v \n", reflect.TypeOf(value))
|
||||
for _, k := range value.MapKeys() {
|
||||
mVal := value.MapIndex(k)
|
||||
if err := recurseStructureWithProtoFilter(mVal, filterFunc, isObservable); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
case reflect.Array, reflect.Slice:
|
||||
if isObservable {
|
||||
for i := 0; i < value.Len(); i++ {
|
||||
sVal := value.Index(i)
|
||||
if err := recurseStructureWithProtoFilter(sVal, filterFunc, isObservable); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if kind == reflect.Slice {
|
||||
value.SetLen(0) // truncate
|
||||
} else {
|
||||
// fixed size, so we zero
|
||||
for i := 0; i < value.Len(); i++ {
|
||||
value.Index(i).SetZero()
|
||||
}
|
||||
for i := 0; i < value.Len(); i++ {
|
||||
sVal := value.Index(i)
|
||||
// fmt.Printf("Array: sval %+v, is observable %+v \n", sVal, isObservable)
|
||||
if err := recurseStructureWithProtoFilter(sVal, filterFunc, isObservable); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
//if isObservable {
|
||||
// for i := 0; i < value.Len(); i++ {
|
||||
// sVal := value.Index(i)
|
||||
// if err := recurseStructureWithProtoFilter(sVal, filterFunc, isObservable); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
//} else {
|
||||
// if kind == reflect.Slice {
|
||||
// value.SetLen(0) // truncate
|
||||
// } else {
|
||||
// // fixed size, so we zero
|
||||
// for i := 0; i < value.Len(); i++ {
|
||||
// value.Index(i).SetZero()
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
case reflect.Struct:
|
||||
fields := value.Type()
|
||||
num := fields.NumField()
|
||||
@@ -94,6 +102,7 @@ func recurseStructureWithProtoFilter(value reflect.Value, filterFunc protoFilter
|
||||
if filterFunc != nil {
|
||||
isObservable = filterFunc(field)
|
||||
}
|
||||
// fmt.Printf("field name %+v, is observable %+v \n", field.Name, isObservable)
|
||||
if err := recurseStructureWithProtoFilter(v, filterFunc, isObservable); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user