-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* add unit test reproducing Signed-off-by: rumstead <rjumstead@gmail.com> Signed-off-by: rumstead <37445536+rumstead@users.noreply.github.com> * feat: Begin polishing top bar design (#12327) Signed-off-by: rumstead <37445536+rumstead@users.noreply.github.com> * chore: add dist to path to use our kustomize version (#12352) * chore: add dist to path to use our kustomize version Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * correct path Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * missed a spot Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> --------- Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Signed-off-by: rumstead <37445536+rumstead@users.noreply.github.com> * fix: when resource does not exist node menu and resource details shou… (#12360) * fix: when resource does not exist node menu and resource details should still render Signed-off-by: Joshua Helton <jdoghelton@gmail.com> * Retrigger CI pipeline Signed-off-by: Joshua Helton <jdoghelton@gmail.com> --------- Signed-off-by: Joshua Helton <jdoghelton@gmail.com> Signed-off-by: rumstead <37445536+rumstead@users.noreply.github.com> * fix: traverse generator tree when getting requeue time Signed-off-by: rumstead <37445536+rumstead@users.noreply.github.com> * fix: traverse generator tree when getting requeue time Signed-off-by: rumstead <37445536+rumstead@users.noreply.github.com> * remove duplicate code Signed-off-by: rumstead <37445536+rumstead@users.noreply.github.com> * Retrigger CI pipeline Signed-off-by: rumstead <37445536+rumstead@users.noreply.github.com> * revert gitignore Signed-off-by: rumstead <37445536+rumstead@users.noreply.github.com> * update from code review Signed-off-by: rumstead <37445536+rumstead@users.noreply.github.com> --------- Signed-off-by: rumstead <rjumstead@gmail.com> Signed-off-by: rumstead <37445536+rumstead@users.noreply.github.com> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Signed-off-by: Joshua Helton <jdoghelton@gmail.com> Co-authored-by: Remington Breeze <remington@breeze.software> Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Co-authored-by: jphelton <jdoghelton@gmail.com>
- Loading branch information
1 parent
2b1d55b
commit 53c3c49
Showing
4 changed files
with
231 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
package controllers | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/argoproj/argo-cd/v2/applicationset/generators" | ||
argov1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
dynfake "k8s.io/client-go/dynamic/fake" | ||
kubefake "k8s.io/client-go/kubernetes/fake" | ||
"k8s.io/client-go/tools/record" | ||
"sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
) | ||
|
||
func TestRequeueAfter(t *testing.T) { | ||
mockServer := argoCDServiceMock{} | ||
ctx := context.Background() | ||
scheme := runtime.NewScheme() | ||
err := argov1alpha1.AddToScheme(scheme) | ||
assert.Nil(t, err) | ||
gvrToListKind := map[schema.GroupVersionResource]string{{ | ||
Group: "mallard.io", | ||
Version: "v1", | ||
Resource: "ducks", | ||
}: "DuckList"} | ||
appClientset := kubefake.NewSimpleClientset() | ||
k8sClient := fake.NewClientBuilder().Build() | ||
duckType := &unstructured.Unstructured{ | ||
Object: map[string]interface{}{ | ||
"apiVersion": "v2quack", | ||
"kind": "Duck", | ||
"metadata": map[string]interface{}{ | ||
"name": "mightyduck", | ||
"namespace": "namespace", | ||
"labels": map[string]interface{}{"duck": "all-species"}, | ||
}, | ||
"status": map[string]interface{}{ | ||
"decisions": []interface{}{ | ||
map[string]interface{}{ | ||
"clusterName": "staging-01", | ||
}, | ||
map[string]interface{}{ | ||
"clusterName": "production-01", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
fakeDynClient := dynfake.NewSimpleDynamicClientWithCustomListKinds(runtime.NewScheme(), gvrToListKind, duckType) | ||
|
||
terminalGenerators := map[string]generators.Generator{ | ||
"List": generators.NewListGenerator(), | ||
"Clusters": generators.NewClusterGenerator(k8sClient, ctx, appClientset, "argocd"), | ||
"Git": generators.NewGitGenerator(mockServer), | ||
"SCMProvider": generators.NewSCMProviderGenerator(fake.NewClientBuilder().WithObjects(&corev1.Secret{}).Build(), generators.SCMAuthProviders{}), | ||
"ClusterDecisionResource": generators.NewDuckTypeGenerator(ctx, fakeDynClient, appClientset, "argocd"), | ||
"PullRequest": generators.NewPullRequestGenerator(k8sClient, generators.SCMAuthProviders{}), | ||
} | ||
|
||
nestedGenerators := map[string]generators.Generator{ | ||
"List": terminalGenerators["List"], | ||
"Clusters": terminalGenerators["Clusters"], | ||
"Git": terminalGenerators["Git"], | ||
"SCMProvider": terminalGenerators["SCMProvider"], | ||
"ClusterDecisionResource": terminalGenerators["ClusterDecisionResource"], | ||
"PullRequest": terminalGenerators["PullRequest"], | ||
"Matrix": generators.NewMatrixGenerator(terminalGenerators), | ||
"Merge": generators.NewMergeGenerator(terminalGenerators), | ||
} | ||
|
||
topLevelGenerators := map[string]generators.Generator{ | ||
"List": terminalGenerators["List"], | ||
"Clusters": terminalGenerators["Clusters"], | ||
"Git": terminalGenerators["Git"], | ||
"SCMProvider": terminalGenerators["SCMProvider"], | ||
"ClusterDecisionResource": terminalGenerators["ClusterDecisionResource"], | ||
"PullRequest": terminalGenerators["PullRequest"], | ||
"Matrix": generators.NewMatrixGenerator(nestedGenerators), | ||
"Merge": generators.NewMergeGenerator(nestedGenerators), | ||
} | ||
|
||
client := fake.NewClientBuilder().WithScheme(scheme).Build() | ||
r := ApplicationSetReconciler{ | ||
Client: client, | ||
Scheme: scheme, | ||
Recorder: record.NewFakeRecorder(0), | ||
Generators: topLevelGenerators, | ||
} | ||
|
||
type args struct { | ||
appset *argov1alpha1.ApplicationSet | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want time.Duration | ||
wantErr assert.ErrorAssertionFunc | ||
}{ | ||
{name: "Cluster", args: args{appset: &argov1alpha1.ApplicationSet{ | ||
Spec: argov1alpha1.ApplicationSetSpec{ | ||
Generators: []argov1alpha1.ApplicationSetGenerator{{Clusters: &argov1alpha1.ClusterGenerator{}}}, | ||
}, | ||
}}, want: generators.NoRequeueAfter, wantErr: assert.NoError}, | ||
{name: "ClusterMergeNested", args: args{&argov1alpha1.ApplicationSet{ | ||
Spec: argov1alpha1.ApplicationSetSpec{ | ||
Generators: []argov1alpha1.ApplicationSetGenerator{ | ||
{Clusters: &argov1alpha1.ClusterGenerator{}}, | ||
{Merge: &argov1alpha1.MergeGenerator{ | ||
Generators: []argov1alpha1.ApplicationSetNestedGenerator{ | ||
{ | ||
Clusters: &argov1alpha1.ClusterGenerator{}, | ||
Git: &argov1alpha1.GitGenerator{}, | ||
}, | ||
}, | ||
}}, | ||
}, | ||
}, | ||
}}, want: generators.DefaultRequeueAfterSeconds, wantErr: assert.NoError}, | ||
{name: "ClusterMatrixNested", args: args{&argov1alpha1.ApplicationSet{ | ||
Spec: argov1alpha1.ApplicationSetSpec{ | ||
Generators: []argov1alpha1.ApplicationSetGenerator{ | ||
{Clusters: &argov1alpha1.ClusterGenerator{}}, | ||
{Matrix: &argov1alpha1.MatrixGenerator{ | ||
Generators: []argov1alpha1.ApplicationSetNestedGenerator{ | ||
{ | ||
Clusters: &argov1alpha1.ClusterGenerator{}, | ||
Git: &argov1alpha1.GitGenerator{}, | ||
}, | ||
}, | ||
}}, | ||
}, | ||
}, | ||
}}, want: generators.DefaultRequeueAfterSeconds, wantErr: assert.NoError}, | ||
{name: "ListGenerator", args: args{appset: &argov1alpha1.ApplicationSet{ | ||
Spec: argov1alpha1.ApplicationSetSpec{ | ||
Generators: []argov1alpha1.ApplicationSetGenerator{{List: &argov1alpha1.ListGenerator{}}}, | ||
}, | ||
}}, want: generators.NoRequeueAfter, wantErr: assert.NoError}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
assert.Equalf(t, tt.want, r.getMinRequeueAfter(tt.args.appset), "getMinRequeueAfter(%v)", tt.args.appset) | ||
}) | ||
} | ||
} | ||
|
||
type argoCDServiceMock struct { | ||
mock *mock.Mock | ||
} | ||
|
||
func (a argoCDServiceMock) GetApps(ctx context.Context, repoURL string, revision string) ([]string, error) { | ||
args := a.mock.Called(ctx, repoURL, revision) | ||
|
||
return args.Get(0).([]string), args.Error(1) | ||
} | ||
|
||
func (a argoCDServiceMock) GetFiles(ctx context.Context, repoURL string, revision string, pattern string) (map[string][]byte, error) { | ||
args := a.mock.Called(ctx, repoURL, revision, pattern) | ||
|
||
return args.Get(0).(map[string][]byte), args.Error(1) | ||
} | ||
|
||
func (a argoCDServiceMock) GetFileContent(ctx context.Context, repoURL string, revision string, path string) ([]byte, error) { | ||
args := a.mock.Called(ctx, repoURL, revision, path) | ||
|
||
return args.Get(0).([]byte), args.Error(1) | ||
} | ||
|
||
func (a argoCDServiceMock) GetDirectories(ctx context.Context, repoURL string, revision string) ([]string, error) { | ||
args := a.mock.Called(ctx, repoURL, revision) | ||
return args.Get(0).([]string), args.Error(1) | ||
} |
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