Skip to content
Open
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
5 changes: 3 additions & 2 deletions plugins/azure-functions/deployment/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package deployment

import (
"context"
"fmt"

sdk "github.com/pipe-cd/piped-plugin-sdk-go"

Expand Down Expand Up @@ -50,7 +51,7 @@ func (p *Plugin) ExecuteStage(ctx context.Context, _ *sdk.ConfigNone, dts []*sdk
Status: p.executeAzureFuncRollbackStage(ctx, dts, input),
}, nil
default:
panic("unimplemented stage: " + input.Request.StageName)
return nil, fmt.Errorf("unimplemented stage: %q", input.Request.StageName)
}
}

Expand All @@ -76,7 +77,7 @@ func (p *Plugin) DetermineVersions(ctx context.Context, _ *sdk.ConfigNone, d *sd
},
}, nil
default:
panic("not supported kind: " + appCfg.Spec.Kind)
return nil, fmt.Errorf("not supported kind: %q", appCfg.Spec.Kind)
}
}

Expand Down
101 changes: 101 additions & 0 deletions plugins/azure-functions/deployment/plugin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright 2025 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 deployment

import (
"testing"

sdk "github.com/pipe-cd/piped-plugin-sdk-go"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/pipe-cd/community-plugins/plugins/azure-functions/config"
)

// Test_ExecuteStage_UnknownStage ensures that an unrecognized stage name
// results in an error instead of a panic, since the stage name originates
// from the pipeline configuration and can be malformed or unsupported.
func Test_ExecuteStage_UnknownStage(t *testing.T) {
t.Parallel()

p := &Plugin{}

got, err := p.ExecuteStage(t.Context(), nil, nil, &sdk.ExecuteStageInput[config.AzureApplicationSpec]{
Request: sdk.ExecuteStageRequest[config.AzureApplicationSpec]{
StageName: "UNKNOWN_STAGE",
},
})

require.Error(t, err)
assert.Nil(t, got)
assert.Contains(t, err.Error(), "UNKNOWN_STAGE")
}

// Test_DetermineVersions_UnsupportedKind ensures that an application spec
// with an unsupported "kind" results in an error instead of a panic, since
// the kind comes directly from the user-authored application config file.
func Test_DetermineVersions_UnsupportedKind(t *testing.T) {
t.Parallel()

p := &Plugin{}

appCfg := &sdk.ApplicationConfig[config.AzureApplicationSpec]{
Spec: &config.AzureApplicationSpec{
Kind: "unsupported-kind",
},
}

got, err := p.DetermineVersions(t.Context(), nil, &sdk.DetermineVersionsInput[config.AzureApplicationSpec]{
Request: sdk.DetermineVersionsRequest[config.AzureApplicationSpec]{
DeploymentSource: sdk.DeploymentSource[config.AzureApplicationSpec]{
ApplicationConfig: appCfg,
},
},
})

require.Error(t, err)
assert.Nil(t, got)
assert.Contains(t, err.Error(), "unsupported-kind")
}

// Test_DetermineVersions_FunctionKind ensures the existing, supported
// behavior for the "function" kind is preserved.
func Test_DetermineVersions_FunctionKind(t *testing.T) {
t.Parallel()

p := &Plugin{}

appCfg := &sdk.ApplicationConfig[config.AzureApplicationSpec]{
Spec: &config.AzureApplicationSpec{
Kind: config.FunctionKind,
FunctionManifest: &config.FunctionsSpec{
PackageUri: "https://example.blob.core.windows.net/pkg.zip",
},
},
}

got, err := p.DetermineVersions(t.Context(), nil, &sdk.DetermineVersionsInput[config.AzureApplicationSpec]{
Request: sdk.DetermineVersionsRequest[config.AzureApplicationSpec]{
DeploymentSource: sdk.DeploymentSource[config.AzureApplicationSpec]{
ApplicationConfig: appCfg,
},
},
})

require.NoError(t, err)
require.NotNil(t, got)
require.Len(t, got.Versions, 1)
assert.Equal(t, "https://example.blob.core.windows.net/pkg.zip", got.Versions[0].Version)
}
4 changes: 4 additions & 0 deletions plugins/azure-functions/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.8.0
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.6.1
github.com/pipe-cd/piped-plugin-sdk-go v0.0.0-20250606012947-e00f415619d0
github.com/stretchr/testify v1.10.0
go.uber.org/zap v1.27.0
)

Expand All @@ -27,6 +28,7 @@ require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/coreos/go-oidc/v3 v3.11.0 // indirect
github.com/creasty/defaults v1.6.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect
github.com/go-jose/go-jose/v4 v4.0.5 // indirect
github.com/go-logr/logr v1.4.2 // indirect
Expand All @@ -45,6 +47,7 @@ require (
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/pipe-cd/pipecd v0.52.0 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.12.1 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
Expand Down Expand Up @@ -72,5 +75,6 @@ require (
google.golang.org/grpc v1.64.1 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading