Skip to content

Commit

Permalink
Encapsulates the API key config access. Refs #1
Browse files Browse the repository at this point in the history
  • Loading branch information
ariel17 committed Mar 7, 2023
1 parent 114836e commit f760858
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ docker build . -t be-challenge-arios
### Using environment variables file
Add keys to `.env` file:
```
FOOTBALL_APIKEY=v4lu3!#
FOOTBALL_MAX_REQUESTS_PER_MINUTE 10
FOOTBALL_APIKEY="v4lu3!#"
FOOTBALL_MAX_REQUESTS_PER_MINUTE=10
DATABASE_DSN="user:password@host:port/db_name"
DATABASE_STATUS_QUERY="SELECT 1"
```

Make Docker pick them as follows:
Expand Down
7 changes: 2 additions & 5 deletions pkg/clients/football.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,11 @@ type FootballAPIClient interface {
}

// NewFootballAPIClient creates a new instance of real API client.
func NewFootballAPIClient(apiKey string) FootballAPIClient {
if apiKey == "" {
panic("cannot work without a key")
}
func NewFootballAPIClient() FootballAPIClient {
return &realAPIClient{
baseURL: BASE_API_URL,
client: client,
apiKey: apiKey,
apiKey: configs.GetFootballAPIKey(),
rateLimiter: rateLimiter,
}
}
Expand Down
15 changes: 0 additions & 15 deletions pkg/clients/football_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,6 @@ var (
apiKey = "abc123"
)

func TestNewFootballAPIClient(t *testing.T) {
t.Run("fails without api key", func(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("The code did not panic")
}
}()
NewFootballAPIClient("")
})

t.Run("ok", func(t *testing.T) {
NewFootballAPIClient(apiKey)
})
}

func TestGet(t *testing.T) {
t.Run("rate limit applied", func(t *testing.T) {
apiContent := loadGoldenFile(t.Name())
Expand Down

0 comments on commit f760858

Please sign in to comment.