Skip to content

Commit

Permalink
update demo to test valid type with no data
Browse files Browse the repository at this point in the history
  • Loading branch information
skpratt committed Sep 15, 2023
1 parent 55c7ffd commit da9090e
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 36 deletions.
15 changes: 15 additions & 0 deletions agent/grpc-external/services/resource/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,21 @@ func TestWrite_NonCASUpdate_Retry(t *testing.T) {
require.NoError(t, <-errCh)
}

func TestWrite_NoData(t *testing.T) {
server := testServer(t)
client := testClient(t, server)

demo.RegisterTypes(server.Registry)

res, err := demo.GenerateV1Concept("jazz")
require.NoError(t, err)

rsp, err := client.Write(testContext(t), &pbresource.WriteRequest{Resource: res})
require.NoError(t, err)
require.NotEmpty(t, rsp.Resource.Version)
require.Equal(t, rsp.Resource.Id.Name, "jazz")
}

func TestWrite_Owner_Immutable(t *testing.T) {
// Use of proto.Equal(..) in implementation covers all permutations
// (nil -> non-nil, non-nil -> nil, owner1 -> owner2) so only the first one
Expand Down
33 changes: 33 additions & 0 deletions internal/resource/demo/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ var (
Kind: "Album",
}

// TypeV1Concept represents an abstract concept that can be associated with any other resource.
TypeV1Concept = &pbresource.Type{
Group: "demo",
GroupVersion: "v1",
Kind: "Concept",
}

// TypeV2Artist represents a musician or group of musicians.
TypeV2Artist = &pbresource.Type{
Group: "demo",
Expand Down Expand Up @@ -159,6 +166,17 @@ func RegisterTypes(r resource.Registry) {
},
})

r.Register(resource.Registration{
Type: TypeV1Concept,
Proto: &pbdemov1.Concept{},
Scope: resource.ScopeNamespace,
ACLs: &resource.ACLHooks{
Read: readACL,
Write: writeACL,
List: makeListACL(TypeV1Concept),
},
})

r.Register(resource.Registration{
Type: TypeV2Artist,
Proto: &pbdemov2.Artist{},
Expand Down Expand Up @@ -204,6 +222,21 @@ func GenerateV1RecordLabel(name string) (*pbresource.Resource, error) {
}, nil
}

// GenerateV1Concept generates a named concept resource.
func GenerateV1Concept(name string) (*pbresource.Resource, error) {
return &pbresource.Resource{
Id: &pbresource.ID{
Type: TypeV1Concept,
Tenancy: resource.DefaultPartitionedTenancy(),
Name: name,
},
Data: nil,
Metadata: map[string]string{
"generated_at": time.Now().Format(time.RFC3339),
},
}, nil
}

// GenerateV2Artist generates a random Artist resource.
func GenerateV2Artist() (*pbresource.Resource, error) {
adjective := adjectives[rand.Intn(len(adjectives))]
Expand Down
10 changes: 10 additions & 0 deletions proto/private/pbdemo/v1/demo.pb.binary.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 88 additions & 36 deletions proto/private/pbdemo/v1/demo.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions proto/private/pbdemo/v1/demo.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ message Album {
bool critically_acclaimed = 3;
repeated string tracks = 4;
}

message Concept {}

0 comments on commit da9090e

Please sign in to comment.