From 8e8177fdca52a9d8490d6b4bd46ca870ff7179c4 Mon Sep 17 00:00:00 2001 From: Alan Parra Date: Fri, 18 Oct 2024 15:22:12 -0300 Subject: [PATCH 1/2] Fix TestAutoEnroll_disabledByEnv flakiness --- lib/devicetrust/enroll/auto_enroll_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/devicetrust/enroll/auto_enroll_test.go b/lib/devicetrust/enroll/auto_enroll_test.go index d12842506dd05..a8d6b453538f6 100644 --- a/lib/devicetrust/enroll/auto_enroll_test.go +++ b/lib/devicetrust/enroll/auto_enroll_test.go @@ -70,7 +70,11 @@ func TestAutoEnrollCeremony_Run(t *testing.T) { } func TestAutoEnroll_disabledByEnv(t *testing.T) { - os.Setenv("TELEPORT_DEVICE_AUTO_ENROLL_DISABLED", "1") + // Don't t.Parallel, test changes env variables. + + const key = "TELEPORT_DEVICE_AUTO_ENROLL_DISABLED" + os.Setenv(key, "1") + t.Cleanup(func() { os.Unsetenv(key) }) _, err := enroll.AutoEnroll(context.Background(), nil /* devicesClient */) assert.ErrorIs(t, err, enroll.ErrAutoEnrollDisabled, "AutoEnroll() error mismatch") From fe063911403ef78e3cbbc58ff1b47e85ae3c8fdd Mon Sep 17 00:00:00 2001 From: Alan Parra Date: Fri, 18 Oct 2024 15:41:50 -0300 Subject: [PATCH 2/2] Use t.Setenv Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com> --- lib/devicetrust/enroll/auto_enroll_test.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/devicetrust/enroll/auto_enroll_test.go b/lib/devicetrust/enroll/auto_enroll_test.go index a8d6b453538f6..77a6678a9949a 100644 --- a/lib/devicetrust/enroll/auto_enroll_test.go +++ b/lib/devicetrust/enroll/auto_enroll_test.go @@ -20,7 +20,6 @@ package enroll_test import ( "context" - "os" "testing" "github.com/stretchr/testify/assert" @@ -70,11 +69,7 @@ func TestAutoEnrollCeremony_Run(t *testing.T) { } func TestAutoEnroll_disabledByEnv(t *testing.T) { - // Don't t.Parallel, test changes env variables. - - const key = "TELEPORT_DEVICE_AUTO_ENROLL_DISABLED" - os.Setenv(key, "1") - t.Cleanup(func() { os.Unsetenv(key) }) + t.Setenv("TELEPORT_DEVICE_AUTO_ENROLL_DISABLED", "1") _, err := enroll.AutoEnroll(context.Background(), nil /* devicesClient */) assert.ErrorIs(t, err, enroll.ErrAutoEnrollDisabled, "AutoEnroll() error mismatch")