Skip to content

Commit

Permalink
style: update linting with golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
pjsier committed Nov 18, 2020
1 parent 4d1b5e1 commit 5ab9022
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 25 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ jobs:

- run: make format

- uses: grandcolline/golang-github-actions@v1.1.0
- uses: actions-contrib/golangci-lint@v1
env:
GOROOT: ""
with:
run: lint
token: ${{ secrets.GITHUB_TOKEN }}
args: "run"

- run: make build
7 changes: 4 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ jobs:

- run: make format

- uses: grandcolline/golang-github-actions@v1.1.0
- uses: actions-contrib/golangci-lint@v1
env:
GOROOT: ""
with:
run: lint
token: ${{ secrets.GITHUB_TOKEN }}
args: "run"

- run: make build

Expand Down
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
run:
skip-dirs:
- node_modules
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ format:
test -z $$(gofmt -l .)

lint:
golint -set_exit_status ./...
golangci-lint run

build:
@for function in $(functions) ; do \
Expand Down
4 changes: 2 additions & 2 deletions functions/handle_tweet/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestHandleTweetExits(t *testing.T) {
dbMock.ExpectQuery("SELECT (.+) FROM (.+) WHERE (.+) LIMIT 1").
WithArgs(bill.TweetID).
WillReturnRows(sqlmock.NewRows([]string{"pk", "tweet_id"}).AddRow(1, 1234))
handleTweet(&bill, DB, snsMock)
_ = handleTweet(&bill, DB, snsMock)
if err := dbMock.ExpectationsWereMet(); err != nil {
t.Errorf("there were unfulfilled expectations: %s", err)
}
Expand All @@ -48,7 +48,7 @@ func TestHandleTweetEmptyBillID(t *testing.T) {
WithArgs(bill.TweetID).
WillReturnError(gorm.ErrRecordNotFound)
snsMock.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil)
handleTweet(&bill, DB, snsMock)
_ = handleTweet(&bill, DB, snsMock)
if err := dbMock.ExpectationsWereMet(); err != nil {
t.Errorf("there were unfulfilled expectations: %s", err)
}
Expand Down
14 changes: 7 additions & 7 deletions functions/query_mentions/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func TestQueryMentionsIgnoresEmptyBillID(t *testing.T) {
tweets := []twitter.Tweet{
twitter.Tweet{
{
ID: 1,
Text: "Testing bill",
User: &twitter.User{ScreenName: "testuser"},
Expand All @@ -23,13 +23,13 @@ func TestQueryMentionsIgnoresEmptyBillID(t *testing.T) {
snsMock := new(mocks.SNSClientMock)
twttrMock.On("GetMentions", mock.Anything).Return(tweets, nil)
snsMock.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil)
queryMentions(twttrMock, snsMock)
_ = queryMentions(twttrMock, snsMock)
snsMock.AssertNotCalled(t, "Publish", mock.Anything, mock.Anything, "handle_tweet")
}

func TestQueryMentionsIgnoresOldTweet(t *testing.T) {
tweets := []twitter.Tweet{
twitter.Tweet{
{
ID: 1,
Text: "@chicagoledger O2010-11 Testing bill",
User: &twitter.User{ScreenName: "testuser"},
Expand All @@ -40,14 +40,14 @@ func TestQueryMentionsIgnoresOldTweet(t *testing.T) {
snsMock := new(mocks.SNSClientMock)
twttrMock.On("GetMentions", mock.Anything).Return(tweets, nil)
snsMock.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil)
queryMentions(twttrMock, snsMock)
_ = queryMentions(twttrMock, snsMock)
snsMock.AssertNotCalled(t, "Publish", mock.Anything, mock.Anything, "handle_tweet")
}

func TestQueryMentionsTweetsBill(t *testing.T) {
log.Printf(time.Now().UTC().String())
log.Println(time.Now().UTC().String())
tweets := []twitter.Tweet{
twitter.Tweet{
{
ID: 1,
Text: "@chicagoledger O2010-11 Testing bill",
User: &twitter.User{ScreenName: "testuser"},
Expand All @@ -58,6 +58,6 @@ func TestQueryMentionsTweetsBill(t *testing.T) {
snsMock := new(mocks.SNSClientMock)
twttrMock.On("GetMentions", mock.Anything).Return(tweets, nil)
snsMock.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil)
queryMentions(twttrMock, snsMock)
_ = queryMentions(twttrMock, snsMock)
snsMock.AssertCalled(t, "Publish", mock.Anything, mock.Anything, "handle_tweet")
}
4 changes: 2 additions & 2 deletions functions/update_bill/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func handler(request events.SNSEvent) error {
err := json.Unmarshal([]byte(message), &bill)
// Log errors because we don't want to trigger Lambda's retries
if err != nil {
snsClient.Publish(message, os.Getenv("SNS_TOPIC_ARN"), "update_bill")
_ = snsClient.Publish(message, os.Getenv("SNS_TOPIC_ARN"), "update_bill")
log.Println(err)
return nil
}
Expand All @@ -70,7 +70,7 @@ func handler(request events.SNSEvent) error {
err = updateBill(bill, actions, snsClient)
// Only log this error since it just prevented
if err != nil {
snsClient.Publish(message, os.Getenv("SNS_TOPIC_ARN"), "update_bill")
_ = snsClient.Publish(message, os.Getenv("SNS_TOPIC_ARN"), "update_bill")
log.Println(err)
}
return nil
Expand Down
8 changes: 4 additions & 4 deletions functions/update_bill/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestUpdateBillIgnoresNoChanges(t *testing.T) {
Data: `[]`,
}
snsMock.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil)
updateBill(bill, []models.LegistarAction{}, snsMock)
_ = updateBill(bill, []models.LegistarAction{}, snsMock)
snsMock.AssertCalled(t, "Publish", mock.Anything, mock.Anything, "save_bill")
}

Expand All @@ -29,7 +29,7 @@ func TestUpdateBillNilNextRunSendsTweet(t *testing.T) {
Data: `[]`,
}
snsMock.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil)
updateBill(bill, []models.LegistarAction{}, snsMock)
_ = updateBill(bill, []models.LegistarAction{}, snsMock)
snsMock.AssertExpectations(t)
snsMock.AssertNumberOfCalls(t, "Publish", 2)
}
Expand All @@ -44,10 +44,10 @@ func TestUpdateBillNewActionsSendsTweet(t *testing.T) {
}
actionDate, _ := time.Parse("2006-01-02", "2019-01-01")
actions := []models.LegistarAction{
models.LegistarAction{Date: actionDate, Action: "introduction", Actor: "Test"},
{Date: actionDate, Action: "introduction", Actor: "Test"},
}
snsMock.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil)
updateBill(bill, actions, snsMock)
_ = updateBill(bill, actions, snsMock)
snsMock.AssertExpectations(t)
snsMock.AssertNumberOfCalls(t, "Publish", 2)
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ require (
github.com/dghubble/go-twitter v0.0.0-20190512073027-53f972dc4b06
github.com/dghubble/oauth1 v0.5.0
github.com/dghubble/sling v1.2.0 // indirect
github.com/fnproject/fdk-go v0.0.3
github.com/google/go-querystring v1.0.0 // indirect
github.com/jinzhu/gorm v1.9.8
github.com/stretchr/testify v1.2.2
github.com/tencentyun/scf-go-lib v0.0.0-20200624065115-ba679e2ec9c9
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y=
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
github.com/fnproject/fdk-go v0.0.3 h1:CkUsIH0QmWDb/vDU3lGoP+Fl0VIfk2/xi1v82Qk5vCs=
github.com/fnproject/fdk-go v0.0.3/go.mod h1:9m+nEyku9SqJAVJQsfZOZBQzFkCs+jvmbZJhvgDX4ts=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
Expand Down Expand Up @@ -102,6 +104,8 @@ github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/tencentyun/scf-go-lib v0.0.0-20200624065115-ba679e2ec9c9 h1:JdeXp/XPi7lBmpQNSUxElMAvwppMlFSiamTtXYRFuUc=
github.com/tencentyun/scf-go-lib v0.0.0-20200624065115-ba679e2ec9c9/go.mod h1:K3DbqPpP2WE/9MWokWWzgFZcbgtMb9Wd5CYk9AAbEN8=
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down
5 changes: 3 additions & 2 deletions pkg/svc/sns.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ type SNSClient struct {

// NewSNSClient creates an SNSClient object
func NewSNSClient() *SNSClient {
client := sns.New(session.New())
sess, _ := session.NewSession()
client := sns.New(sess)
return &SNSClient{Client: client}
}

Expand All @@ -28,7 +29,7 @@ func (c *SNSClient) Publish(message string, topicArn string, feed string) error
Message: aws.String(message),
TopicArn: aws.String(topicArn),
MessageAttributes: map[string]*sns.MessageAttributeValue{
"feed": &sns.MessageAttributeValue{
"feed": {
DataType: aws.String("String"),
StringValue: aws.String(feed),
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/svc/twitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewTwitterClient() *TwitterClient {

// PostTweet posts a tweet to Twitter
func (t *TwitterClient) PostTweet(tweet string, params *twitter.StatusUpdateParams) error {
log.Printf(tweet)
log.Println(tweet)
_, _, err := t.Client.Statuses.Update(tweet, params)
return err
}
Expand Down

0 comments on commit 5ab9022

Please sign in to comment.