8000 refactor: Move environment variables to constants (#98) · obalunenko/advent-of-code@81bbf52 · GitHub
[go: up one dir, main page]

Skip to content

Commit 81bbf52

Browse files
authored
refactor: Move environment variables to constants (#98)
1 parent be3b301 commit 81bbf52

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

cmd/aoc-cli/flags.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package main
22

33
import (
44
"github.com/urfave/cli/v2"
5+
6+
"github.com/obalunenko/advent-of-code/internal/puzzles"
57
)
68

79
const (
@@ -48,7 +50,7 @@ func cmdRunFlags() []cli.Flag {
4850
Name: flagSession,
4951
Aliases: []string{flagShortSession},
5052
Usage: "AOC auth session to get inputs",
51-
EnvVars: []string{"AOC_SESSION"},
53+
EnvVars: []string{puzzles.AOCSession},
5254
FilePath: "",
5355
Required: true,
5456
Hidden: false,

internal/puzzles/constants.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,7 @@ const (
6161
unsolved = "not solved"
6262
undefined = "undefined"
6363
inProgress = "in progress"
64+
65+
// AOCSession env variable name.
66+
AOCSession = "AOC_SESSION"
6467
)

tests/regression_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,19 @@ type testcase struct {
2525
wantErr bool
2626
}
2727

28+
const (
29+
regressionEnabled = "AOC_REGRESSION_ENABLED"
30+
)
31+
2832
// Regression tests for all puzzles. Check that answers still correct.
2933
func TestRun(t *testing.T) {
30-
if !getenv.BoolOrDefault("AOC_REGRESSION_ENABLED", false) {
31-
t.Skip("Regression test disabled")
34+
if !getenv.BoolOrDefault(regressionEnabled, false) {
35+
t.Skipf("%s disabled", regressionEnabled)
3236
}
3337

34-
session := getenv.StringOrDefault("AOC_SESSION", "")
38+
session := getenv.StringOrDefault(puzzles.AOCSession, "")
3539
if session == "" {
36-
t.Fatal("AOC_SESSION not set")
40+
t.Fatalf("%s not set", puzzles.AOCSession)
3741
}
3842

3943
ctx := command.ContextWithSession(context.Background(), session)

0 commit comments

Comments
 (0)
0