Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

old feedback + export IsState #58

Merged
merged 2 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
old feedback + export IsState
  • Loading branch information
DanG100 committed Aug 22, 2022
commit 9c523e132eb89217905188bbb7a28e5f3fc36adc
30 changes: 15 additions & 15 deletions internal/testutil/gnmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import (

// FakeGNMI is a running fake GNMI server.
type FakeGNMI struct {
agent *gnmi.Agent
stub *Stubber
getWrapper *getWrapper
agent *gnmi.Agent
stub *Stubber
clientWrapper *clientWithGetter
}

// StartGNMI launches a new fake GNMI server on the given port
Expand All @@ -51,9 +51,9 @@ func StartGNMI(port int) (*FakeGNMI, error) {
}
stub := &Stubber{gen: gen}
return &FakeGNMI{
agent: agent,
stub: stub,
getWrapper: &getWrapper{stub: stub},
agent: agent,
stub: stub,
clientWrapper: &clientWithGetter{stub: stub},
}, nil
}

Expand All @@ -64,8 +64,8 @@ func (g *FakeGNMI) Dial(ctx context.Context, opts ...grpc.DialOption) (gpb.GNMIC
if err != nil {
return nil, errors.Wrapf(err, "DialContext(%s, %v)", g.agent.Address(), opts)
}
g.getWrapper.GNMIClient = gpb.NewGNMIClient(conn)
return g.getWrapper, nil
g.clientWrapper.GNMIClient = gpb.NewGNMIClient(conn)
return g.clientWrapper, nil
}

