feat: returning correct list of included facts

This commit is contained in:
Jefferson Girão
2020-02-06 13:18:56 +01:00
parent 1832a3a763
commit 90495b6187
3 changed files with 13 additions and 9 deletions
+8 -7
View File
@@ -26,19 +26,20 @@ func (s *Server) CreateEntity(ctx context.Context, req *pb.CreateEntityRequest)
// GetEntity returns an inventory Entity with the selected facts
func (s *Server) GetEntity(ctx context.Context, req *pb.GetEntityRequest) (*pb.GetEntityReply, error) {
numberOfIncludedFacts := len(req.GetIncludeFacts())
var facts = make([]pb.Fact, numberOfIncludedFacts)
entityURI, err := s.Storage.GetEntity(req.GetEntity().GetUri())
var facts []*pb.Fact
entityUri, err := s.Storage.GetEntity(req.GetEntity().GetUri())
if err != nil {
return nil, status.Error(codes.Internal, fmt.Sprintf("could not get entity %v", err))
}
for _, factName := range req.GetIncludeFacts() {
value, err := s.Storage.GetFact(entityURI, factName)
// TODO: handle errors
append(facts, pb.Fact{Name: factName, Value: value})
value, err := s.Storage.GetFact(entityUri, factName)
if err != nil {
return nil, status.Error(codes.Internal, fmt.Sprintf("could not get fact %v for %v" , factName, entityUri))
}
facts = append(facts, &pb.Fact{Name: factName, Value: value})
}
return &pb.GetEntityReply{Entity: &pb.Entity{Uri: entityURI}, Facts: facts}, nil
return &pb.GetEntityReply{Entity: &pb.Entity{Uri: entityUri}, Facts: facts}, nil
}
func (s *Server) SetFact(ctx context.Context, req *pb.SetFactRequest) (*pb.SetFactReply, error) {
+2 -2
View File
@@ -104,8 +104,8 @@ func TestServerSetFactForNonExistingEntity(t *testing.T) {
defer testStorage.Close()
s := Server{Storage: testStorage.Storage}
entityURI := "boss://test/test"
req := &pb.SetFactRequest{EntityUri: entityURI, Name: "test-name", Value: "test-value"}
entityUri := "boss://test/test"
req := &pb.SetFactRequest{EntityUri: entityUri, Name: "test-name", Value: "test-value"}
resp, err := s.SetFact(context.Background(), req)
if err != nil {
t.Errorf("ServerTest(SetFact) got unexpected error %v", err)
+3
View File
@@ -8,5 +8,8 @@ require (
github.com/golang/protobuf v1.3.3
github.com/spotify/backstage/proto v0.0.0-00010101000000-000000000000
go.etcd.io/bbolt v1.3.3
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 // indirect
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 // indirect
google.golang.org/grpc v1.27.0
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc // indirect
)