Skip to content

Commit

Permalink
refactor: Move environment variables to constants (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
obalunenko committed Feb 18, 2022
1 parent be3b301 commit 81bbf52
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion cmd/aoc-cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"github.com/urfave/cli/v2"

"github.com/obalunenko/advent-of-code/internal/puzzles"
)

const (
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions internal/puzzles/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,7 @@ const (
unsolved = "not solved"
undefined = "undefined"
inProgress = "in progress"

// AOCSession env variable name.
AOCSession = "AOC_SESSION"
)
12 changes: 8 additions & 4 deletions tests/regression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 81bbf52

Please sign in to comment.