mirror of
https://github.com/argoproj/argo-cd
synced 2026-04-21 17:07:16 +00:00
chore: enable thelper linter (#20405)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
parent
f031f490e6
commit
cc989251ef
59 changed files with 146 additions and 7 deletions
|
|
@ -20,6 +20,7 @@ linters:
|
|||
- misspell
|
||||
- staticcheck
|
||||
- testifylint
|
||||
- thelper
|
||||
- unparam
|
||||
- unused
|
||||
- usestdlibvars
|
||||
|
|
|
|||
|
|
@ -2246,6 +2246,7 @@ func TestSetApplicationSetStatusCondition(t *testing.T) {
|
|||
},
|
||||
},
|
||||
testfunc: func(t *testing.T, appset v1alpha1.ApplicationSet) {
|
||||
t.Helper()
|
||||
assert.Len(t, appset.Status.Conditions, 3)
|
||||
},
|
||||
},
|
||||
|
|
@ -2281,6 +2282,7 @@ func TestSetApplicationSetStatusCondition(t *testing.T) {
|
|||
},
|
||||
},
|
||||
testfunc: func(t *testing.T, appset v1alpha1.ApplicationSet) {
|
||||
t.Helper()
|
||||
assert.Len(t, appset.Status.Conditions, 3)
|
||||
|
||||
isProgressingCondition := false
|
||||
|
|
@ -2343,6 +2345,7 @@ func TestSetApplicationSetStatusCondition(t *testing.T) {
|
|||
},
|
||||
},
|
||||
testfunc: func(t *testing.T, appset v1alpha1.ApplicationSet) {
|
||||
t.Helper()
|
||||
assert.Len(t, appset.Status.Conditions, 4)
|
||||
|
||||
isProgressingCondition := false
|
||||
|
|
@ -2389,6 +2392,7 @@ func TestSetApplicationSetStatusCondition(t *testing.T) {
|
|||
}
|
||||
|
||||
func applicationsUpdateSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alpha1.ApplicationsSyncPolicy, recordBuffer int, allowPolicyOverride bool) v1alpha1.Application {
|
||||
t.Helper()
|
||||
scheme := runtime.NewScheme()
|
||||
err := v1alpha1.AddToScheme(scheme)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -2550,6 +2554,7 @@ func TestUpdatePerformedWithSyncPolicyCreateOnlyAndAllowPolicyOverrideFalse(t *t
|
|||
}
|
||||
|
||||
func applicationsDeleteSyncPolicyTest(t *testing.T, applicationsSyncPolicy v1alpha1.ApplicationsSyncPolicy, recordBuffer int, allowPolicyOverride bool) v1alpha1.ApplicationList {
|
||||
t.Helper()
|
||||
scheme := runtime.NewScheme()
|
||||
err := v1alpha1.AddToScheme(scheme)
|
||||
require.NoError(t, err)
|
||||
|
|
|
|||
|
|
@ -197,6 +197,7 @@ func TestMergeGenerate(t *testing.T) {
|
|||
}
|
||||
|
||||
func toAPIExtensionsJSON(t *testing.T, g interface{}) *apiextensionsv1.JSON {
|
||||
t.Helper()
|
||||
resVal, err := json.Marshal(g)
|
||||
if err != nil {
|
||||
t.Error("unable to unmarshal json", g)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import (
|
|||
)
|
||||
|
||||
func defaultHandlerCloud(t *testing.T) func(http.ResponseWriter, *http.Request) {
|
||||
t.Helper()
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
var err error
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import (
|
|||
)
|
||||
|
||||
func defaultHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
|
||||
t.Helper()
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
var err error
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import (
|
|||
)
|
||||
|
||||
func giteaMockHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
|
||||
t.Helper()
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
fmt.Println(r.RequestURI)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import (
|
|||
)
|
||||
|
||||
func writeMRListResponse(t *testing.T, w io.Writer) {
|
||||
t.Helper()
|
||||
f, err := os.Open("fixtures/gitlab_mr_list_response.json")
|
||||
if err != nil {
|
||||
t.Fatalf("error opening fixture file: %v", err)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import (
|
|||
)
|
||||
|
||||
func defaultHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
|
||||
t.Helper()
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
var err error
|
||||
|
|
@ -82,6 +83,7 @@ func defaultHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
|
|||
}
|
||||
|
||||
func verifyDefaultRepo(t *testing.T, err error, repos []*Repository) {
|
||||
t.Helper()
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, repos, 1)
|
||||
assert.Equal(t, Repository{
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import (
|
|||
)
|
||||
|
||||
func giteaMockHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
|
||||
t.Helper()
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
switch r.RequestURI {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import (
|
|||
)
|
||||
|
||||
func githubMockHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
|
||||
t.Helper()
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
switch r.RequestURI {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import (
|
|||
)
|
||||
|
||||
func gitlabMockHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
|
||||
t.Helper()
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
switch r.RequestURI {
|
||||
|
|
|
|||
|
|
@ -2196,6 +2196,7 @@ func TestAlreadyAttemptSync(t *testing.T) {
|
|||
}
|
||||
|
||||
func assertDurationAround(t *testing.T, expected time.Duration, actual time.Duration) {
|
||||
t.Helper()
|
||||
delta := time.Second / 2
|
||||
assert.GreaterOrEqual(t, expected, actual-delta)
|
||||
assert.LessOrEqual(t, expected, actual+delta)
|
||||
|
|
|
|||
|
|
@ -467,6 +467,7 @@ func assertMetricsPrinted(t *testing.T, expectedLines, body string) {
|
|||
|
||||
// assertMetricsNotPrinted
|
||||
func assertMetricsNotPrinted(t *testing.T, expectedLines, body string) {
|
||||
t.Helper()
|
||||
for _, line := range strings.Split(expectedLines, "\n") {
|
||||
if line == "" {
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -836,6 +836,7 @@ func TestGetClusterSharding(t *testing.T) {
|
|||
{
|
||||
name: "Default sharding with statefulset",
|
||||
envsSetter: func(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Setenv(common.EnvControllerReplicas, "1")
|
||||
},
|
||||
cleanup: func() {},
|
||||
|
|
@ -847,6 +848,7 @@ func TestGetClusterSharding(t *testing.T) {
|
|||
{
|
||||
name: "Default sharding with deployment",
|
||||
envsSetter: func(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Setenv(common.EnvAppControllerName, common.DefaultApplicationControllerName)
|
||||
},
|
||||
cleanup: func() {},
|
||||
|
|
@ -858,6 +860,7 @@ func TestGetClusterSharding(t *testing.T) {
|
|||
{
|
||||
name: "Default sharding with deployment and multiple replicas",
|
||||
envsSetter: func(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Setenv(common.EnvAppControllerName, "argocd-application-controller-multi-replicas")
|
||||
},
|
||||
cleanup: func() {},
|
||||
|
|
@ -869,6 +872,7 @@ func TestGetClusterSharding(t *testing.T) {
|
|||
{
|
||||
name: "Statefulset multiple replicas",
|
||||
envsSetter: func(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Setenv(common.EnvControllerReplicas, "3")
|
||||
osHostnameFunction = func() (string, error) { return "example-shard-3", nil }
|
||||
},
|
||||
|
|
@ -883,6 +887,7 @@ func TestGetClusterSharding(t *testing.T) {
|
|||
{
|
||||
name: "Explicit shard with statefulset and 1 replica",
|
||||
envsSetter: func(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Setenv(common.EnvControllerReplicas, "1")
|
||||
t.Setenv(common.EnvControllerShard, "3")
|
||||
},
|
||||
|
|
@ -895,6 +900,7 @@ func TestGetClusterSharding(t *testing.T) {
|
|||
{
|
||||
name: "Explicit shard with statefulset and 2 replica - and to high shard",
|
||||
envsSetter: func(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Setenv(common.EnvControllerReplicas, "2")
|
||||
t.Setenv(common.EnvControllerShard, "3")
|
||||
},
|
||||
|
|
@ -907,6 +913,7 @@ func TestGetClusterSharding(t *testing.T) {
|
|||
{
|
||||
name: "Explicit shard with statefulset and 2 replica",
|
||||
envsSetter: func(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Setenv(common.EnvControllerReplicas, "2")
|
||||
t.Setenv(common.EnvControllerShard, "1")
|
||||
},
|
||||
|
|
@ -919,6 +926,7 @@ func TestGetClusterSharding(t *testing.T) {
|
|||
{
|
||||
name: "Explicit shard with deployment",
|
||||
envsSetter: func(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Setenv(common.EnvControllerShard, "3")
|
||||
},
|
||||
cleanup: func() {},
|
||||
|
|
@ -930,6 +938,7 @@ func TestGetClusterSharding(t *testing.T) {
|
|||
{
|
||||
name: "Explicit shard with deployment and multiple replicas will read from configmap",
|
||||
envsSetter: func(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Setenv(common.EnvAppControllerName, "argocd-application-controller-multi-replicas")
|
||||
t.Setenv(common.EnvControllerShard, "3")
|
||||
},
|
||||
|
|
@ -942,6 +951,7 @@ func TestGetClusterSharding(t *testing.T) {
|
|||
{
|
||||
name: "Dynamic sharding but missing deployment",
|
||||
envsSetter: func(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Setenv(common.EnvAppControllerName, "missing-deployment")
|
||||
},
|
||||
cleanup: func() {},
|
||||
|
|
|
|||
|
|
@ -547,6 +547,7 @@ func TestAppRevisionsMultiSource(t *testing.T) {
|
|||
}
|
||||
|
||||
func toJSON(t *testing.T, obj *unstructured.Unstructured) string {
|
||||
t.Helper()
|
||||
data, err := json.Marshal(obj)
|
||||
require.NoError(t, err)
|
||||
return string(data)
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ func TestApplicationSetSetConditions(t *testing.T) {
|
|||
testAppSetCond(ApplicationSetConditionResourcesUpToDate, "bar", tenMinsAgo, ApplicationSetConditionStatusTrue, ApplicationSetReasonApplicationSetUpToDate),
|
||||
},
|
||||
validate: func(t *testing.T, a *ApplicationSet) {
|
||||
t.Helper()
|
||||
assert.Equal(t, fiveMinsAgo, a.Status.Conditions[0].LastTransitionTime)
|
||||
assert.Equal(t, tenMinsAgo, a.Status.Conditions[1].LastTransitionTime)
|
||||
},
|
||||
|
|
@ -120,6 +121,7 @@ func TestApplicationSetSetConditions(t *testing.T) {
|
|||
testAppSetCond(ApplicationSetConditionResourcesUpToDate, "bar", nil, ApplicationSetConditionStatusFalse, ApplicationSetReasonApplicationSetUpToDate),
|
||||
},
|
||||
validate: func(t *testing.T, a *ApplicationSet) {
|
||||
t.Helper()
|
||||
// SetConditions should add timestamps for new conditions.
|
||||
assert.True(t, a.Status.Conditions[0].LastTransitionTime.Time.After(fiveMinsAgo.Time))
|
||||
assert.True(t, a.Status.Conditions[1].LastTransitionTime.Time.After(fiveMinsAgo.Time))
|
||||
|
|
@ -141,6 +143,7 @@ func TestApplicationSetSetConditions(t *testing.T) {
|
|||
testAppSetCond(ApplicationSetConditionResourcesUpToDate, "bar", tenMinsAgo, ApplicationSetConditionStatusTrue, ApplicationSetReasonApplicationSetUpToDate),
|
||||
},
|
||||
validate: func(t *testing.T, a *ApplicationSet) {
|
||||
t.Helper()
|
||||
assert.Equal(t, tenMinsAgo.Time, a.Status.Conditions[0].LastTransitionTime.Time)
|
||||
},
|
||||
},
|
||||
|
|
@ -161,6 +164,7 @@ func TestApplicationSetSetConditions(t *testing.T) {
|
|||
}
|
||||
|
||||
func assertAppSetConditions(t *testing.T, expected []ApplicationSetCondition, actual []ApplicationSetCondition) {
|
||||
t.Helper()
|
||||
assert.Equal(t, len(expected), len(actual))
|
||||
for i := range expected {
|
||||
assert.Equal(t, expected[i].Type, actual[i].Type)
|
||||
|
|
|
|||
|
|
@ -2982,6 +2982,7 @@ func TestSetConditions(t *testing.T) {
|
|||
testCond(ApplicationConditionSharedResourceWarning, "bar", tenMinsAgo),
|
||||
},
|
||||
validate: func(t *testing.T, a *Application) {
|
||||
t.Helper()
|
||||
assert.Equal(t, fiveMinsAgo, a.Status.Conditions[0].LastTransitionTime)
|
||||
assert.Equal(t, tenMinsAgo, a.Status.Conditions[1].LastTransitionTime)
|
||||
},
|
||||
|
|
@ -3002,6 +3003,7 @@ func TestSetConditions(t *testing.T) {
|
|||
testCond(ApplicationConditionSharedResourceWarning, "bar", nil),
|
||||
},
|
||||
validate: func(t *testing.T, a *Application) {
|
||||
t.Helper()
|
||||
// SetConditions should add timestamps for new conditions.
|
||||
assert.True(t, a.Status.Conditions[0].LastTransitionTime.Time.After(fiveMinsAgo.Time))
|
||||
assert.True(t, a.Status.Conditions[1].LastTransitionTime.Time.After(fiveMinsAgo.Time))
|
||||
|
|
@ -3024,6 +3026,7 @@ func TestSetConditions(t *testing.T) {
|
|||
testCond(ApplicationConditionSharedResourceWarning, "bar", tenMinsAgo),
|
||||
},
|
||||
validate: func(t *testing.T, a *Application) {
|
||||
t.Helper()
|
||||
assert.Equal(t, tenMinsAgo.Time, a.Status.Conditions[0].LastTransitionTime.Time)
|
||||
},
|
||||
},
|
||||
|
|
@ -3059,6 +3062,7 @@ func TestSetConditions(t *testing.T) {
|
|||
testCond(ApplicationConditionSharedResourceWarning, "bar", tenMinsAgo),
|
||||
},
|
||||
validate: func(t *testing.T, a *Application) {
|
||||
t.Helper()
|
||||
assert.Equal(t, tenMinsAgo.Time, a.Status.Conditions[0].LastTransitionTime.Time)
|
||||
assert.Equal(t, tenMinsAgo.Time, a.Status.Conditions[1].LastTransitionTime.Time)
|
||||
},
|
||||
|
|
@ -3082,6 +3086,7 @@ func TestSetConditions(t *testing.T) {
|
|||
testCond(ApplicationConditionSharedResourceWarning, "bar changed message", fiveMinsAgo),
|
||||
},
|
||||
validate: func(t *testing.T, a *Application) {
|
||||
t.Helper()
|
||||
assert.Equal(t, tenMinsAgo.Time, a.Status.Conditions[0].LastTransitionTime.Time)
|
||||
assert.Equal(t, fiveMinsAgo.Time, a.Status.Conditions[1].LastTransitionTime.Time)
|
||||
},
|
||||
|
|
@ -3100,6 +3105,7 @@ func TestSetConditions(t *testing.T) {
|
|||
testCond(ApplicationConditionSharedResourceWarning, "bar", tenMinsAgo),
|
||||
},
|
||||
validate: func(t *testing.T, a *Application) {
|
||||
t.Helper()
|
||||
assert.Equal(t, tenMinsAgo.Time, a.Status.Conditions[0].LastTransitionTime.Time)
|
||||
},
|
||||
},
|
||||
|
|
@ -3121,6 +3127,7 @@ func TestSetConditions(t *testing.T) {
|
|||
// difficult to strictly assert on as they can use time.Now(). Elements in each array are assumed
|
||||
// to match positions.
|
||||
func assertConditions(t *testing.T, expected []ApplicationCondition, actual []ApplicationCondition) {
|
||||
t.Helper()
|
||||
assert.Equal(t, len(expected), len(actual))
|
||||
for i := range expected {
|
||||
assert.Equal(t, expected[i].Type, actual[i].Type)
|
||||
|
|
|
|||
1
reposerver/cache/cache_test.go
vendored
1
reposerver/cache/cache_test.go
vendored
|
|
@ -261,6 +261,7 @@ func TestCachedManifestResponse_HashBehavior(t *testing.T) {
|
|||
}
|
||||
|
||||
func getInMemoryCacheContents(t *testing.T, inMemCache *cacheutil.InMemoryCache) map[string]*CachedManifestResponse {
|
||||
t.Helper()
|
||||
items, err := inMemCache.Items(func() interface{} { return &CachedManifestResponse{} })
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
|
|||
1
reposerver/cache/mocks/reposervercache.go
generated
vendored
1
reposerver/cache/mocks/reposervercache.go
generated
vendored
|
|
@ -41,6 +41,7 @@ type CacheCallCounts struct {
|
|||
|
||||
// Checks that the cache was called the expected number of times
|
||||
func (mockCache *MockRepoCache) AssertCacheCalledTimes(t *testing.T, calls *CacheCallCounts) {
|
||||
t.Helper()
|
||||
mockCache.RedisClient.AssertNumberOfCalls(t, "Get", calls.ExternalGets)
|
||||
mockCache.RedisClient.AssertNumberOfCalls(t, "Set", calls.ExternalSets)
|
||||
mockCache.RedisClient.AssertNumberOfCalls(t, "Delete", calls.ExternalDeletes)
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ func TestEdgeCasesAndErrorHandling(t *testing.T) {
|
|||
{
|
||||
name: "lsRemoteParallelismLimitSemaphore is nil",
|
||||
testFunc: func(t *testing.T) {
|
||||
t.Helper()
|
||||
lsRemoteParallelismLimitSemaphore = nil
|
||||
assert.NotPanics(t, func() {
|
||||
NewGitClientEventHandlers(&MetricsServer{})
|
||||
|
|
@ -37,6 +38,7 @@ func TestEdgeCasesAndErrorHandling(t *testing.T) {
|
|||
lsRemoteParallelismLimitSemaphore = nil
|
||||
},
|
||||
testFunc: func(t *testing.T) {
|
||||
t.Helper()
|
||||
assert.NotPanics(t, func() {
|
||||
NewGitClientEventHandlers(&MetricsServer{})
|
||||
})
|
||||
|
|
@ -51,6 +53,7 @@ func TestEdgeCasesAndErrorHandling(t *testing.T) {
|
|||
lsRemoteParallelismLimitSemaphore = nil
|
||||
},
|
||||
testFunc: func(t *testing.T) {
|
||||
t.Helper()
|
||||
assert.NotPanics(t, func() {
|
||||
NewGitClientEventHandlers(&MetricsServer{})
|
||||
})
|
||||
|
|
@ -88,6 +91,7 @@ func TestSemaphoreFunctionality(t *testing.T) {
|
|||
lsRemoteParallelismLimitSemaphore = nil
|
||||
},
|
||||
testFunc: func(t *testing.T) {
|
||||
t.Helper()
|
||||
assert.NotPanics(t, func() {
|
||||
NewGitClientEventHandlers(&MetricsServer{})
|
||||
})
|
||||
|
|
@ -102,6 +106,7 @@ func TestSemaphoreFunctionality(t *testing.T) {
|
|||
lsRemoteParallelismLimitSemaphore = nil
|
||||
},
|
||||
testFunc: func(t *testing.T) {
|
||||
t.Helper()
|
||||
assert.NotPanics(t, func() {
|
||||
NewGitClientEventHandlers(&MetricsServer{})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ func newCacheMocksWithOpts(repoCacheExpiration, revisionCacheExpiration, revisio
|
|||
}
|
||||
|
||||
func newServiceWithMocks(t *testing.T, root string, signed bool) (*Service, *gitmocks.Client, *repoCacheMocks) {
|
||||
t.Helper()
|
||||
root, err := filepath.Abs(root)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
@ -140,6 +141,7 @@ func newServiceWithMocks(t *testing.T, root string, signed bool) (*Service, *git
|
|||
}
|
||||
|
||||
func newServiceWithOpt(t *testing.T, cf clientFunc, root string) (*Service, *gitmocks.Client, *repoCacheMocks) {
|
||||
t.Helper()
|
||||
helmClient := &helmmocks.Client{}
|
||||
gitClient := &gitmocks.Client{}
|
||||
paths := &iomocks.TempPaths{}
|
||||
|
|
@ -162,16 +164,19 @@ func newServiceWithOpt(t *testing.T, cf clientFunc, root string) (*Service, *git
|
|||
}
|
||||
|
||||
func newService(t *testing.T, root string) *Service {
|
||||
t.Helper()
|
||||
service, _, _ := newServiceWithMocks(t, root, false)
|
||||
return service
|
||||
}
|
||||
|
||||
func newServiceWithSignature(t *testing.T, root string) *Service {
|
||||
t.Helper()
|
||||
service, _, _ := newServiceWithMocks(t, root, true)
|
||||
return service
|
||||
}
|
||||
|
||||
func newServiceWithCommitSHA(t *testing.T, root, revision string) *Service {
|
||||
t.Helper()
|
||||
var revisionErr error
|
||||
|
||||
commitSHARegex := regexp.MustCompile("^[0-9A-Fa-f]{40}$")
|
||||
|
|
@ -1842,6 +1847,7 @@ func TestGetAppDetailsWithAppParameterFile(t *testing.T) {
|
|||
t.Run("No app name set and app specific file exists", func(t *testing.T) {
|
||||
service := newService(t, ".")
|
||||
runWithTempTestdata(t, "multi", func(t *testing.T, path string) {
|
||||
t.Helper()
|
||||
details, err := service.GetAppDetails(context.Background(), &apiclient.RepoServerAppDetailsQuery{
|
||||
Repo: &argoappv1.Repository{},
|
||||
Source: &argoappv1.ApplicationSource{
|
||||
|
|
@ -1855,6 +1861,7 @@ func TestGetAppDetailsWithAppParameterFile(t *testing.T) {
|
|||
t.Run("No app specific override", func(t *testing.T) {
|
||||
service := newService(t, ".")
|
||||
runWithTempTestdata(t, "single-global", func(t *testing.T, path string) {
|
||||
t.Helper()
|
||||
details, err := service.GetAppDetails(context.Background(), &apiclient.RepoServerAppDetailsQuery{
|
||||
Repo: &argoappv1.Repository{},
|
||||
Source: &argoappv1.ApplicationSource{
|
||||
|
|
@ -1869,6 +1876,7 @@ func TestGetAppDetailsWithAppParameterFile(t *testing.T) {
|
|||
t.Run("Only app specific override", func(t *testing.T) {
|
||||
service := newService(t, ".")
|
||||
runWithTempTestdata(t, "single-app-only", func(t *testing.T, path string) {
|
||||
t.Helper()
|
||||
details, err := service.GetAppDetails(context.Background(), &apiclient.RepoServerAppDetailsQuery{
|
||||
Repo: &argoappv1.Repository{},
|
||||
Source: &argoappv1.ApplicationSource{
|
||||
|
|
@ -1883,6 +1891,7 @@ func TestGetAppDetailsWithAppParameterFile(t *testing.T) {
|
|||
t.Run("App specific override", func(t *testing.T) {
|
||||
service := newService(t, ".")
|
||||
runWithTempTestdata(t, "multi", func(t *testing.T, path string) {
|
||||
t.Helper()
|
||||
details, err := service.GetAppDetails(context.Background(), &apiclient.RepoServerAppDetailsQuery{
|
||||
Repo: &argoappv1.Repository{},
|
||||
Source: &argoappv1.ApplicationSource{
|
||||
|
|
@ -1897,6 +1906,7 @@ func TestGetAppDetailsWithAppParameterFile(t *testing.T) {
|
|||
t.Run("App specific overrides containing non-mergeable field", func(t *testing.T) {
|
||||
service := newService(t, ".")
|
||||
runWithTempTestdata(t, "multi", func(t *testing.T, path string) {
|
||||
t.Helper()
|
||||
details, err := service.GetAppDetails(context.Background(), &apiclient.RepoServerAppDetailsQuery{
|
||||
Repo: &argoappv1.Repository{},
|
||||
Source: &argoappv1.ApplicationSource{
|
||||
|
|
@ -1911,6 +1921,7 @@ func TestGetAppDetailsWithAppParameterFile(t *testing.T) {
|
|||
t.Run("Broken app-specific overrides", func(t *testing.T) {
|
||||
service := newService(t, ".")
|
||||
runWithTempTestdata(t, "multi", func(t *testing.T, path string) {
|
||||
t.Helper()
|
||||
_, err := service.GetAppDetails(context.Background(), &apiclient.RepoServerAppDetailsQuery{
|
||||
Repo: &argoappv1.Repository{},
|
||||
Source: &argoappv1.ApplicationSource{
|
||||
|
|
@ -1943,6 +1954,7 @@ func mkTempParameters(source string) string {
|
|||
// Simple wrapper run a test with a temporary copy of the testdata, because
|
||||
// the test would modify the data when run.
|
||||
func runWithTempTestdata(t *testing.T, path string, runner func(t *testing.T, path string)) {
|
||||
t.Helper()
|
||||
tempDir := mkTempParameters("./testdata/app-parameters")
|
||||
runner(t, filepath.Join(tempDir, "app-parameters", path))
|
||||
os.RemoveAll(tempDir)
|
||||
|
|
@ -1951,6 +1963,7 @@ func runWithTempTestdata(t *testing.T, path string, runner func(t *testing.T, pa
|
|||
func TestGenerateManifestsWithAppParameterFile(t *testing.T) {
|
||||
t.Run("Single global override", func(t *testing.T) {
|
||||
runWithTempTestdata(t, "single-global", func(t *testing.T, path string) {
|
||||
t.Helper()
|
||||
service := newService(t, ".")
|
||||
manifests, err := service.GenerateManifest(context.Background(), &apiclient.ManifestRequest{
|
||||
Repo: &argoappv1.Repository{},
|
||||
|
|
@ -1980,6 +1993,7 @@ func TestGenerateManifestsWithAppParameterFile(t *testing.T) {
|
|||
|
||||
t.Run("Single global override Helm", func(t *testing.T) {
|
||||
runWithTempTestdata(t, "single-global-helm", func(t *testing.T, path string) {
|
||||
t.Helper()
|
||||
service := newService(t, ".")
|
||||
manifests, err := service.GenerateManifest(context.Background(), &apiclient.ManifestRequest{
|
||||
Repo: &argoappv1.Repository{},
|
||||
|
|
@ -2010,6 +2024,7 @@ func TestGenerateManifestsWithAppParameterFile(t *testing.T) {
|
|||
t.Run("Application specific override", func(t *testing.T) {
|
||||
service := newService(t, ".")
|
||||
runWithTempTestdata(t, "single-app-only", func(t *testing.T, path string) {
|
||||
t.Helper()
|
||||
manifests, err := service.GenerateManifest(context.Background(), &apiclient.ManifestRequest{
|
||||
Repo: &argoappv1.Repository{},
|
||||
ApplicationSource: &argoappv1.ApplicationSource{
|
||||
|
|
@ -2040,6 +2055,7 @@ func TestGenerateManifestsWithAppParameterFile(t *testing.T) {
|
|||
t.Run("Multi-source with source as ref only does not generate manifests", func(t *testing.T) {
|
||||
service := newService(t, ".")
|
||||
runWithTempTestdata(t, "single-app-only", func(t *testing.T, path string) {
|
||||
t.Helper()
|
||||
manifests, err := service.GenerateManifest(context.Background(), &apiclient.ManifestRequest{
|
||||
Repo: &argoappv1.Repository{},
|
||||
ApplicationSource: &argoappv1.ApplicationSource{
|
||||
|
|
@ -2061,6 +2077,7 @@ func TestGenerateManifestsWithAppParameterFile(t *testing.T) {
|
|||
t.Run("Application specific override for other app", func(t *testing.T) {
|
||||
service := newService(t, ".")
|
||||
runWithTempTestdata(t, "single-app-only", func(t *testing.T, path string) {
|
||||
t.Helper()
|
||||
manifests, err := service.GenerateManifest(context.Background(), &apiclient.ManifestRequest{
|
||||
Repo: &argoappv1.Repository{},
|
||||
ApplicationSource: &argoappv1.ApplicationSource{
|
||||
|
|
@ -2091,6 +2108,7 @@ func TestGenerateManifestsWithAppParameterFile(t *testing.T) {
|
|||
t.Run("Override info does not appear in cache key", func(t *testing.T) {
|
||||
service := newService(t, ".")
|
||||
runWithTempTestdata(t, "single-global", func(t *testing.T, path string) {
|
||||
t.Helper()
|
||||
source := &argoappv1.ApplicationSource{
|
||||
Path: path,
|
||||
}
|
||||
|
|
@ -2371,6 +2389,7 @@ func TestFindManifests_Exclude_NothingMatches(t *testing.T) {
|
|||
}
|
||||
|
||||
func tempDir(t *testing.T) string {
|
||||
t.Helper()
|
||||
dir, err := os.MkdirTemp(".", "")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
|
|
@ -2385,6 +2404,7 @@ func tempDir(t *testing.T) string {
|
|||
}
|
||||
|
||||
func walkFor(t *testing.T, root string, testPath string, run func(info fs.FileInfo)) {
|
||||
t.Helper()
|
||||
hitExpectedPath := false
|
||||
err := filepath.Walk(root, func(path string, info fs.FileInfo, err error) error {
|
||||
if path == testPath {
|
||||
|
|
@ -2932,6 +2952,7 @@ func TestDirectoryPermissionInitializer(t *testing.T) {
|
|||
}
|
||||
|
||||
func addHelmToGitRepo(t *testing.T, options newGitRepoOptions) {
|
||||
t.Helper()
|
||||
err := os.WriteFile(filepath.Join(options.path, "Chart.yaml"), []byte("name: test\nversion: v1.0.0"), 0o777)
|
||||
require.NoError(t, err)
|
||||
for valuesFileName, values := range options.helmChartOptions.valuesFiles {
|
||||
|
|
@ -2950,6 +2971,7 @@ func addHelmToGitRepo(t *testing.T, options newGitRepoOptions) {
|
|||
}
|
||||
|
||||
func initGitRepo(t *testing.T, options newGitRepoOptions) (revision string) {
|
||||
t.Helper()
|
||||
if options.createPath {
|
||||
require.NoError(t, os.Mkdir(options.path, 0o755))
|
||||
}
|
||||
|
|
@ -3070,6 +3092,7 @@ func TestCheckoutRevisionNotPresentCallFetch(t *testing.T) {
|
|||
// runGit runs a git command in the given working directory. If the command succeeds, it returns the combined standard
|
||||
// and error output. If it fails, it stops the test with a failure message.
|
||||
func runGit(t *testing.T, workDir string, args ...string) string {
|
||||
t.Helper()
|
||||
cmd := exec.Command("git", args...)
|
||||
cmd.Dir = workDir
|
||||
out, err := cmd.CombinedOutput()
|
||||
|
|
|
|||
|
|
@ -131,14 +131,16 @@ func fakeRepoServerClient(isHelm bool) *mocks.RepoServerServiceClient {
|
|||
|
||||
// return an ApplicationServiceServer which returns fake data
|
||||
func newTestAppServer(t *testing.T, objects ...runtime.Object) *Server {
|
||||
t.Helper()
|
||||
f := func(enf *rbac.Enforcer) {
|
||||
_ = enf.SetBuiltinPolicy(assets.BuiltinPolicyCSV)
|
||||
enf.SetDefaultRole("role:admin")
|
||||
}
|
||||
return newTestAppServerWithEnforcerConfigure(f, t, map[string]string{}, objects...)
|
||||
return newTestAppServerWithEnforcerConfigure(t, f, map[string]string{}, objects...)
|
||||
}
|
||||
|
||||
func newTestAppServerWithEnforcerConfigure(f func(*rbac.Enforcer), t *testing.T, additionalConfig map[string]string, objects ...runtime.Object) *Server {
|
||||
func newTestAppServerWithEnforcerConfigure(t *testing.T, f func(*rbac.Enforcer), additionalConfig map[string]string, objects ...runtime.Object) *Server {
|
||||
t.Helper()
|
||||
kubeclientset := fake.NewSimpleClientset(&v1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: testNamespace,
|
||||
|
|
@ -315,14 +317,16 @@ func newTestAppServerWithEnforcerConfigure(f func(*rbac.Enforcer), t *testing.T,
|
|||
|
||||
// return an ApplicationServiceServer which returns fake data
|
||||
func newTestAppServerWithBenchmark(b *testing.B, objects ...runtime.Object) *Server {
|
||||
b.Helper()
|
||||
f := func(enf *rbac.Enforcer) {
|
||||
_ = enf.SetBuiltinPolicy(assets.BuiltinPolicyCSV)
|
||||
enf.SetDefaultRole("role:admin")
|
||||
}
|
||||
return newTestAppServerWithEnforcerConfigureWithBenchmark(f, b, objects...)
|
||||
return newTestAppServerWithEnforcerConfigureWithBenchmark(b, f, objects...)
|
||||
}
|
||||
|
||||
func newTestAppServerWithEnforcerConfigureWithBenchmark(f func(*rbac.Enforcer), b *testing.B, objects ...runtime.Object) *Server {
|
||||
func newTestAppServerWithEnforcerConfigureWithBenchmark(b *testing.B, f func(*rbac.Enforcer), objects ...runtime.Object) *Server {
|
||||
b.Helper()
|
||||
kubeclientset := fake.NewSimpleClientset(&v1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: testNamespace,
|
||||
|
|
@ -792,7 +796,7 @@ func TestNoAppEnumeration(t *testing.T) {
|
|||
}
|
||||
})
|
||||
testDeployment := kube.MustToUnstructured(&deployment)
|
||||
appServer := newTestAppServerWithEnforcerConfigure(f, t, map[string]string{}, testApp, testHelmApp, testAppMulti, testDeployment)
|
||||
appServer := newTestAppServerWithEnforcerConfigure(t, f, map[string]string{}, testApp, testHelmApp, testAppMulti, testDeployment)
|
||||
|
||||
noRoleCtx := context.Background()
|
||||
// nolint:staticcheck
|
||||
|
|
@ -1096,6 +1100,7 @@ func TestNoAppEnumeration(t *testing.T) {
|
|||
|
||||
// setSyncRunningOperationState simulates starting a sync operation on the given app.
|
||||
func setSyncRunningOperationState(t *testing.T, appServer *Server) {
|
||||
t.Helper()
|
||||
appIf := appServer.appclientset.ArgoprojV1alpha1().Applications("default")
|
||||
app, err := appIf.Get(context.Background(), "test", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
|
|
@ -1107,6 +1112,7 @@ func setSyncRunningOperationState(t *testing.T, appServer *Server) {
|
|||
|
||||
// unsetSyncRunningOperationState simulates finishing a sync operation on the given app.
|
||||
func unsetSyncRunningOperationState(t *testing.T, appServer *Server) {
|
||||
t.Helper()
|
||||
appIf := appServer.appclientset.ArgoprojV1alpha1().Applications("default")
|
||||
app, err := appIf.Get(context.Background(), "test", metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
|
|
@ -1153,6 +1159,7 @@ func TestListAppsInDefaultNSWithLabels(t *testing.T) {
|
|||
}
|
||||
|
||||
func testListAppsWithLabels(t *testing.T, appQuery application.ApplicationQuery, appServer *Server) {
|
||||
t.Helper()
|
||||
validTests := []struct {
|
||||
testName string
|
||||
label string
|
||||
|
|
@ -1334,7 +1341,7 @@ g, group-49, role:test3
|
|||
`
|
||||
_ = enf.SetUserPolicy(policy)
|
||||
}
|
||||
appServer := newTestAppServerWithEnforcerConfigure(f, t, map[string]string{}, objects...)
|
||||
appServer := newTestAppServerWithEnforcerConfigure(t, f, map[string]string{}, objects...)
|
||||
|
||||
res, err := appServer.List(ctx, &application.ApplicationQuery{})
|
||||
|
||||
|
|
@ -2228,6 +2235,7 @@ func TestMaxPodLogsRender(t *testing.T) {
|
|||
|
||||
// createAppServerWithMaxLodLogs creates a new app server with given number of pods and resources
|
||||
func createAppServerWithMaxLodLogs(t *testing.T, podNumber int, maxPodLogsToRender ...int64) (*Server, context.Context) {
|
||||
t.Helper()
|
||||
runtimeObjects := make([]runtime.Object, podNumber+1)
|
||||
resources := make([]appsv1.ResourceStatus, podNumber)
|
||||
|
||||
|
|
@ -2269,7 +2277,7 @@ func createAppServerWithMaxLodLogs(t *testing.T, podNumber int, maxPodLogsToRend
|
|||
enf.SetDefaultRole("role:admin")
|
||||
}
|
||||
formatInt := strconv.FormatInt(maxPodLogsToRender[0], 10)
|
||||
appServer := newTestAppServerWithEnforcerConfigure(f, t, map[string]string{"server.maxPodLogsToRender": formatInt}, runtimeObjects...)
|
||||
appServer := newTestAppServerWithEnforcerConfigure(t, f, map[string]string{"server.maxPodLogsToRender": formatInt}, runtimeObjects...)
|
||||
return appServer, adminCtx
|
||||
} else {
|
||||
appServer := newTestAppServer(t, runtimeObjects...)
|
||||
|
|
@ -2279,6 +2287,7 @@ func createAppServerWithMaxLodLogs(t *testing.T, podNumber int, maxPodLogsToRend
|
|||
|
||||
// refreshAnnotationRemover runs an infinite loop until it detects and removes refresh annotation or given context is done
|
||||
func refreshAnnotationRemover(t *testing.T, ctx context.Context, patched *int32, appServer *Server, appName string, ch chan string) {
|
||||
t.Helper()
|
||||
for ctx.Err() == nil {
|
||||
aName, appNs := argo.ParseFromQualifiedName(appName, appServer.ns)
|
||||
a, err := appServer.appLister.Applications(appNs).Get(aName)
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ func TestReconnect(t *testing.T) {
|
|||
}
|
||||
|
||||
func testServerConnection(t *testing.T, testFunc func(w http.ResponseWriter, r *http.Request), expectPermissionDenied bool) {
|
||||
t.Helper()
|
||||
s := httptest.NewServer(http.HandlerFunc(testFunc))
|
||||
defer s.Close()
|
||||
|
||||
|
|
|
|||
|
|
@ -190,6 +190,7 @@ func newTestAppSet(opts ...func(appset *appsv1.ApplicationSet)) *appsv1.Applicat
|
|||
}
|
||||
|
||||
func testListAppsetsWithLabels(t *testing.T, appsetQuery applicationset.ApplicationSetListQuery, appServer *Server) {
|
||||
t.Helper()
|
||||
validTests := []struct {
|
||||
testName string
|
||||
label string
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ type FakeArgoCDServer struct {
|
|||
}
|
||||
|
||||
func fakeServer(t *testing.T) (*FakeArgoCDServer, func()) {
|
||||
t.Helper()
|
||||
cm := test.NewFakeConfigMap()
|
||||
secret := test.NewFakeSecret()
|
||||
kubeclientset := fake.NewSimpleClientset(cm, secret)
|
||||
|
|
@ -477,6 +478,7 @@ func TestAuthenticate(t *testing.T) {
|
|||
}
|
||||
|
||||
func dexMockHandler(t *testing.T, url string) func(http.ResponseWriter, *http.Request) {
|
||||
t.Helper()
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
switch r.RequestURI {
|
||||
|
|
@ -542,6 +544,7 @@ func dexMockHandler(t *testing.T, url string) func(http.ResponseWriter, *http.Re
|
|||
}
|
||||
|
||||
func getTestServer(t *testing.T, anonymousEnabled bool, withFakeSSO bool, useDexForSSO bool, additionalOIDCConfig settings_util.OIDCConfig) (argocd *ArgoCDServer, oidcURL string) {
|
||||
t.Helper()
|
||||
cm := test.NewFakeConfigMap()
|
||||
if anonymousEnabled {
|
||||
cm.Data["users.anonymous.enabled"] = "true"
|
||||
|
|
@ -1532,6 +1535,7 @@ func TestReplaceBaseHRef(t *testing.T) {
|
|||
|
||||
func Test_enforceContentTypes(t *testing.T) {
|
||||
getBaseHandler := func(t *testing.T, allow bool) http.Handler {
|
||||
t.Helper()
|
||||
return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
|
||||
assert.True(t, allow, "http handler was hit when it should have been blocked by content type enforcement")
|
||||
writer.WriteHeader(http.StatusOK)
|
||||
|
|
|
|||
|
|
@ -876,6 +876,7 @@ func TestNamespacedConfigMap(t *testing.T) {
|
|||
}
|
||||
|
||||
func testNSEdgeCasesApplicationResources(t *testing.T, appPath string, statusCode health.HealthStatusCode, message ...string) {
|
||||
t.Helper()
|
||||
ctx := Given(t)
|
||||
expect := ctx.
|
||||
Path(appPath).
|
||||
|
|
@ -1085,6 +1086,7 @@ func TestNamespacedSyncAsync(t *testing.T) {
|
|||
|
||||
// assertResourceActions verifies if view/modify resource actions are successful/failing for given application
|
||||
func assertNSResourceActions(t *testing.T, appName string, successful bool) {
|
||||
t.Helper()
|
||||
assertError := func(err error, message string) {
|
||||
if successful {
|
||||
require.NoError(t, err)
|
||||
|
|
|
|||
|
|
@ -757,6 +757,7 @@ func TestManipulateApplicationResources(t *testing.T) {
|
|||
}
|
||||
|
||||
func assetSecretDataHidden(t *testing.T, manifest string) {
|
||||
t.Helper()
|
||||
secret, err := UnmarshalToUnstructured(manifest)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
@ -1020,6 +1021,7 @@ func TestConfigMap(t *testing.T) {
|
|||
}
|
||||
|
||||
func testEdgeCasesApplicationResources(t *testing.T, appPath string, statusCode health.HealthStatusCode, message ...string) {
|
||||
t.Helper()
|
||||
expect := Given(t).
|
||||
Path(appPath).
|
||||
When().
|
||||
|
|
@ -1442,6 +1444,7 @@ func TestSyncAsync(t *testing.T) {
|
|||
|
||||
// assertResourceActions verifies if view/modify resource actions are successful/failing for given application
|
||||
func assertResourceActions(t *testing.T, appName string, successful bool) {
|
||||
t.Helper()
|
||||
assertError := func(err error, message string) {
|
||||
if successful {
|
||||
require.NoError(t, err)
|
||||
|
|
|
|||
|
|
@ -2107,6 +2107,7 @@ func TestSimpleGitFilesPreserveResourcesOnDeletionGoTemplate(t *testing.T) {
|
|||
}
|
||||
|
||||
func githubSCMMockHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
|
||||
t.Helper()
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
switch r.RequestURI {
|
||||
|
|
@ -2296,6 +2297,7 @@ func githubSCMMockHandler(t *testing.T) func(http.ResponseWriter, *http.Request)
|
|||
}
|
||||
|
||||
func testServerWithPort(t *testing.T, port int, handler http.Handler) *httptest.Server {
|
||||
t.Helper()
|
||||
// Use mocked API response to avoid rate-limiting.
|
||||
l, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", port))
|
||||
if err != nil {
|
||||
|
|
@ -2673,6 +2675,7 @@ func TestCustomApplicationFinalizersGoTemplate(t *testing.T) {
|
|||
}
|
||||
|
||||
func githubPullMockHandler(t *testing.T) func(http.ResponseWriter, *http.Request) {
|
||||
t.Helper()
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
switch r.RequestURI {
|
||||
|
|
|
|||
|
|
@ -168,6 +168,7 @@ func TestCustomToolSyncAndDiffLocal(t *testing.T) {
|
|||
}
|
||||
|
||||
func startCMPServer(t *testing.T, configFile string) {
|
||||
t.Helper()
|
||||
pluginSockFilePath := TmpDir + PluginSockFilePath
|
||||
t.Setenv("ARGOCD_BINARY_NAME", "argocd-cmp-server")
|
||||
// ARGOCD_PLUGINSOCKFILEPATH should be set as the same value as repo server env var
|
||||
|
|
|
|||
|
|
@ -259,6 +259,7 @@ func buildArgoCDClusterSecret(secretName, secretNamespace, clusterName, clusterS
|
|||
// - username = name of Namespace the simulated user is able to deploy to
|
||||
// - clusterScopedSecrets = whether the Service Account is namespace-scoped or cluster-scoped.
|
||||
func createNamespaceScopedUser(t *testing.T, username string, clusterScopedSecrets bool) {
|
||||
t.Helper()
|
||||
// Create a new Namespace for our simulated user
|
||||
ns := corev1.Namespace{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ type Context struct {
|
|||
}
|
||||
|
||||
func Given(t *testing.T) *Context {
|
||||
t.Helper()
|
||||
fixture.EnsureCleanState(t)
|
||||
// ARGOCE_E2E_DEFAULT_TIMEOUT can be used to override the default timeout
|
||||
// for any context.
|
||||
|
|
|
|||
|
|
@ -16,11 +16,13 @@ type Context struct {
|
|||
}
|
||||
|
||||
func Given(t *testing.T) *Context {
|
||||
t.Helper()
|
||||
fixture.EnsureCleanState(t)
|
||||
return GivenWithSameState(t)
|
||||
}
|
||||
|
||||
func GivenWithSameState(t *testing.T) *Context {
|
||||
t.Helper()
|
||||
// ARGOCE_E2E_DEFAULT_TIMEOUT can be used to override the default timeout
|
||||
// for any context.
|
||||
timeout := env.ParseNumFromEnv("ARGOCD_E2E_DEFAULT_TIMEOUT", 20, 0, 180)
|
||||
|
|
|
|||
|
|
@ -53,17 +53,20 @@ type ContextArgs struct {
|
|||
}
|
||||
|
||||
func Given(t *testing.T, opts ...fixture.TestOption) *Context {
|
||||
t.Helper()
|
||||
fixture.EnsureCleanState(t, opts...)
|
||||
return GivenWithSameState(t)
|
||||
}
|
||||
|
||||
func GivenWithNamespace(t *testing.T, namespace string) *Context {
|
||||
t.Helper()
|
||||
ctx := Given(t)
|
||||
ctx.appNamespace = namespace
|
||||
return ctx
|
||||
}
|
||||
|
||||
func GivenWithSameState(t *testing.T) *Context {
|
||||
t.Helper()
|
||||
// ARGOCE_E2E_DEFAULT_TIMEOUT can be used to override the default timeout
|
||||
// for any context.
|
||||
timeout := env.ParseNumFromEnv("ARGOCD_E2E_DEFAULT_TIMEOUT", 20, 0, 180)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ type Context struct {
|
|||
}
|
||||
|
||||
func Given(t *testing.T) *Context {
|
||||
t.Helper()
|
||||
utils.EnsureCleanState(t)
|
||||
return &Context{t: t}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,6 +106,7 @@ func GetE2EFixtureK8sClient() *E2EFixtureK8sClient {
|
|||
|
||||
// EnsureCleanSlate ensures that the Kubernetes resources on the cluster are in a 'clean' state, before a test is run.
|
||||
func EnsureCleanState(t *testing.T) {
|
||||
t.Helper()
|
||||
start := time.Now()
|
||||
|
||||
fixtureClient := GetE2EFixtureK8sClient()
|
||||
|
|
@ -366,6 +367,7 @@ func ToUnstructured(obj interface{}) (*unstructured.Unstructured, error) {
|
|||
//
|
||||
// Note: This only applies to tests that use the GitHub API (different from GitHub's Git service)
|
||||
func IsGitHubAPISkippedTest(t *testing.T) bool {
|
||||
t.Helper()
|
||||
if strings.TrimSpace(os.Getenv("GITHUB_TOKEN")) == "" {
|
||||
t.Skip("Skipping this test, as the GITHUB_TOKEN is not set. Please ensure this test passes locally, with your own GITHUB_TOKEN.")
|
||||
return true
|
||||
|
|
|
|||
|
|
@ -22,11 +22,13 @@ type Context struct {
|
|||
}
|
||||
|
||||
func Given(t *testing.T) *Context {
|
||||
t.Helper()
|
||||
fixture.EnsureCleanState(t)
|
||||
return GivenWithSameState(t)
|
||||
}
|
||||
|
||||
func GivenWithSameState(t *testing.T) *Context {
|
||||
t.Helper()
|
||||
// ARGOCE_E2E_DEFAULT_TIMEOUT can be used to override the default timeout
|
||||
// for any context.
|
||||
timeout := env.ParseNumFromEnv("ARGOCD_E2E_DEFAULT_TIMEOUT", 10, 0, 180)
|
||||
|
|
|
|||
|
|
@ -574,6 +574,7 @@ func WithTestData(testdata string) TestOption {
|
|||
}
|
||||
|
||||
func EnsureCleanState(t *testing.T, opts ...TestOption) {
|
||||
t.Helper()
|
||||
opt := newTestOption(opts...)
|
||||
// In large scenarios, we can skip tests that already run
|
||||
SkipIfAlreadyRun(t)
|
||||
|
|
@ -984,6 +985,7 @@ func LocalOrRemotePath(base string) string {
|
|||
// Environment variable names follow the ARGOCD_E2E_SKIP_<suffix> pattern,
|
||||
// and must be set to the string value 'true' in order to skip a test.
|
||||
func SkipOnEnv(t *testing.T, suffixes ...string) {
|
||||
t.Helper()
|
||||
for _, suffix := range suffixes {
|
||||
e := os.Getenv("ARGOCD_E2E_SKIP_" + suffix)
|
||||
if e == "true" {
|
||||
|
|
@ -995,6 +997,7 @@ func SkipOnEnv(t *testing.T, suffixes ...string) {
|
|||
// SkipIfAlreadyRun skips a test if it has been already run by a previous
|
||||
// test cycle and was recorded.
|
||||
func SkipIfAlreadyRun(t *testing.T) {
|
||||
t.Helper()
|
||||
if _, ok := testsRun[t.Name()]; ok {
|
||||
t.Skip()
|
||||
}
|
||||
|
|
@ -1003,6 +1006,7 @@ func SkipIfAlreadyRun(t *testing.T) {
|
|||
// RecordTestRun records a test that has been run successfully to a text file,
|
||||
// so that it can be automatically skipped if requested.
|
||||
func RecordTestRun(t *testing.T) {
|
||||
t.Helper()
|
||||
if t.Skipped() || t.Failed() {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ type Context struct {
|
|||
}
|
||||
|
||||
func Given(t *testing.T) *Context {
|
||||
t.Helper()
|
||||
fixture.EnsureCleanState(t)
|
||||
return &Context{t: t}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,11 +20,13 @@ type Context struct {
|
|||
}
|
||||
|
||||
func Given(t *testing.T) *Context {
|
||||
t.Helper()
|
||||
fixture.EnsureCleanState(t)
|
||||
return GivenWithSameState(t)
|
||||
}
|
||||
|
||||
func GivenWithSameState(t *testing.T) *Context {
|
||||
t.Helper()
|
||||
// ARGOCE_E2E_DEFAULT_TIMEOUT can be used to override the default timeout
|
||||
// for any context.
|
||||
timeout := env.ParseNumFromEnv("ARGOCD_E2E_DEFAULT_TIMEOUT", 10, 0, 180)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ type Context struct {
|
|||
}
|
||||
|
||||
func Given(t *testing.T, sameState bool) *Context {
|
||||
t.Helper()
|
||||
if !sameState {
|
||||
fixture.EnsureCleanState(t)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -501,6 +501,7 @@ func TestHelmWithDependenciesLegacyRepo(t *testing.T) {
|
|||
}
|
||||
|
||||
func testHelmWithDependencies(t *testing.T, chartPath string, legacyRepo bool) {
|
||||
t.Helper()
|
||||
ctx := Given(t).
|
||||
CustomCACertAdded().
|
||||
// these are slow tests
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ func TestPostSyncHookSuccessful(t *testing.T) {
|
|||
|
||||
// make sure we can run a standard sync hook
|
||||
func testHookSuccessful(t *testing.T, hookType HookType) {
|
||||
t.Helper()
|
||||
Given(t).
|
||||
Path("hook").
|
||||
When().
|
||||
|
|
|
|||
|
|
@ -435,6 +435,7 @@ func TestMergeTerminalMergeGeneratorSelector(t *testing.T) {
|
|||
}
|
||||
|
||||
func toAPIExtensionsJSON(t *testing.T, g interface{}) *apiextensionsv1.JSON {
|
||||
t.Helper()
|
||||
resVal, err := json.Marshal(g)
|
||||
if err != nil {
|
||||
t.Error("unable to unmarshal json", g)
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import (
|
|||
)
|
||||
|
||||
func assertProjHasEvent(t *testing.T, a *v1alpha1.AppProject, message string, reason string) {
|
||||
t.Helper()
|
||||
list, err := fixture.KubeClientset.CoreV1().Events(fixture.TestNamespace()).List(context.Background(), metav1.ListOptions{
|
||||
FieldSelector: fields.SelectorFromSet(map[string]string{
|
||||
"involvedObject.name": a.Name,
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@ func TestSelectiveSyncWithNamespace(t *testing.T) {
|
|||
}
|
||||
|
||||
func getNewNamespace(t *testing.T) string {
|
||||
t.Helper()
|
||||
randStr, err := rand.String(5)
|
||||
require.NoError(t, err)
|
||||
postFix := "-" + strings.ToLower(randStr)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
// invoke this method to indicate test that should be skipped on CI, i.e. you only need it for manual testing/locally
|
||||
func LocalOnly(t *testing.T) {
|
||||
t.Helper()
|
||||
if os.Getenv("CI") == "true" {
|
||||
t.Skipf("test %s skipped when envvar CI=true", t.Name())
|
||||
}
|
||||
|
|
@ -15,6 +16,7 @@ func LocalOnly(t *testing.T) {
|
|||
// invoke this method to indicate test should only run on CI, i.e. edge-case test on code that rarely changes and needs
|
||||
// extra software install
|
||||
func CIOnly(t *testing.T) {
|
||||
t.Helper()
|
||||
if os.Getenv("CI") != "true" {
|
||||
t.Skipf("test %s skipped when envvar CI!=true", t.Name())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,5 +6,6 @@ import (
|
|||
|
||||
// invoke this method to indicate it is a flaky test that should be skipped on CI
|
||||
func Flaky(t *testing.T) {
|
||||
t.Helper()
|
||||
LocalOnly(t)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -172,6 +172,7 @@ func TestParseAppInstanceValueCorrectFormat(t *testing.T) {
|
|||
}
|
||||
|
||||
func sampleResource(t *testing.T) *unstructured.Unstructured {
|
||||
t.Helper()
|
||||
yamlBytes, err := os.ReadFile("testdata/svc.yaml")
|
||||
require.NoError(t, err)
|
||||
var obj *unstructured.Unstructured
|
||||
|
|
|
|||
|
|
@ -94,5 +94,6 @@ func (m *streamMock) sendFile(ctx context.Context, t *testing.T, basedir string,
|
|||
// getTestDataDir will return the full path of the testdata dir
|
||||
// under the running test folder.
|
||||
func getTestDataDir(t *testing.T) string {
|
||||
t.Helper()
|
||||
return filepath.Join(test.GetTestDir(t), "testdata")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,11 +7,13 @@ import (
|
|||
)
|
||||
|
||||
func loadOpts(t *testing.T, opts string) {
|
||||
t.Helper()
|
||||
t.Setenv("ARGOCD_OPTS", opts)
|
||||
assert.NoError(t, loadFlags())
|
||||
}
|
||||
|
||||
func loadInvalidOpts(t *testing.T, opts string) {
|
||||
t.Helper()
|
||||
t.Setenv("ARGOCD_OPTS", opts)
|
||||
assert.Error(t, loadFlags())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -255,6 +255,7 @@ func TestRejectCreationForInClusterWhenDisabled(t *testing.T) {
|
|||
}
|
||||
|
||||
func runWatchTest(t *testing.T, db ArgoDB, actions []func(old *v1alpha1.Cluster, new *v1alpha1.Cluster)) {
|
||||
t.Helper()
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ var syncTestSources = map[string]string{
|
|||
|
||||
// Helper function to create temporary GNUPGHOME
|
||||
func initTempDir(t *testing.T) string {
|
||||
t.Helper()
|
||||
// Intentionally avoid using t.TempDir. That function creates really long paths, which can exceed the socket file
|
||||
// path length on some OSes. The GPG tests rely on sockets.
|
||||
p, err := os.MkdirTemp(os.TempDir(), "")
|
||||
|
|
|
|||
|
|
@ -251,11 +251,13 @@ func read(tgz *os.File) (map[string]string, error) {
|
|||
// getTestAppDir will return the full path of the app dir under
|
||||
// the 'testdata' folder.
|
||||
func getTestAppDir(t *testing.T) string {
|
||||
t.Helper()
|
||||
return filepath.Join(getTestDataDir(t), "app")
|
||||
}
|
||||
|
||||
// getTestDataDir will return the full path of the testdata dir
|
||||
// under the running test folder.
|
||||
func getTestDataDir(t *testing.T) string {
|
||||
t.Helper()
|
||||
return filepath.Join(test.GetTestDir(t), "testdata")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ const (
|
|||
)
|
||||
|
||||
func testDataDir(tb testing.TB, testData string) (string, error) {
|
||||
tb.Helper()
|
||||
res := tb.TempDir()
|
||||
_, err := exec.RunCommand("cp", exec.CmdOpts{}, "-r", "./testdata/"+testData, filepath.Join(res, "testdata"))
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -209,6 +209,7 @@ func TestLuaResourceActionsScript(t *testing.T) {
|
|||
// Handling backward compatibility.
|
||||
// The old-style actions return a single object in the expected output from testdata, so will wrap them in a list
|
||||
func getExpectedObjectList(t *testing.T, path string) *unstructured.UnstructuredList {
|
||||
t.Helper()
|
||||
yamlBytes, err := os.ReadFile(path)
|
||||
errors.CheckError(err)
|
||||
unstructuredList := &unstructured.UnstructuredList{}
|
||||
|
|
|
|||
|
|
@ -122,5 +122,6 @@ func TestManifestStream(t *testing.T) {
|
|||
}
|
||||
|
||||
func getTestDataDir(t *testing.T) string {
|
||||
t.Helper()
|
||||
return filepath.Join(test.GetTestDir(t), "testdata")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
)
|
||||
|
||||
func testPasswordHasher(t *testing.T, h PasswordHasher) {
|
||||
t.Helper()
|
||||
// Use the default work factor
|
||||
const (
|
||||
defaultPassword = "Hello, world!"
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import (
|
|||
|
||||
func Test_UnverifiedHasAudClaim(t *testing.T) {
|
||||
tokenForAud := func(t *testing.T, aud jwt.ClaimStrings) string {
|
||||
t.Helper()
|
||||
claims := jwt.RegisteredClaims{Audience: aud, Subject: "admin", ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Hour * 24))}
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodRS512, claims)
|
||||
key, err := jwt.ParseRSAPrivateKeyFromPEM(utiltest.PrivateKey)
|
||||
|
|
|
|||
|
|
@ -108,6 +108,7 @@ B3XwyYtAFsaO5r7oEc1Bv6oNSbE+FNJzRdjkWEIhdLVKlepil/w=
|
|||
-----END RSA PRIVATE KEY-----`)
|
||||
|
||||
func dexMockHandler(t *testing.T, url string) func(http.ResponseWriter, *http.Request) {
|
||||
t.Helper()
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
switch r.RequestURI {
|
||||
|
|
@ -137,6 +138,7 @@ func dexMockHandler(t *testing.T, url string) func(http.ResponseWriter, *http.Re
|
|||
}
|
||||
|
||||
func GetDexTestServer(t *testing.T) *httptest.Server {
|
||||
t.Helper()
|
||||
ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// Start with a placeholder. We need the server URL before setting up the real handler.
|
||||
}))
|
||||
|
|
@ -147,6 +149,7 @@ func GetDexTestServer(t *testing.T) *httptest.Server {
|
|||
}
|
||||
|
||||
func oidcMockHandler(t *testing.T, url string) func(http.ResponseWriter, *http.Request) {
|
||||
t.Helper()
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
switch r.RequestURI {
|
||||
|
|
@ -200,6 +203,7 @@ func oidcMockHandler(t *testing.T, url string) func(http.ResponseWriter, *http.R
|
|||
}
|
||||
|
||||
func GetOIDCTestServer(t *testing.T) *httptest.Server {
|
||||
t.Helper()
|
||||
ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// Start with a placeholder. We need the server URL before setting up the real handler.
|
||||
}))
|
||||
|
|
|
|||
Loading…
Reference in a new issue