From 7cd7ff7dd55db47593c1a5e45a4c8b8457851b87 Mon Sep 17 00:00:00 2001 From: Naveen Gogineni Date: Sun, 28 Mar 2021 18:34:30 -0400 Subject: [PATCH] Remove reflect from flag_test --- flag_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/flag_test.go b/flag_test.go index e46270d..d44214c 100644 --- a/flag_test.go +++ b/flag_test.go @@ -123,8 +123,13 @@ func TestFlagsFromEnv(t *testing.T) { for i, test := range flagTests { defer resetEnv(os.Environ()) os.Clearenv() - envVarSlice := reflect.Indirect(reflect.ValueOf(test.flag)).FieldByName("EnvVars").Slice(0, 1) - _ = os.Setenv(envVarSlice.Index(0).String(), test.input) + + f, ok := test.flag.(DocGenerationFlag) + if !ok { + t.Errorf("flag %v needs to implement DocGenerationFlag to retrieve env vars", test.flag) + } + envVarSlice := f.GetEnvVars() + _ = os.Setenv(envVarSlice[0], test.input) a := App{ Flags: []Flag{test.flag},