// Stub reset the stubbed responses to empty and returns a handle to add new ones.
Expand All @@ -81,18 +81,18 @@ func (g *FakeGNMI) Requests() []*gpb.SubscribeRequest {

// GetRequests returns the set of GetRequests sent to the gNMI server.
func (g *FakeGNMI) GetRequests() []*gpb.GetRequest {
return g.getWrapper.getRequests
return g.clientWrapper.getRequests
}

// getWrapper adds gNMI Get functionality to a GNMI client.
type getWrapper struct {
// clientWithGetter adds gNMI Get functionality to a GNMI client.
type clientWithGetter struct {
gpb.GNMIClient
stub *Stubber
getRequests []*gpb.GetRequest
}

// Get is fake implement of gnmi.Get, it returns the GetResponse contained in the stub.
func (g *getWrapper) Get(ctx context.Context, req *gpb.GetRequest, _ ...grpc.CallOption) (*gpb.GetResponse, error) {
// Get is a fake implementation of gnmi.Get, it returns the GetResponse contained in the stub.
func (g *clientWithGetter) Get(ctx context.Context, req *gpb.GetRequest, _ ...grpc.CallOption) (*gpb.GetResponse, error) {
g.getRequests = append(g.getRequests, req)
if len(g.stub.getResponses) == 0 {
return nil, io.EOF
Expand All @@ -116,8 +116,8 @@ func (s *Stubber) Notification(n *gpb.Notification) *Stubber {
return s
}

// AppendGetResponse appends the given GetResponse as a stub response.
func (s *Stubber) AppendGetResponse(gr *gpb.GetResponse) *Stubber {
// GetResponse appends the given GetResponse as a stub response.
func (s *Stubber) GetResponse(gr *gpb.GetResponse) *Stubber {
s.getResponses = append(s.getResponses, gr)
return s
}
Expand Down
4 changes: 2 additions & 2 deletions ygnmi/gnmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func subscribe[T any](ctx context.Context, c *Client, q AnyQuery[T], mode gpb.Su
var err error
if o.useGet {
dt := gpb.GetRequest_CONFIG
if q.isState() {
if q.IsState() {
dt = gpb.GetRequest_STATE
}
sub = &getSubscriber{
Expand Down Expand Up @@ -123,7 +123,7 @@ func (gs *getSubscriber) Send(req *gpb.SubscribeRequest) error {
return nil
}

// Recv returns the result of the Get request, returning io.EOF after resonpse are read.
// Recv returns the result of the Get request, returning io.EOF after response are read.
DanG100 marked this conversation as resolved.
Show resolved Hide resolved
func (gs *getSubscriber) Recv() (*gpb.SubscribeResponse, error) {
if len(gs.notifs) == 0 {
return nil, io.EOF
Expand Down
8 changes: 4 additions & 4 deletions ygnmi/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ func (lq *leafBaseQuery[T]) isLeaf() bool {
return true
}

// isState returns if the Query is for a state or config path.
func (lq *leafBaseQuery[T]) isState() bool {
// IsState returns if the Query is for a state or config path.
func (lq *leafBaseQuery[T]) IsState() bool {
return lq.state
}

Expand Down Expand Up @@ -247,8 +247,8 @@ func (lq *nonLeafBaseQuery[T]) isScalar() bool {
return false
}

// isState returns if the Query is for a state or config path.
func (lq *nonLeafBaseQuery[T]) isState() bool {
// IsState returns if the Query is for a state or config path.
func (lq *nonLeafBaseQuery[T]) IsState() bool {
return lq.state
}

Expand Down
4 changes: 2 additions & 2 deletions ygnmi/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func unmarshalAndExtract[T any](data []*DataPoint, q AnyQuery[T], goStruct ygot.
return ret, nil
}

unmarshalledData, complianceErrs, err := unmarshal(data, q.schema().SchemaTree[q.dirName()], goStruct, queryPath, q.schema(), q.isLeaf(), !q.isState())
unmarshalledData, complianceErrs, err := unmarshal(data, q.schema().SchemaTree[q.dirName()], goStruct, queryPath, q.schema(), q.isLeaf(), !q.IsState())
ret.ComplianceErrors = complianceErrs
if err != nil {
return ret, err
Expand All @@ -151,7 +151,7 @@ func unmarshalAndExtract[T any](data []*DataPoint, q AnyQuery[T], goStruct ygot.
ret.Path = path

// For non-leaf config queries, prune all state-only leaves.
if !q.isLeaf() && !q.isState() {
if !q.isLeaf() && !q.IsState() {
err := ygot.PruneConfigFalse(q.schema().SchemaTree[q.dirName()], goStruct)
if err != nil {
return ret, err
Expand Down
4 changes: 2 additions & 2 deletions ygnmi/ygnmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ type AnyQuery[T any] interface {
// extract is used for leaves to return the field from the parent GoStruct.
// For non-leaves, this casts the GoStruct to the concrete type.
extract(ygot.ValidatedGoStruct) (T, bool)
// isState returns if the path for this query is a state node.
isState() bool
// IsState returns if the path for this query is a state node.
IsState() bool
// isLeaf returns if the path for this query is a leaf.
isLeaf() bool
// isScalar returns whether the type (T) for this path is a pointer field (*T) in the parent GoStruct.
Expand Down
8 changes: 4 additions & 4 deletions ygnmi/ygnmi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func TestLookup(t *testing.T) {
})
}
t.Run("use get", func(t *testing.T) {
fakeGNMI.Stub().AppendGetResponse(&gpb.GetResponse{
fakeGNMI.Stub().GetResponse(&gpb.GetResponse{
Notification: []*gpb.Notification{{
Timestamp: 100,
Update: []*gpb.Update{{
Expand Down Expand Up @@ -522,7 +522,7 @@ func TestGet(t *testing.T) {
})
}
t.Run("use get", func(t *testing.T) {
fakeGNMI.Stub().AppendGetResponse(&gpb.GetResponse{
fakeGNMI.Stub().GetResponse(&gpb.GetResponse{
Notification: []*gpb.Notification{{
Timestamp: 100,
Update: []*gpb.Update{{
Expand Down Expand Up @@ -1569,7 +1569,7 @@ func TestLookupAll(t *testing.T) {
})
}
t.Run("use get", func(t *testing.T) {
fakeGNMI.Stub().AppendGetResponse(&gpb.GetResponse{
fakeGNMI.Stub().GetResponse(&gpb.GetResponse{
Notification: []*gpb.Notification{{
Timestamp: 100,
Update: []*gpb.Update{{
Expand Down Expand Up @@ -1652,7 +1652,7 @@ func TestGetAll(t *testing.T) {
})
}
t.Run("use get", func(t *testing.T) {
fakeGNMI.Stub().AppendGetResponse(&gpb.GetResponse{
fakeGNMI.Stub().GetResponse(&gpb.GetResponse{
Notification: []*gpb.Notification{{
Timestamp: 100,
Update: []*gpb.Update{{
Expand Down