Skip to content

Commit

Permalink
refactor: rename api->service
Browse files Browse the repository at this point in the history
Signed-off-by: t-kikuc <[email protected]>
  • Loading branch information
t-kikuc committed Jan 8, 2025
1 parent cf4e557 commit b53f980
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
46 changes: 23 additions & 23 deletions pkg/app/pipedv1/metadatastore/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

"github.com/pipe-cd/pipecd/pkg/model"

api "github.com/pipe-cd/pipecd/pkg/plugin/pipedservice"
service "github.com/pipe-cd/pipecd/pkg/plugin/pipedservice"
)

// MetadataStoreRegistry is a registry of metadata stores for deployments.
Expand Down Expand Up @@ -51,84 +51,84 @@ func (r *MetadataStoreRegistry) Delete(deploymentID string) {
delete(r.stores, deploymentID)
}

func (r *MetadataStoreRegistry) GetStageMetadata(ctx context.Context, req *api.GetStageMetadataRequest) (*api.GetStageMetadataResponse, error) {
func (r *MetadataStoreRegistry) GetStageMetadata(ctx context.Context, req *service.GetStageMetadataRequest) (*service.GetStageMetadataResponse, error) {
mds, ok := r.stores[req.DeploymentId]
if !ok {
return &api.GetStageMetadataResponse{Found: false}, fmt.Errorf("metadata store not found for deployment %s", req.DeploymentId)
return &service.GetStageMetadataResponse{Found: false}, fmt.Errorf("metadata store not found for deployment %s", req.DeploymentId)
}

value, found := mds.Stage(req.StageId).Get(req.Key)
return &api.GetStageMetadataResponse{
return &service.GetStageMetadataResponse{
Value: value,
Found: found,
}, nil
}

func (r *MetadataStoreRegistry) PutStageMetadata(ctx context.Context, req *api.PutStageMetadataRequest) (*api.PutStageMetadataResponse, error) {
func (r *MetadataStoreRegistry) PutStageMetadata(ctx context.Context, req *service.PutStageMetadataRequest) (*service.PutStageMetadataResponse, error) {
mds, ok := r.stores[req.DeploymentId]
if !ok {
return &api.PutStageMetadataResponse{}, fmt.Errorf("metadata store not found for deployment %s", req.DeploymentId)
return &service.PutStageMetadataResponse{}, fmt.Errorf("metadata store not found for deployment %s", req.DeploymentId)
}

err := mds.Stage(req.StageId).Put(ctx, req.Key, req.Value)
if err != nil {
return &api.PutStageMetadataResponse{}, err
return &service.PutStageMetadataResponse{}, err
}

return &api.PutStageMetadataResponse{}, nil
return &service.PutStageMetadataResponse{}, nil
}

func (r *MetadataStoreRegistry) PutStageMetadataMulti(ctx context.Context, req *api.PutStageMetadataMultiRequest) (*api.PutStageMetadataMultiResponse, error) {
func (r *MetadataStoreRegistry) PutStageMetadataMulti(ctx context.Context, req *service.PutStageMetadataMultiRequest) (*service.PutStageMetadataMultiResponse, error) {
mds, ok := r.stores[req.DeploymentId]
if !ok {
return &api.PutStageMetadataMultiResponse{}, fmt.Errorf("metadata store not found for deployment %s", req.DeploymentId)
return &service.PutStageMetadataMultiResponse{}, fmt.Errorf("metadata store not found for deployment %s", req.DeploymentId)
}

err := mds.Stage(req.StageId).PutMulti(ctx, req.Metadata)
if err != nil {
return &api.PutStageMetadataMultiResponse{}, err
return &service.PutStageMetadataMultiResponse{}, err
}

return &api.PutStageMetadataMultiResponse{}, nil
return &service.PutStageMetadataMultiResponse{}, nil
}

func (r *MetadataStoreRegistry) GetDeploymentMetadata(ctx context.Context, req *api.GetDeploymentMetadataRequest) (*api.GetDeploymentMetadataResponse, error) {
func (r *MetadataStoreRegistry) GetDeploymentMetadata(ctx context.Context, req *service.GetDeploymentMetadataRequest) (*service.GetDeploymentMetadataResponse, error) {
mds, ok := r.stores[req.DeploymentId]
if !ok {
return &api.GetDeploymentMetadataResponse{Found: false}, fmt.Errorf("metadata store not found for deployment %s", req.DeploymentId)
return &service.GetDeploymentMetadataResponse{Found: false}, fmt.Errorf("metadata store not found for deployment %s", req.DeploymentId)
}

value, found := mds.Shared().Get(req.Key)
return &api.GetDeploymentMetadataResponse{
return &service.GetDeploymentMetadataResponse{
Value: value,
Found: found,
}, nil
}

func (r *MetadataStoreRegistry) PutDeploymentMetadata(ctx context.Context, req *api.PutDeploymentMetadataRequest) (*api.PutDeploymentMetadataResponse, error) {
func (r *MetadataStoreRegistry) PutDeploymentMetadata(ctx context.Context, req *service.PutDeploymentMetadataRequest) (*service.PutDeploymentMetadataResponse, error) {
mds, ok := r.stores[req.DeploymentId]
if !ok {
return &api.PutDeploymentMetadataResponse{}, fmt.Errorf("metadata store not found for deployment %s", req.DeploymentId)
return &service.PutDeploymentMetadataResponse{}, fmt.Errorf("metadata store not found for deployment %s", req.DeploymentId)
}

err := mds.Shared().Put(ctx, req.Key, req.Value)
if err != nil {
return &api.PutDeploymentMetadataResponse{}, err
return &service.PutDeploymentMetadataResponse{}, err
}

return &api.PutDeploymentMetadataResponse{}, nil
return &service.PutDeploymentMetadataResponse{}, nil
}

func (r *MetadataStoreRegistry) PutDeploymentMetadataMulti(ctx context.Context, req *api.PutDeploymentMetadataMultiRequest) (*api.PutDeploymentMetadataMultiResponse, error) {
func (r *MetadataStoreRegistry) PutDeploymentMetadataMulti(ctx context.Context, req *service.PutDeploymentMetadataMultiRequest) (*service.PutDeploymentMetadataMultiResponse, error) {
mds, ok := r.stores[req.DeploymentId]
if !ok {
return &api.PutDeploymentMetadataMultiResponse{}, fmt.Errorf("metadata store not found for deployment %s", req.DeploymentId)
return &service.PutDeploymentMetadataMultiResponse{}, fmt.Errorf("metadata store not found for deployment %s", req.DeploymentId)
}

err := mds.Shared().PutMulti(ctx, req.Metadata)
if err != nil {
return &api.PutDeploymentMetadataMultiResponse{}, err
return &service.PutDeploymentMetadataMultiResponse{}, err
}

return &api.PutDeploymentMetadataMultiResponse{}, nil
return &service.PutDeploymentMetadataMultiResponse{}, nil
}
32 changes: 16 additions & 16 deletions pkg/app/pipedv1/metadatastore/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"testing"

"github.com/pipe-cd/pipecd/pkg/model"
api "github.com/pipe-cd/pipecd/pkg/plugin/pipedservice"
service "github.com/pipe-cd/pipecd/pkg/plugin/pipedservice"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -57,7 +57,7 @@ func TestRegistry(t *testing.T) {
// Get
{
// Existing key
resp, err := r.GetDeploymentMetadata(ctx, &api.GetDeploymentMetadataRequest{
resp, err := r.GetDeploymentMetadata(ctx, &service.GetDeploymentMetadataRequest{
DeploymentId: d.Id,
Key: "key-1",
})
Expand All @@ -66,7 +66,7 @@ func TestRegistry(t *testing.T) {
assert.Equal(t, "value-1", resp.Value)

// Nonexistent key
resp, err = r.GetDeploymentMetadata(ctx, &api.GetDeploymentMetadataRequest{
resp, err = r.GetDeploymentMetadata(ctx, &service.GetDeploymentMetadataRequest{
DeploymentId: d.Id,
Key: "key-2",
})
Expand All @@ -75,7 +75,7 @@ func TestRegistry(t *testing.T) {
assert.Equal(t, "", resp.Value)

// Nonexistent deployment
resp, err = r.GetDeploymentMetadata(ctx, &api.GetDeploymentMetadataRequest{
resp, err = r.GetDeploymentMetadata(ctx, &service.GetDeploymentMetadataRequest{
DeploymentId: "not-exist-id",
Key: "key-2",
})
Expand All @@ -86,7 +86,7 @@ func TestRegistry(t *testing.T) {
// Put
{
// New key
_, err := r.PutDeploymentMetadata(ctx, &api.PutDeploymentMetadataRequest{
_, err := r.PutDeploymentMetadata(ctx, &service.PutDeploymentMetadataRequest{
DeploymentId: d.Id,
Key: "key-2",
Value: "value-2",
Expand All @@ -98,7 +98,7 @@ func TestRegistry(t *testing.T) {
}, ac.shared)

// Nonexistent deployment
_, err = r.PutDeploymentMetadata(ctx, &api.PutDeploymentMetadataRequest{
_, err = r.PutDeploymentMetadata(ctx, &service.PutDeploymentMetadataRequest{
DeploymentId: "not-exist-id",
Key: "key-2",
Value: "value-2",
Expand All @@ -108,7 +108,7 @@ func TestRegistry(t *testing.T) {
// PutMulti
{
// New keys(3,4) with one existing key(1)
_, err := r.PutDeploymentMetadataMulti(ctx, &api.PutDeploymentMetadataMultiRequest{
_, err := r.PutDeploymentMetadataMulti(ctx, &service.PutDeploymentMetadataMultiRequest{
DeploymentId: d.Id,
Metadata: map[string]string{
"key-3": "value-3",
Expand All @@ -125,7 +125,7 @@ func TestRegistry(t *testing.T) {
}, ac.shared)

// Nonexistent deployment
_, err = r.PutDeploymentMetadataMulti(ctx, &api.PutDeploymentMetadataMultiRequest{
_, err = r.PutDeploymentMetadataMulti(ctx, &service.PutDeploymentMetadataMultiRequest{
DeploymentId: "not-exist-id",
Metadata: map[string]string{
"key-3": "value-3",
Expand All @@ -141,7 +141,7 @@ func TestRegistry(t *testing.T) {
// Get
{
// Existing key
resp, err := r.GetStageMetadata(ctx, &api.GetStageMetadataRequest{
resp, err := r.GetStageMetadata(ctx, &service.GetStageMetadataRequest{
DeploymentId: d.Id,
StageId: "stage-2",
Key: "stage-2-key-1",
Expand All @@ -151,7 +151,7 @@ func TestRegistry(t *testing.T) {
assert.Equal(t, "stage-2-value-1", resp.Value)

// Nonexistent key
resp, err = r.GetStageMetadata(ctx, &api.GetStageMetadataRequest{
resp, err = r.GetStageMetadata(ctx, &service.GetStageMetadataRequest{
DeploymentId: d.Id,
StageId: "stage-1",
Key: "not-exist-key",
Expand All @@ -161,7 +161,7 @@ func TestRegistry(t *testing.T) {
assert.Equal(t, "", resp.Value)

// Nonexistent stage
resp, err = r.GetStageMetadata(ctx, &api.GetStageMetadataRequest{
resp, err = r.GetStageMetadata(ctx, &service.GetStageMetadataRequest{
DeploymentId: d.Id,
StageId: "not-exist-stage",
Key: "key-1",
Expand All @@ -171,7 +171,7 @@ func TestRegistry(t *testing.T) {
assert.Equal(t, "", resp.Value)

// Nonexistent deployment
resp, err = r.GetStageMetadata(ctx, &api.GetStageMetadataRequest{
resp, err = r.GetStageMetadata(ctx, &service.GetStageMetadataRequest{
DeploymentId: "not-exist-id",
StageId: "stage-1",
Key: "key-1",
Expand All @@ -183,7 +183,7 @@ func TestRegistry(t *testing.T) {
// Put
{
// New key
_, err := r.PutStageMetadata(ctx, &api.PutStageMetadataRequest{
_, err := r.PutStageMetadata(ctx, &service.PutStageMetadataRequest{
DeploymentId: d.Id,
StageId: "stage-1",
Key: "stage-1-key-1",
Expand All @@ -195,7 +195,7 @@ func TestRegistry(t *testing.T) {
}, ac.stages["stage-1"])

// Nonexistent deployment
_, err = r.PutStageMetadata(ctx, &api.PutStageMetadataRequest{
_, err = r.PutStageMetadata(ctx, &service.PutStageMetadataRequest{
DeploymentId: "not-exist-id",
StageId: "stage-1",
Key: "stage-1-key-1",
Expand All @@ -206,7 +206,7 @@ func TestRegistry(t *testing.T) {
// PutMulti
{
// New key(2) with one existing key(1)
_, err := r.PutStageMetadataMulti(ctx, &api.PutStageMetadataMultiRequest{
_, err := r.PutStageMetadataMulti(ctx, &service.PutStageMetadataMultiRequest{
DeploymentId: d.Id,
StageId: "stage-2",
Metadata: map[string]string{
Expand All @@ -226,7 +226,7 @@ func TestRegistry(t *testing.T) {
}, ac.stages)

// Nonexistent deployment
_, err = r.PutStageMetadataMulti(ctx, &api.PutStageMetadataMultiRequest{
_, err = r.PutStageMetadataMulti(ctx, &service.PutStageMetadataMultiRequest{
DeploymentId: "not-exist-id",
StageId: "stage-1",
Metadata: map[string]string{
Expand Down

0 comments on commit b53f980

Please sign in to comment.