Skip to content

Commit

Permalink
fix: fix issues related to resource deploy (#749)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbchaos authored Feb 28, 2023
1 parent d54792a commit 83ece95
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
1 change: 0 additions & 1 deletion core/resource/handler/v1beta1/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func (rh ResourceHandler) DeployResourceSpecification(stream pb.ResourceService_
}
if len(resourceSpecs) != len(request.GetResources()) {
errNamespaces = append(errNamespaces, request.GetNamespaceName())
continue
}

err = rh.service.Deploy(stream.Context(), tnnt, store, resourceSpecs)
Expand Down
5 changes: 5 additions & 0 deletions core/resource/handler/v1beta1/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func TestResourceHandler(t *testing.T) {
})
t.Run("returns error log when conversion fails", func(t *testing.T) {
service := new(resourceService)
service.On("Deploy", ctx, mock.Anything, resource.Bigquery, mock.Anything).
Return(nil)
defer service.AssertExpectations(t)

handler := v1beta1.NewResourceHandler(logger, service)

res1 := pb.ResourceSpecification{
Expand All @@ -112,6 +116,7 @@ func TestResourceHandler(t *testing.T) {
stream.On("Recv").Return(req, nil).Once()
stream.On("Recv").Return(nil, io.EOF).Once()
stream.On("Send", argMatcher).Return(nil).Once()
stream.On("Send", mock.Anything).Return(nil)

err := handler.DeployResourceSpecification(stream)
assert.NotNil(t, err)
Expand Down
4 changes: 2 additions & 2 deletions core/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ func NewResource(fullName string, kind string, store Store, tnnt tenant.Tenant,
}

if len(spec) == 0 {
return nil, errors.InvalidArgument(EntityResource, "invalid resource spec for "+fullName)
return nil, errors.InvalidArgument(EntityResource, "empty resource spec for "+fullName)
}

if meta == nil {
return nil, errors.InvalidArgument(EntityResource, "invalid resource metadata")
return nil, errors.InvalidArgument(EntityResource, "empty resource metadata for "+fullName)
}

return &Resource{
Expand Down
4 changes: 2 additions & 2 deletions core/resource/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestNewResource(t *testing.T) {
spec := map[string]any{"a": "b"}
_, err := resource.NewResource("proj.set.res_name", "table", resource.Bigquery, tnnt, nil, spec)
assert.NotNil(t, err)
assert.EqualError(t, err, "invalid argument for entity resource: invalid resource metadata")
assert.EqualError(t, err, "invalid argument for entity resource: empty resource metadata for proj.set.res_name")
})
t.Run("returns error when invalid resource metadata", func(t *testing.T) {
meta := resource.Metadata{
Expand All @@ -55,7 +55,7 @@ func TestNewResource(t *testing.T) {
_, err := resource.NewResource("proj.set.res_name", "table",
resource.Bigquery, tnnt, &meta, nil)
assert.NotNil(t, err)
assert.EqualError(t, err, "invalid argument for entity resource: invalid resource spec "+
assert.EqualError(t, err, "invalid argument for entity resource: empty resource spec "+
"for proj.set.res_name")
})
})
Expand Down
10 changes: 10 additions & 0 deletions internal/utils/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils_test

import (
"reflect"
"sort"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -66,6 +67,15 @@ func TestMapHelper(t *testing.T) {
assert.Equal(t, "4", merged["Key"])
})
})
t.Run("MapToList", func(t *testing.T) {
t.Run("returns the values in map", func(t *testing.T) {
mapping := map[string]string{"a": "b", "c": "d", "e": "f"}
list := utils.MapToList(mapping)
assert.Len(t, list, 3)
sort.Strings(list)
assert.Equal(t, []string{"b", "d", "f"}, list)
})
})
t.Run("AppendToMap", func(t *testing.T) {
t.Run("appends data from string map", func(t *testing.T) {
orig := map[string]interface{}{
Expand Down

0 comments on commit 83ece95

Please sign in to comment.