-
Notifications
You must be signed in to change notification settings - Fork 799
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Yi Cai <[email protected]>
- Loading branch information
Showing
5 changed files
with
102 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package applicationset | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/argoproj-labs/argocd-operator/controllers/argocd/argocdcommon" | ||
"github.com/stretchr/testify/assert" | ||
|
||
appsv1 "k8s.io/api/apps/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
func TestApplicationSetReconciler_reconcileDeployment(t *testing.T) { | ||
resourceName = argocdcommon.TestArgoCDName | ||
resourceLabels = testExpectedLabels | ||
ns := argocdcommon.MakeTestNamespace() | ||
asr := makeTestApplicationSetReconciler(t, ns) | ||
|
||
existingDeployment := asr.getDesiredDeployment() | ||
|
||
tests := []struct { | ||
name string | ||
setupClient func() *ApplicationSetReconciler | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "create a deployment", | ||
setupClient: func() *ApplicationSetReconciler { | ||
return makeTestApplicationSetReconciler(t, ns) | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "update a deployment", | ||
setupClient: func() *ApplicationSetReconciler { | ||
outdatedDeployment := existingDeployment | ||
outdatedDeployment.ObjectMeta.Labels = argocdcommon.TestKVP | ||
return makeTestApplicationSetReconciler(t, outdatedDeployment, ns) | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
asr := tt.setupClient() | ||
err := asr.reconcileDeployment() | ||
if (err != nil) != tt.wantErr { | ||
if tt.wantErr { | ||
t.Errorf("Expected error but did not get one") | ||
} else { | ||
t.Errorf("Unexpected error: %v", err) | ||
} | ||
} | ||
|
||
updatedDeployment := &appsv1.Deployment{} | ||
err = asr.Client.Get(context.TODO(), types.NamespacedName{Name: resourceName, Namespace: argocdcommon.TestNamespace}, updatedDeployment) | ||
if err != nil { | ||
t.Fatalf("Could not get updated Deployment: %v", err) | ||
} | ||
assert.Equal(t, testExpectedLabels, updatedDeployment.ObjectMeta.Labels) | ||
}) | ||
} | ||
} | ||
|
||
func TestApplicationSetReconciler_DeleteDeployment(t *testing.T) { | ||
ns := argocdcommon.MakeTestNamespace() | ||
resourceName = argocdcommon.TestArgoCDName | ||
tests := []struct { | ||
name string | ||
setupClient func() *ApplicationSetReconciler | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "successful delete", | ||
setupClient: func() *ApplicationSetReconciler { | ||
return makeTestApplicationSetReconciler(t, ns) | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
nr := tt.setupClient() | ||
if err := nr.DeleteDeployment(resourceName, ns.Name); (err != nil) != tt.wantErr { | ||
if tt.wantErr { | ||
t.Errorf("Expected error but did not get one") | ||
} else { | ||
t.Errorf("Unexpected error: %v", err) | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters