Skip to content

Commit

Permalink
Update CrownJewel test and serialization methods
Browse files Browse the repository at this point in the history
Updated the test condition in crown_jewels_test.go to use Proto.Equal for object comparisons. Also, swapped out the FastMarshal and FastUnmarshal methods with protojson's Marshal and Unmarshal in the CrownJewels service.
  • Loading branch information
jakule committed May 7, 2024
1 parent 0cc7e5e commit 4c47ce3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/services/crown_jewel.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
"context"

"github.com/gravitational/trace"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"

crownjewelv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/crownjewel/v1"
"github.com/gravitational/teleport/lib/utils"
)

// CrownJewels is the interface for managing crown jewel resources.
Expand Down Expand Up @@ -57,7 +57,7 @@ func MarshalCrownJewel(object *crownjewelv1.CrownJewel, opts ...MarshalOption) (
object = proto.Clone(object).(*crownjewelv1.CrownJewel)
object.Metadata.Revision = ""
}
data, err := utils.FastMarshal(object)
data, err := protojson.Marshal(object)
if err != nil {
return nil, trace.Wrap(err)
}
Expand All @@ -74,7 +74,7 @@ func UnmarshalCrownJewel(data []byte, opts ...MarshalOption) (*crownjewelv1.Crow
return nil, trace.Wrap(err)
}
var obj crownjewelv1.CrownJewel
if err := utils.FastUnmarshal(data, &obj); err != nil {
if err := protojson.Unmarshal(data, &obj); err != nil {
return nil, trace.BadParameter(err.Error())
}
if cfg.Revision != "" {
Expand Down
4 changes: 2 additions & 2 deletions lib/services/crown_jewels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestUnmarshalCrownJewel(t *testing.T) {

obj, err := UnmarshalCrownJewel(data)
require.NoError(t, err)
require.Equal(t, expected, obj)
require.True(t, proto.Equal(expected, obj), "CrownJewel objects are not equal")
}

const correctCrownJewelYAML = `
Expand All @@ -112,7 +112,7 @@ spec:
tags:
- key: env
values:
- value: prod
- prod
types:
- ec2
teleport_matchers:
Expand Down

0 comments on commit 4c47ce3

Please sign in to comment.