Skip to content

Commit

Permalink
Fix empty pack patterns in Go client
Browse files Browse the repository at this point in the history
  • Loading branch information
angelini committed Oct 25, 2022
1 parent 0618819 commit 8e33f21
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/cli/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewCmdNew() *cobra.Command {
templatePtr = &template
}

err := client.NewProject(ctx, id, templatePtr, patterns)
err := client.NewProject(ctx, id, templatePtr, &patterns)
if err != nil {
return fmt.Errorf("could not create new project: %w", err)
}
Expand Down
12 changes: 8 additions & 4 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,23 @@ func (c *Client) ListProjects(ctx context.Context) ([]*pb.Project, error) {
return resp.Projects, nil
}

func (c *Client) NewProject(ctx context.Context, id int64, template *int64, packPatterns string) error {
splitPackPatterns := strings.Split(packPatterns, ",")
func (c *Client) NewProject(ctx context.Context, id int64, template *int64, packPatternsString *string) error {
var packPatterns []string
if packPatternsString != nil && *packPatternsString != "" {
packPatterns = strings.Split(*packPatternsString, ",")
}

ctx, span := telemetry.Start(ctx, "client.new-project", trace.WithAttributes(
key.Project.Attribute(id),
key.Template.Attribute(template),
key.PackPatterns.Attribute(splitPackPatterns),
key.PackPatterns.Attribute(packPatterns),
))
defer span.End()

request := &pb.NewProjectRequest{
Id: id,
Template: template,
PackPatterns: splitPackPatterns,
PackPatterns: packPatterns,
}

_, err := c.fs.NewProject(ctx, request)
Expand Down
42 changes: 42 additions & 0 deletions test/client_new_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package test

import (
"testing"

"github.com/gadget-inc/dateilager/internal/auth"
util "github.com/gadget-inc/dateilager/internal/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestClientNewProjectEmptyPackPattern(t *testing.T) {
tc := util.NewTestCtx(t, auth.Admin, 1)
defer tc.Close()

c, fs, close := createTestClient(tc)
defer close()

err := c.NewProject(tc.Context(), 1, nil, nil)
require.NoError(t, err, "NewProject")

updateStream := newMockUpdateServer(tc.Context(), 1, map[string]expectedObject{
"a": {content: "a v1"},
"b": {content: "b v1"},
"c": {content: "c v1"},
})
err = fs.Update(updateStream)
require.NoError(t, err, "fs.Update")

stream := &mockGetCompressServer{ctx: tc.Context()}
err = fs.GetCompress(buildCompressRequest(1, nil, nil, ""), stream)
require.NoError(t, err, "fs.GetCompress")

// If the objects were marked as packed they would be returned as more than 1 TAR
assert.Equal(t, 1, len(stream.results), "expected 1 TAR files")

verifyTarResults(t, stream.results, map[string]expectedObject{
"a": {content: "a v1"},
"b": {content: "b v1"},
"c": {content: "c v1"},
})
}

0 comments on commit 8e33f21

Please sign in to comment.