Skip to content

Commit

Permalink
Lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
westy92 committed Aug 14, 2024
1 parent 12edec0 commit fdc122d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
4 changes: 1 addition & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ linters:
- exhaustruct
# TODO re-enable these
- err113
- funlen
- godox
- nlreturn
- paralleltest
- testifylint
- tparallel
linters-settings:
tagliatelle:
Expand All @@ -29,3 +26,4 @@ issues:
- path: _test\.go
linters:
- depguard
- funlen
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import (
func main() {
// Get a FREE API key from https://apilayer.com/marketplace/checkiday-api#pricing
client, err := holidays.New(holidays.APILayer, "<your API key>")

if err != nil {
fmt.Println(err)

return
}

Expand All @@ -49,9 +49,9 @@ func main() {
// Timezone: "America/Chicago",
// Adult: false,
})

if err != nil {
fmt.Println(err)

return
}

Expand All @@ -66,24 +66,25 @@ func main() {
// Start: 2020,
// End: 2030,
})

if err != nil {
fmt.Println(err)

return
}

fmt.Printf("The Event's hashtags are %q.\n", eventInfo.Event.Hashtags)

// Search for Events
query := "pizza day"

search, err := client.Search(ctx, holidays.SearchRequest{
Query: query,
// These parameters are the defaults but can be specified:
// Adult: false,
})

if err != nil {
fmt.Println(err)

return
}

Expand Down
4 changes: 4 additions & 0 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func main() {
client, err := holidays.New(holidays.APILayer, "<your API key>")

Check warning on line 12 in example/main.go

View check run for this annotation

Codecov / codecov/patch

example/main.go#L12

Added line #L12 was not covered by tests
if err != nil {
fmt.Println(err)

return
}

Expand All @@ -26,6 +27,7 @@ func main() {
})
if err != nil {
fmt.Println(err)

return
}

Expand All @@ -42,6 +44,7 @@ func main() {
})
if err != nil {
fmt.Println(err)

return
}

Expand All @@ -57,6 +60,7 @@ func main() {
})
if err != nil {
fmt.Println(err)

return
}

Expand Down
41 changes: 21 additions & 20 deletions holidays_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/h2non/gock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
holidays "github.com/westy92/holiday-event-api-go"
)

Expand All @@ -22,7 +23,7 @@ func TestNew(t *testing.T) {

assert := assert.New(t)
assert.Nil(api)
assert.EqualError(err, "please provide a valid API key. Get one at https://apilayer.com/marketplace/checkiday-api#pricing")
require.EqualError(t, err, "please provide a valid API key. Get one at https://apilayer.com/marketplace/checkiday-api#pricing")
})

