Skip to content

Commit

Permalink
Fix to use plugins
Browse files Browse the repository at this point in the history
Signed-off-by: Yoshiki Fujikane <[email protected]>
  • Loading branch information
ffjlabo committed Dec 27, 2024
1 parent 374de36 commit 0c4fc0d
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 116 deletions.
7 changes: 5 additions & 2 deletions pkg/app/pipedv1/apistore/applicationstore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,11 @@ func (s *store) ListByPluginName(name string) []*model.Application {
list := apps.([]*model.Application)

for _, app := range list {
if app.Plugin == name {
out = append(out, app)
for _, p := range app.Plugins {
if p == name {
out = append(out, app)
break
}
}
}

Expand Down
89 changes: 89 additions & 0 deletions pkg/app/pipedv1/apistore/applicationstore/store_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright 2024 The PipeCD Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package applicationstore

import (
"testing"

"go.uber.org/atomic"
"go.uber.org/zap/zaptest"

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

Check failure on line 23 in pkg/app/pipedv1/apistore/applicationstore/store_test.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] pkg/app/pipedv1/apistore/applicationstore/store_test.go#L23

File is not `goimports`-ed with -local github.com/pipe-cd/pipecd (goimports)
Raw output
pkg/app/pipedv1/apistore/applicationstore/store_test.go:23: File is not `goimports`-ed with -local github.com/pipe-cd/pipecd (goimports)
	"github.com/pipe-cd/pipecd/pkg/model"
"github.com/stretchr/testify/assert"
)

func TestListByPluginName(t *testing.T) {
logger := zaptest.NewLogger(t)

tests := []struct {
name string
storedApps []*model.Application
plugin string
expected []*model.Application
}{
{
name: "There is no stored application",
storedApps: []*model.Application{},
plugin: "plugin-a",
expected: []*model.Application{},
},
{
name: "no matching",
storedApps: []*model.Application{
{Id: "app-1", Plugins: []string{"plugin-b"}},
{Id: "app-2", Plugins: []string{"plugin-c"}},
},
plugin: "plugin-a",
expected: []*model.Application{},
},
{
name: "one matched application",
storedApps: []*model.Application{
{Id: "app-1", Plugins: []string{"plugin-a", "plugin-b"}},
{Id: "app-2", Plugins: []string{"plugin-b"}},
},
plugin: "plugin-a",
expected: []*model.Application{
{Id: "app-1", Plugins: []string{"plugin-a", "plugin-b"}},
},
},
{
name: "matched some applications",
storedApps: []*model.Application{
{Id: "app-1", Plugins: []string{"plugin-a", "plugin-b"}},
{Id: "app-2", Plugins: []string{"plugin-a"}},
{Id: "app-3", Plugins: []string{"plugin-b"}},
},
plugin: "plugin-a",
expected: []*model.Application{
{Id: "app-1", Plugins: []string{"plugin-a", "plugin-b"}},
{Id: "app-2", Plugins: []string{"plugin-a"}},
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &store{
applicationList: atomic.Value{},
logger: logger,
}
s.applicationList.Store(tt.storedApps)

got := s.ListByPluginName(tt.plugin)
assert.Equal(t, tt.expected, got)
})
}
}
191 changes: 96 additions & 95 deletions pkg/model/application.pb.go

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions pkg/model/application.pb.validate.go

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

4 changes: 2 additions & 2 deletions pkg/model/application.proto
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ message Application {
string platform_provider = 15;
// The names of deploy taget where to deploy this application.
repeated string deploy_targets = 16;
// The name of plugin used to deploy this application.
string plugin = 17;
// The names of plugin used to deploy this application.
repeated string plugins = 17;
// Additional description about application.
string description = 9;
// Custom attributes to identify applications.
Expand Down
8 changes: 5 additions & 3 deletions web/model/application_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ export class Application extends jspb.Message {
clearDeployTargetsList(): Application;
addDeployTargets(value: string, index?: number): Application;

getPlugin(): string;
setPlugin(value: string): Application;
getPluginsList(): Array<string>;
setPluginsList(value: Array<string>): Application;
clearPluginsList(): Application;
addPlugins(value: string, index?: number): Application;

getDescription(): string;
setDescription(value: string): Application;
Expand Down Expand Up @@ -98,7 +100,7 @@ export namespace Application {
cloudProvider: string,
platformProvider: string,
deployTargetsList: Array<string>,
plugin: string,
pluginsList: Array<string>,
description: string,
labelsMap: Array<[string, string]>,
mostRecentlySuccessfulDeployment?: ApplicationDeploymentReference.AsObject,
Expand Down
41 changes: 30 additions & 11 deletions web/model/application_pb.js

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

3 changes: 2 additions & 1 deletion web/src/__fixtures__/dummy-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const dummyApplication: Application.AsObject = {
cloudProvider: "",
platformProvider: "kubernetes-default",
deployTargetsList: ["kubernetes-default"],
plugin: "",
pluginsList: ["kubernetes"],
disabled: false,
gitPath: {
configFilename: "",
Expand Down Expand Up @@ -134,6 +134,7 @@ export function createApplicationFromObject(
app.setId(o.id);
app.setPlatformProvider(o.platformProvider);
app.setDeployTargetsList(o.deployTargetsList);
app.setPluginsList(o.pluginsList);
app.setDisabled(o.disabled);
app.setKind(o.kind);
app.setName(o.name);
Expand Down

0 comments on commit 0c4fc0d

Please sign in to comment.