Skip to content

Commit

Permalink
rename handle err, remove unessacarry value test
Browse files Browse the repository at this point in the history
Signed-off-by: hungran <26101787+hungran@users.noreply.github.com>
  • Loading branch information
hungran committed Jul 23, 2023
1 parent cb04b9b commit 0ed97c5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
4 changes: 2 additions & 2 deletions pkg/app/piped/platformprovider/kubernetes/applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (a *applier) ApplyManifest(ctx context.Context, manifest Manifest) error {
a.platformProvider.KubeConfigPath,
a.getNamespaceToRun(manifest.Key),
)
if err != nil && !errors.Is(err, errReplaceAlreadyExists) {
if err != nil && !errors.Is(err, errResourceAlreadyExists) {
return err
}
}
Expand Down Expand Up @@ -98,7 +98,7 @@ func (a *applier) CreateManifest(ctx context.Context, manifest Manifest) error {
a.platformProvider.KubeConfigPath,
a.getNamespaceToRun(manifest.Key),
)
if err != nil && !errors.Is(err, errReplaceAlreadyExists) {
if err != nil && !errors.Is(err, errResourceAlreadyExists) {
return err
}
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/app/piped/platformprovider/kubernetes/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ import (
)

var (
errorReplaceNotFound = errors.New("specified resource is not found")
errorNotFoundLiteral = "Error from server (NotFound)"
errReplaceAlreadyExists = errors.New("resource already exists")
errAlreadyExistsLiteral = "Error from server (AlreadyExists)"
errorReplaceNotFound = errors.New("specified resource is not found")
errorNotFoundLiteral = "Error from server (NotFound)"
errResourceAlreadyExists = errors.New("resource already exists")
errAlreadyExistsLiteral = "Error from server (AlreadyExists)"
)

type Kubectl struct {
Expand Down Expand Up @@ -237,7 +237,7 @@ func (c *Kubectl) CreateNamespace(ctx context.Context, kubeconfig, namespace str
out, err := cmd.CombinedOutput()

if strings.Contains(string(out), errAlreadyExistsLiteral) {
return errReplaceAlreadyExists
return errResourceAlreadyExists
}
if err != nil {
return fmt.Errorf("failed to create namespace: %s, %v", string(out), err)
Expand Down
6 changes: 2 additions & 4 deletions pkg/config/application_kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ func TestKubernetesApplicationConfig(t *testing.T) {
},
},
Input: KubernetesDeploymentInput{
AutoRollback: newBoolPointer(true),
AutoCreateNamespace: false,
AutoRollback: newBoolPointer(true),
},
TrafficRouting: &KubernetesTrafficRouting{
Method: KubernetesTrafficRoutingMethodPodSelector,
Expand Down Expand Up @@ -136,8 +135,7 @@ func TestKubernetesApplicationConfig(t *testing.T) {
},
},
Input: KubernetesDeploymentInput{
AutoRollback: newBoolPointer(true),
AutoCreateNamespace: false,
AutoRollback: newBoolPointer(true),
},
VariantLabel: KubernetesVariantLabel{
Key: "pipecd.dev/variant",
Expand Down
15 changes: 5 additions & 10 deletions pkg/config/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,7 @@ func TestGenericTriggerConfiguration(t *testing.T) {
},
},
Input: KubernetesDeploymentInput{
AutoRollback: newBoolPointer(true),
AutoCreateNamespace: false,
AutoRollback: newBoolPointer(true),
},
VariantLabel: KubernetesVariantLabel{
Key: "pipecd.dev/variant",
Expand Down Expand Up @@ -367,8 +366,7 @@ func TestTrueByDefaultBoolConfiguration(t *testing.T) {
},
},
Input: KubernetesDeploymentInput{
AutoRollback: newBoolPointer(true),
AutoCreateNamespace: false,
AutoRollback: newBoolPointer(true),
},
VariantLabel: KubernetesVariantLabel{
Key: "pipecd.dev/variant",
Expand Down Expand Up @@ -397,8 +395,7 @@ func TestTrueByDefaultBoolConfiguration(t *testing.T) {
},
},
Input: KubernetesDeploymentInput{
AutoRollback: newBoolPointer(false),
AutoCreateNamespace: false,
AutoRollback: newBoolPointer(false),
},
VariantLabel: KubernetesVariantLabel{
Key: "pipecd.dev/variant",
Expand Down Expand Up @@ -497,8 +494,7 @@ func TestGenericPostSyncConfiguration(t *testing.T) {
},
},
Input: KubernetesDeploymentInput{
AutoRollback: newBoolPointer(true),
AutoCreateNamespace: false,
AutoRollback: newBoolPointer(true),
},
VariantLabel: KubernetesVariantLabel{
Key: "pipecd.dev/variant",
Expand Down Expand Up @@ -618,8 +614,7 @@ func TestGenericAnalysisConfiguration(t *testing.T) {
},
},
Input: KubernetesDeploymentInput{
AutoRollback: newBoolPointer(true),
AutoCreateNamespace: false,
AutoRollback: newBoolPointer(true),
},
VariantLabel: KubernetesVariantLabel{
Key: "pipecd.dev/variant",
Expand Down

0 comments on commit 0ed97c5

Please sign in to comment.