t.Run("returns a new client", func(t *testing.T) {
Expand All @@ -31,7 +32,7 @@ func TestNew(t *testing.T) {
api, err := holidays.New(holidays.APILayer, "abc123")

assert := assert.New(t)
assert.NoError(err)
require.NoError(t, err)
assert.NotNil(api)
})
}
Expand Down Expand Up @@ -96,7 +97,7 @@ func TestCommonFunctionality(t *testing.T) {

assert := assert.New(t)
assert.Nil(response)
assert.EqualError(err, "MyError!")
require.Error(t, err, "MyError!")

assert.True(gock.IsDone())
})
Expand All @@ -112,7 +113,7 @@ func TestCommonFunctionality(t *testing.T) {

assert := assert.New(t)
assert.Nil(response)
assert.EqualError(err, "500 Internal Server Error")
require.EqualError(t, err, "500 Internal Server Error")

assert.True(gock.IsDone())
})
Expand All @@ -128,7 +129,7 @@ func TestCommonFunctionality(t *testing.T) {

assert := assert.New(t)
assert.Nil(response)
assert.EqualError(err, "599 ")
require.EqualError(t, err, "599 ")

assert.True(gock.IsDone())
})
Expand All @@ -144,7 +145,7 @@ func TestCommonFunctionality(t *testing.T) {

assert := assert.New(t)
assert.Nil(response)
assert.EqualError(err, "can't process request: Get \"https://api.apilayer.com/checkiday/events?adult=false\": err")
require.Error(t, err, "can't process request: Get \"https://api.apilayer.com/checkiday/events?adult=false\": err")

assert.True(gock.IsDone())
})
Expand All @@ -161,7 +162,7 @@ func TestCommonFunctionality(t *testing.T) {

assert := assert.New(t)
assert.Nil(response)
assert.EqualError(err, "can't parse response: unexpected EOF")
require.EqualError(t, err, "can't parse response: unexpected EOF")

assert.True(gock.IsDone())
})
Expand All @@ -182,7 +183,7 @@ func TestCommonFunctionality(t *testing.T) {
response, err := api.GetEvents(context.TODO(), holidays.GetEventsRequest{})

assert := assert.New(t)
assert.NoError(err)
require.NoError(t, err)
assert.Equal("America/Chicago", response.Timezone)

assert.True(gock.IsDone())
Expand All @@ -201,7 +202,7 @@ func TestCommonFunctionality(t *testing.T) {
response, err := api.GetEvents(context.TODO(), holidays.GetEventsRequest{})

assert := assert.New(t)
assert.NoError(err)
require.NoError(t, err)
assert.Equal(holidays.RateLimit{
Limit: 100,
Remaining: 88,
Expand All @@ -223,7 +224,7 @@ func TestGetEvents(t *testing.T) {
response, err := api.GetEvents(context.TODO(), holidays.GetEventsRequest{})

assert := assert.New(t)
assert.NoError(err)
require.NoError(t, err)
assert.False(response.Adult)
assert.Equal("America/Chicago", response.Timezone)
assert.Len(response.Events, 2)
Expand Down Expand Up @@ -256,7 +257,7 @@ func TestGetEvents(t *testing.T) {
})

assert := assert.New(t)
assert.NoError(err)
require.NoError(t, err)
assert.True(response.Adult)
assert.Equal("America/New_York", response.Timezone)
assert.Len(response.Events, 2)
Expand Down Expand Up @@ -287,7 +288,7 @@ func TestGetEventInfo(t *testing.T) {
})

assert := assert.New(t)
assert.NoError(err)
require.NoError(t, err)
assert.Equal("f90b893ea04939d7456f30c54f68d7b4", response.Event.ID)
assert.Len(response.Event.Hashtags, 2)

Expand All @@ -312,7 +313,7 @@ func TestGetEventInfo(t *testing.T) {
})

assert := assert.New(t)
assert.NoError(err)
require.NoError(t, err)
assert.Len(response.Event.Occurrences, 2)
assert.Equal(holidays.Occurrence{
Date: "08/08/2002",
Expand All @@ -337,7 +338,7 @@ func TestGetEventInfo(t *testing.T) {

assert := assert.New(t)
assert.Nil(response)
assert.EqualError(err, "Event not found.")
require.EqualError(t, err, "Event not found.")

assert.True(gock.IsDone())
})
Expand All @@ -350,7 +351,7 @@ func TestGetEventInfo(t *testing.T) {

assert := assert.New(t)
assert.Nil(response)
assert.EqualError(err, "event id is required")
require.EqualError(t, err, "event id is required")
})
}

Expand All @@ -369,7 +370,7 @@ func TestSearch(t *testing.T) {
})

assert := assert.New(t)
assert.NoError(err)
require.NoError(t, err)
assert.False(response.Adult)
assert.Equal("zucchini", response.Query)
assert.Len(response.Events, 3)
Expand Down Expand Up @@ -398,7 +399,7 @@ func TestSearch(t *testing.T) {
})

assert := assert.New(t)
assert.NoError(err)
require.NoError(t, err)
assert.True(response.Adult)
assert.Equal("porch day", response.Query)
assert.Len(response.Events, 1)
Expand Down Expand Up @@ -426,7 +427,7 @@ func TestSearch(t *testing.T) {

assert := assert.New(t)
assert.Nil(response)
assert.EqualError(err, "Please enter a longer search term.")
require.EqualError(t, err, "Please enter a longer search term.")

assert.True(gock.IsDone())
})
Expand All @@ -446,7 +447,7 @@ func TestSearch(t *testing.T) {

assert := assert.New(t)
assert.Nil(response)
assert.EqualError(err, "Too many results returned. Please refine your query.")
require.EqualError(t, err, "Too many results returned. Please refine your query.")

assert.True(gock.IsDone())
})
Expand All @@ -459,6 +460,6 @@ func TestSearch(t *testing.T) {

assert := assert.New(t)
assert.Nil(response)
assert.EqualError(err, "search query is required")
require.EqualError(t, err, "search query is required")
})
}

0 comments on commit fdc122d

Please sign in to comment.