-
Notifications
You must be signed in to change notification settings - Fork 111
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
APP-7497: Add Button client, server, and fake model #4740
Conversation
87741a8
to
6b4f06f
Compare
d1ec868
to
d62aae2
Compare
components/button/fake/button.go
Outdated
// Config is the config for a fake button. | ||
type Config struct { | ||
resource.TriviallyValidateConfig | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Config is the config for a fake button. | |
type Config struct { | |
resource.TriviallyValidateConfig | |
} |
With resource.NoNativeConfig
below
components/button/server.go
Outdated
func (s *serviceServer) DoCommand(ctx context.Context, | ||
req *commonpb.DoCommandRequest, | ||
) (*commonpb.DoCommandResponse, error) { | ||
gripper, err := s.coll.Resource(req.GetName()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gripper, err := s.coll.Resource(req.GetName()) | |
button, err := s.coll.Resource(req.GetName()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
components/button/server.go
Outdated
if err != nil { | ||
return nil, err | ||
} | ||
return protoutils.DoFromResourceServer(ctx, gripper, req) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return protoutils.DoFromResourceServer(ctx, gripper, req) | |
return protoutils.DoFromResourceServer(ctx, button, req) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t.Run("push", func(t *testing.T) { | ||
_, err := buttonServer.Push(context.Background(), &pb.PushRequest{Name: missingButtonName}) | ||
test.That(t, err, test.ShouldNotBeNil) | ||
test.That(t, err.Error(), test.ShouldContainSubstring, errButtonNotFound.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[super nit] could you compare the errors directly? don't try to do this in the client as it wraps it was a "grpc error blah blah", but I prefer comparing the errors directly in server code
rdk/components/movementsensor/server_test.go
Line 134 in 93eea2e
test.That(t, err, test.ShouldBeError, errLinearVelocity) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could only do this for the push error. For the missing errors, the error is wrapped with the resource's name so it does not exactly match the error.
components/button/button_test.go
Outdated
@@ -0,0 +1,33 @@ | |||
package button_test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to fake, it's testing that package, the helpers in the interface package are tested in the resource graph.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a follow up ticket for me to "add fake button and switch to fake.json in rdk" - do NOT do it yourself, it will open up a can of worms in robot and resource graph. |
|
d52ab1b
to
1ff98bc
Compare
This adds the button client and server, and registers a button fake model.
Here's a button component properly configured in app:
Change log
I used Cursor quite a bit here:
go.viam.com/api
versionButton
SDK helpersReview requests