Skip to content

Commit

Permalink
fix: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FluffyBucket committed Feb 29, 2024
1 parent e23485d commit d22cefb
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions envconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,11 +834,47 @@ func TestErrorMessageForRequiredAltVar(t *testing.T) {
t.Error("no failure when missing required variable")
}

if !strings.Contains(err.Error(), " ENV_CONFIG_BAR ") {
t.Errorf("expected error message to contain ENV_CONFIG_BAR, got \"%v\"", err)
}
}

func TestErrorMessageForRequiredAltVarNoPrefix(t *testing.T) {
var s struct {
Foo string `envconfig:"BAR" required:"true"`
}

os.Clearenv()
err := Process("", &s)

if err == nil {
t.Error("no failure when missing required variable")
}

if !strings.Contains(err.Error(), " BAR ") {
t.Errorf("expected error message to contain BAR, got \"%v\"", err)
}
}

func TestErrorMessageForRequiredAltVarNestedStruct(t *testing.T) {
var s struct {
Foo struct {
Bar string `envconfig:"BAR" required:"true"`
} `envconfig:"FOO" required:"true"`
}

os.Clearenv()
err := Process("ENV_CONFIG", &s)

if err == nil {
t.Error("no failure when missing required variable")
}

if !strings.Contains(err.Error(), " ENV_CONFIG_FOO_BAR ") {
t.Errorf("expected error message to contain ENV_CONFIG_FOO_BAR, got \"%v\"", err)
}
}

func TestNonTaggedFields(t *testing.T) {
var s struct {
Foo string `envconfig:"FOO"`
Expand Down

0 comments on commit d22cefb

Please sign in to comment.