Skip to content

Commit

Permalink
Add consts and validation of accessType
Browse files Browse the repository at this point in the history
Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
  • Loading branch information
t-kikuc committed Nov 23, 2023
1 parent 95055cd commit 919cc3c
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
22 changes: 21 additions & 1 deletion pkg/config/application_ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ package config

import (
"encoding/json"
"fmt"
)

const (
accessTypeELB string = "ELB"
accessTypeServiveDiscovery string = "SERVICE_DISCOVERY"
)

// ECSApplicationSpec represents an application configuration for ECS application.
Expand All @@ -32,6 +38,11 @@ func (s *ECSApplicationSpec) Validate() error {
if err := s.GenericApplicationSpec.Validate(); err != nil {
return err
}

if err := s.Input.validateAccessType(); err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -70,7 +81,7 @@ func (in *ECSDeploymentInput) IsStandaloneTask() bool {
}

func (in *ECSDeploymentInput) IsAccessedViaELB() bool {
return in.AccessType == "ELB"
return in.AccessType == accessTypeELB
}

type ECSVpcConfiguration struct {
Expand Down Expand Up @@ -131,3 +142,12 @@ func (opts ECSTrafficRoutingStageOptions) Percentage() (primary, canary int) {
canary = 0
return
}

func (in *ECSDeploymentInput) validateAccessType() error {
switch in.AccessType {
case accessTypeELB, accessTypeServiveDiscovery:
return nil
default:
return fmt.Errorf("invalid accessType: %s", in.AccessType)
}
}
35 changes: 35 additions & 0 deletions pkg/config/application_ecs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package config

import (
"encoding/json"
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -103,6 +104,40 @@ func TestECSApplicationConfig(t *testing.T) {
},
expectedError: nil,
},
{
fileName: "testdata/application/ecs-app-invalid-access-type.yaml",
expectedKind: KindECSApp,
expectedAPIVersion: "pipecd.dev/v1beta1",
expectedSpec: &ECSApplicationSpec{
GenericApplicationSpec: GenericApplicationSpec{
Timeout: Duration(6 * time.Hour),
Trigger: Trigger{
OnCommit: OnCommit{
Disabled: false,
},
OnCommand: OnCommand{
Disabled: false,
},
OnOutOfSync: OnOutOfSync{
Disabled: newBoolPointer(true),
MinWindow: Duration(5 * time.Minute),
},
OnChain: OnChain{
Disabled: newBoolPointer(true),
},
},
},
Input: ECSDeploymentInput{
ServiceDefinitionFile: "/path/to/servicedef.yaml",
TaskDefinitionFile: "/path/to/taskdef.yaml",
LaunchType: "FARGATE",
AutoRollback: newBoolPointer(true),
RunStandaloneTask: newBoolPointer(true),
AccessType: "XXX",
},
},
expectedError: fmt.Errorf("invalid accessType: XXX"),
},
}
for _, tc := range testcases {
t.Run(tc.fileName, func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: pipecd.dev/v1beta1
kind: ECSApp
spec:
input:
serviceDefinitionFile: /path/to/servicedef.yaml
taskDefinitionFile: /path/to/taskdef.yaml
accessType: XXX

0 comments on commit 919cc3c

Please sign in to comment.