Skip to content

Commit

Permalink
chore: use testify instead of testing.Fatal
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 committed Dec 19, 2024
1 parent d84ac3a commit 182fbb6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 28 deletions.
5 changes: 2 additions & 3 deletions common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ func TestSetOptionalRedisPasswordFromKubeConfig(t *testing.T) {
redisOptions = &redis.Options{}
)
if tc.secret != nil {
if _, err := kubeClient.CoreV1().Secrets(tc.namespace).Create(ctx, tc.secret, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to create secret: %v", err)
}
_, err := kubeClient.CoreV1().Secrets(tc.namespace).Create(ctx, tc.secret, metav1.CreateOptions{})
require.NoErrorf(t, err, "Failed to create secret")
}
err := SetOptionalRedisPasswordFromKubeConfig(ctx, kubeClient, tc.namespace, redisOptions)
if tc.expectedErr != "" {
Expand Down
5 changes: 2 additions & 3 deletions controller/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
v1 "k8s.io/api/core/v1"
apierr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -726,9 +727,7 @@ func TestShouldHashManifest(t *testing.T) {
test.un.SetAnnotations(test.annotations)
}
got := shouldHashManifest(test.appName, test.gvk, test.un)
if test.want != got {
t.Fatalf("test=%v want %v got %v", test.name, test.want, got)
}
require.Equalf(t, test.want, got, "test=%v", test.name)
})
}
}
4 changes: 1 addition & 3 deletions controller/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1564,9 +1564,7 @@ func TestUseDiffCache(t *testing.T) {
}
if a != nil {
err := mergo.Merge(app, a, mergo.WithOverride, mergo.WithOverwriteWithEmptyValue)
if err != nil {
t.Fatalf("error merging app: %s", err)
}
require.NoErrorf(t, err, "error merging app")
}
if app.Spec.Destination.Name != "" && app.Spec.Destination.Server != "" {
// Simulate the controller's process for populating both of these fields.
Expand Down
8 changes: 2 additions & 6 deletions notification_controller/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ func TestGetAppProj_invalidProjectNestedString(t *testing.T) {
func TestInit(t *testing.T) {
scheme := runtime.NewScheme()
err := v1alpha1.SchemeBuilder.AddToScheme(scheme)
if err != nil {
t.Fatalf("Error registering the resource: %v", err)
}
require.NoErrorf(t, err, "Error registering the resource")
dynamicClient := fake.NewSimpleDynamicClient(scheme)
k8sClient := k8sfake.NewSimpleClientset()
appLabelSelector := "app=test"
Expand Down Expand Up @@ -141,9 +139,7 @@ func TestInit(t *testing.T) {
func TestInitTimeout(t *testing.T) {
scheme := runtime.NewScheme()
err := v1alpha1.SchemeBuilder.AddToScheme(scheme)
if err != nil {
t.Fatalf("Error registering the resource: %v", err)
}
require.NoErrorf(t, err, "Error registering the resource")
dynamicClient := fake.NewSimpleDynamicClient(scheme)
k8sClient := k8sfake.NewSimpleClientset()
appLabelSelector := "app=test"
Expand Down
21 changes: 8 additions & 13 deletions util/oidc/oidc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net/http/httptest"
"net/url"
"os"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -137,9 +136,8 @@ requestedScopes: ["oidc"]`, oidcTestServer.URL),

app.HandleLogin(w, req)

if !strings.Contains(w.Body.String(), "certificate signed by unknown authority") && !strings.Contains(w.Body.String(), "certificate is not trusted") {
t.Fatal("did not receive expected certificate verification failure error")
}
require.Containsf(t, w.Body.String(), "certificate signed by unknown authority", "did not receive expected certificate verification failure error")
require.Containsf(t, w.Body.String(), "certificate is not trusted", "did not receive expected certificate verification failure error")

cdSettings.OIDCTLSInsecureSkipVerify = true

Expand Down Expand Up @@ -177,9 +175,8 @@ requestedScopes: ["oidc"]`, oidcTestServer.URL),

app.HandleLogin(w, req)

if !strings.Contains(w.Body.String(), "certificate signed by unknown authority") && !strings.Contains(w.Body.String(), "certificate is not trusted") {
t.Fatal("did not receive expected certificate verification failure error")
}
require.Containsf(t, w.Body.String(), "certificate signed by unknown authority", "did not receive expected certificate verification failure error")
require.Containsf(t, w.Body.String(), "certificate is not trusted", "did not receive expected certificate verification failure error")

app, err = NewClientApp(cdSettings, dexTestServer.URL, &dex.DexTLSConfig{StrictValidation: false}, "https://argocd.example.com", cache.NewInMemoryCache(24*time.Hour))
require.NoError(t, err)
Expand Down Expand Up @@ -363,9 +360,8 @@ requestedScopes: ["oidc"]`, oidcTestServer.URL),

app.HandleCallback(w, req)

if !strings.Contains(w.Body.String(), "certificate signed by unknown authority") && !strings.Contains(w.Body.String(), "certificate is not trusted") {
t.Fatal("did not receive expected certificate verification failure error")
}
require.Containsf(t, w.Body.String(), "certificate signed by unknown authority", "did not receive expected certificate verification failure error")
require.Containsf(t, w.Body.String(), "certificate is not trusted", "did not receive expected certificate verification failure error")

cdSettings.OIDCTLSInsecureSkipVerify = true

Expand Down Expand Up @@ -403,9 +399,8 @@ requestedScopes: ["oidc"]`, oidcTestServer.URL),

app.HandleCallback(w, req)

if !strings.Contains(w.Body.String(), "certificate signed by unknown authority") && !strings.Contains(w.Body.String(), "certificate is not trusted") {
t.Fatal("did not receive expected certificate verification failure error")
}
require.Containsf(t, w.Body.String(), "certificate signed by unknown authority", "did not receive expected certificate verification failure error")
require.Containsf(t, w.Body.String(), "certificate is not trusted", "did not receive expected certificate verification failure error")

app, err = NewClientApp(cdSettings, dexTestServer.URL, &dex.DexTLSConfig{StrictValidation: false}, "https://argocd.example.com", cache.NewInMemoryCache(24*time.Hour))
require.NoError(t, err)
Expand Down

0 comments on commit 182fbb6

Please sign in to comment.