Skip to content

Commit

Permalink
Merge pull request #51 from ezeoleaf/feature/new-contributor
Browse files Browse the repository at this point in the history
add contributor and test
  • Loading branch information
ezeoleaf authored Mar 14, 2022
2 parents 0a17f87 + 5847d6d commit d867f79
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 16 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ test:
compile:
# 64-Bit
# FreeBDS
GOOS=freebsd GOARCH=amd64 go build -o ./bin/larry-freebsd-64 ./cmd/larry/.
GOOS=freebsd GOARCH=amd64 go build -ldflags="-s -w" -o ./bin/larry-freebsd-64 ./cmd/larry/.
# MacOS
GOOS=darwin GOARCH=amd64 go build -o ./bin/larry-macos-64 ./cmd/larry/.
# Linux
GOOS=linux GOARCH=amd64 go build -o ./bin/larry-linux-64 ./cmd/larry/.
GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -o ./bin/larry-macos-64 ./cmd/larry/.
Linux
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o ./bin/larry-linux-64 ./cmd/larry/.
# Windows
GOOS=windows GOARCH=amd64 go build -o ./bin/larry-windows-64 ./cmd/larry/.
GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" -o ./bin/larry-windows-64 ./cmd/larry/.

## help: prints this help message
help:
Expand Down
4 changes: 3 additions & 1 deletion cmd/larry/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ func main() {
Flags: larry.GetFlags(&cfg),
Authors: []*cli.Author{
{Name: "@ezeoleaf", Email: "[email protected]"},
{Name: "@beesaferoot", Email: "[email protected]"}},
{Name: "@beesaferoot", Email: "[email protected]"},
{Name: "@Shubhcoder"},
},
Action: func(c *cli.Context) error {
prov, err := getProvider(cfg)
if err != nil {
Expand Down
42 changes: 32 additions & 10 deletions publisher/twitter/publisher_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package twitter

import (
"fmt"
"testing"

"github.com/ezeoleaf/larry/config"
Expand Down Expand Up @@ -45,17 +46,38 @@ func TestCheckTweetDataInSafeMode(t *testing.T) {

p := NewPublisher(ak, c)

subtitle := "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
subtitle += "Vitae sapien pellentesque habitant morbi tristique senectus et netus et. Nunc sed velit dignissim sodales."

ti, s, u := "Lorem Ipsum", subtitle, "https://loremipsum.io/generator/?n=3&t=s"
ti, u := "Lorem Ipsum", "https://loremipsum.io/generator/?n=3&t=s"
extraData := []string{"50k", "Author: @unknown"}

cont := &domain.Content{Title: &ti, Subtitle: &s, URL: &u, ExtraData: extraData}

resp := p.prepareTweet(cont)

if len(resp) > TweetLength {
t.Errorf("tweet length is %v, which is greater than %v", len(resp), TweetLength)
for _, tc := range []struct {
Name string
Subtitle string
ExpectedResult string
}{
{
Name: "Test should return same content",
Subtitle: "t",
ExpectedResult: "Lorem Ipsum: t\n50k\nAuthor: @unknown\nhttps://loremipsum.io/generator/?n=3&t=s",
},
{
Name: "Test should truncate subtitle",
Subtitle: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Vitae sapien pellentesque habitant morbi tristique senectus et netus et. Nunc sed velit dignissim sodales.",
ExpectedResult: "Lorem Ipsum: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Vitae sapien pellentesque habitant morbi tristique senectus et netus et. Nunc ...\n50k\nAuthor: @unknown\nhttps://loremipsum.io/generator/?n=3&t=s",
},
} {
t.Run(tc.Name, func(t *testing.T) {
cont := &domain.Content{Title: &ti, Subtitle: &tc.Subtitle, URL: &u, ExtraData: extraData}

resp := p.prepareTweet(cont)
fmt.Println(resp)
if resp != tc.ExpectedResult {
t.Errorf("resp should be %v, got %v", tc.ExpectedResult, resp)
}

if len(resp) > TweetLength {
t.Errorf("tweet length is %v, which is greater than %v", len(resp), TweetLength)
}
})
}

}

0 comments on commit d867f79

Please sign in to comment.