Skip to content

Commit

Permalink
Expose Action.Getenv (#37)
Browse files Browse the repository at this point in the history
This commit makes `Action.getenv` accessible without making it settable without using `WithGetenv`. That allows tests with a fake environment to pass only Action.
  • Loading branch information
AlekSi committed Feb 9, 2022
1 parent 7040a8f commit 2b8e95d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,12 @@ func (c *Action) GetIDToken(ctx context.Context, audience string) (string, error
return tokenResp.Value, nil
}

// Getenv retrieves the value of the environment variable named by the key.
// It uses an internal function that can be set with `WithGetenv`.
func (c *Action) Getenv(key string) string {
return c.getenv(key)
}

// GetenvFunc is an abstraction to make tests feasible for commands that
// interact with environment variables.
type GetenvFunc func(k string) string
type GetenvFunc func(key string) string
2 changes: 1 addition & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"net/http"
)

// Option is a modifier for an Action
// Option is a modifier for an Action.
type Option func(*Action) *Action

// WithWriter sets the writer function on an Action. By default, this will
Expand Down
2 changes: 1 addition & 1 deletion options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestWithGetenv(t *testing.T) {
})

opt(a)
if got, want := a.getenv("any"), "sentinel"; got != want {
if got, want := a.Getenv("any"), "sentinel"; got != want {
t.Errorf("expected %q to be %q", got, want)
}
}

0 comments on commit 2b8e95d

Please sign in to comment.