Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions client/building_block_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,19 @@ type MeshBuildingBlockV2ListFilter struct {
Sort SortCriteria `json:"sort"`
}

// MeshBuildingBlockV2UpdateOptions go out as query parameters, and a zero field as none, so the
// zero value works against a meshStack that does not know them.
type MeshBuildingBlockV2UpdateOptions struct {
// SkipRun saves the update without starting a run.
SkipRun bool `json:"skipRun"`
}

type MeshBuildingBlockV2Client interface {
Read(ctx context.Context, uuid string) (*MeshBuildingBlockV2, error)
ReadFunc(uuid string) func(ctx context.Context) (*MeshBuildingBlockV2, error)
List(ctx context.Context, filter MeshBuildingBlockV2ListFilter) ([]MeshBuildingBlockV2, error)
Create(ctx context.Context, bb *MeshBuildingBlockV2) (*MeshBuildingBlockV2, error)
Update(ctx context.Context, bb *MeshBuildingBlockV2) (*MeshBuildingBlockV2, error)
Update(ctx context.Context, bb *MeshBuildingBlockV2, options MeshBuildingBlockV2UpdateOptions) (*MeshBuildingBlockV2, error)
Delete(ctx context.Context, uuid string, purge bool) error
TriggerRun(ctx context.Context, uuid string) (*MeshBuildingBlockV2, error)
}
Expand Down Expand Up @@ -372,11 +379,11 @@ func (c meshBuildingBlockV2Client) Create(ctx context.Context, bb *MeshBuildingB
return c.meshObject.Post(ctx, bb)
}

func (c meshBuildingBlockV2Client) Update(ctx context.Context, bb *MeshBuildingBlockV2) (*MeshBuildingBlockV2, error) {
func (c meshBuildingBlockV2Client) Update(ctx context.Context, bb *MeshBuildingBlockV2, options MeshBuildingBlockV2UpdateOptions) (*MeshBuildingBlockV2, error) {
if bb.Metadata.Uuid == nil {
return nil, errors.New("cannot update building block without UUID")
}
return c.meshObject.Put(ctx, *bb.Metadata.Uuid, bb)
return c.meshObject.Put(ctx, *bb.Metadata.Uuid, bb, http.WithUrlQuery(options))
}

func (c meshBuildingBlockV2Client) Delete(ctx context.Context, uuid string, purge bool) error {
Expand Down
20 changes: 20 additions & 0 deletions client/building_block_v2_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package client

import (
"io"
gohttp "net/http"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/meshcloud/meshstack-cli/client/types/enum"
"github.com/meshcloud/meshstack-cli/internal/testutil/fakemeshstack"
)

func TestMeshBuildingBlockV2Status_RunChangedSince(t *testing.T) {
Expand Down Expand Up @@ -170,3 +173,20 @@ func TestMeshBuildingBlockV2_DeletionSuccessful(t *testing.T) {
})
}
}

func TestMeshBuildingBlockV2Client_UpdateSendsSkipRunOnlyWhenSet(t *testing.T) {
server := fakemeshstack.Start(t, fakemeshstack.Options{})
server.Route("/", func(w gohttp.ResponseWriter, _ *gohttp.Request) { _, _ = io.WriteString(w, `{}`) })
blocks := newBuildingBlockV2Client(t.Context(), newTestHttpClient(server))
bb := &MeshBuildingBlockV2{Metadata: MeshBuildingBlockV2Metadata{Uuid: new("0b5c1d3e-5f1a-4c2b-9d7e-2a6f8e4b1c90")}}

for _, options := range []MeshBuildingBlockV2UpdateOptions{{}, {SkipRun: true}} {
_, err := blocks.Update(t.Context(), bb, options)
require.NoError(t, err)
}

requests := server.TakeRequests()
require.Len(t, requests, 2)
assert.Empty(t, requests[0].URL.RawQuery)
assert.Equal(t, "skipRun=true", requests[1].URL.RawQuery)
}
4 changes: 2 additions & 2 deletions client/internal/mesh_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ func (c MeshObjectApi) PostAtPath[R, P any](ctx context.Context, payload P, extr
http.WithAccept(c.MeshObjectMimeType()), c.withMeshObjectPayload(payload))
}

func (c MeshObjectClient[M]) Put[P any](ctx context.Context, id string, payload P) (*M, error) {
return c.DoRequest[*M](ctx, http.MethodPut, c.ApiUrl.JoinPath(id), c.withMeshObjectPayload(payload), http.Retryable())
func (c MeshObjectClient[M]) Put[P any](ctx context.Context, id string, payload P, options ...http.RequestOption) (*M, error) {
return c.DoRequest[*M](ctx, http.MethodPut, c.ApiUrl.JoinPath(id), append(options, c.withMeshObjectPayload(payload), http.Retryable())...)
}

func (c MeshObjectClient[M]) Delete(ctx context.Context, id string) (err error) {
Expand Down
Loading