From 81bbf52ef54ae3e84cb2ca89d81b34a71804d5cb Mon Sep 17 00:00:00 2001 From: Oleg Balunenko Date: Fri, 18 Feb 2022 20:02:50 +0300 Subject: [PATCH] refactor: Move environment variables to constants (#98) --- cmd/aoc-cli/flags.go | 4 +++- internal/puzzles/constants.go | 3 +++ tests/regression_test.go | 12 ++++++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/cmd/aoc-cli/flags.go b/cmd/aoc-cli/flags.go index 52a55133..35ea3f59 100644 --- a/cmd/aoc-cli/flags.go +++ b/cmd/aoc-cli/flags.go @@ -2,6 +2,8 @@ package main import ( "github.com/urfave/cli/v2" + + "github.com/obalunenko/advent-of-code/internal/puzzles" ) const ( @@ -48,7 +50,7 @@ func cmdRunFlags() []cli.Flag { Name: flagSession, Aliases: []string{flagShortSession}, Usage: "AOC auth session to get inputs", - EnvVars: []string{"AOC_SESSION"}, + EnvVars: []string{puzzles.AOCSession}, FilePath: "", Required: true, Hidden: false, diff --git a/internal/puzzles/constants.go b/internal/puzzles/constants.go index 7a983fb6..4505f208 100644 --- a/internal/puzzles/constants.go +++ b/internal/puzzles/constants.go @@ -61,4 +61,7 @@ const ( unsolved = "not solved" undefined = "undefined" inProgress = "in progress" + + // AOCSession env variable name. + AOCSession = "AOC_SESSION" ) diff --git a/tests/regression_test.go b/tests/regression_test.go index de9629bc..573d69e6 100644 --- a/tests/regression_test.go +++ b/tests/regression_test.go @@ -25,15 +25,19 @@ type testcase struct { wantErr bool } +const ( + regressionEnabled = "AOC_REGRESSION_ENABLED" +) + // Regression tests for all puzzles. Check that answers still correct. func TestRun(t *testing.T) { - if !getenv.BoolOrDefault("AOC_REGRESSION_ENABLED", false) { - t.Skip("Regression test disabled") + if !getenv.BoolOrDefault(regressionEnabled, false) { + t.Skipf("%s disabled", regressionEnabled) } - session := getenv.StringOrDefault("AOC_SESSION", "") + session := getenv.StringOrDefault(puzzles.AOCSession, "") if session == "" { - t.Fatal("AOC_SESSION not set") + t.Fatalf("%s not set", puzzles.AOCSession) } ctx := command.ContextWithSession(context.Background(), session)