Skip to content

Commit

Permalink
move simple fetch tests to "go test"
Browse files Browse the repository at this point in the history
  • Loading branch information
azimut committed Apr 12, 2023
1 parent cde4349 commit ac610f8
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 19 deletions.
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ jobs:
go-version: 1.17
- run: |
make test
make testrun > /dev/null
20 changes: 4 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
HN_URL := 'https://news.ycombinator.com/item?id=3078128'
TW_URL := 'https://twitter.com/TwitterDev/status/1443269993676763138'
GO_FILES = $(shell find . -type f -name '*.go')

.PHONY: all install clean test testrun

all: twitterview hackerview redditview

hackerview: $(GO_FILES)
go build -race -v -ldflags="-s -w" ./cmd/$@
ls -lh $@

hackerview:
redditview:
twitterview: $(GO_FILES)
go build -v -ldflags="-s -w" ./cmd/$@
ls -lh $@

redditview: $(GO_FILES)
go build -v -ldflags="-s -w" ./cmd/$@
ls -lh $@

install: hackerview twitterview redditview
mv hackerview $(HOME)/go/bin/
mv twitterview $(HOME)/go/bin/
mv redditview $(HOME)/go/bin/
mv redditview $(HOME)/go/bin/

clean: ; go clean -x ./...
test: ; go test -vet=all -v ./...

testrun:
go run cmd/hackerview/main.go -l 10 -t 20s $(HN_URL)
go run cmd/twitterview/main.go -t 20s $(TW_URL)
test: ; go test -vet=all -v -race ./...
2 changes: 1 addition & 1 deletion cmd/twitterview/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var url string

func init() {
flag.DurationVar(&opt.timeout, "t", time.Second*5, "timeout in seconds")
flag.StringVar(&opt.userAgent, "A", "Wget", "default User-Agent sent")
flag.StringVar(&opt.userAgent, "A", "Twitter_View/0.1", "default User-Agent sent")
flag.BoolVar(&opt.useColors, "C", true, "use colors")
flag.BoolVar(&opt.usePretty, "P", true, "use pretty formatting")
flag.IntVar(&opt.width, "w", 0, "fixed with, defaults to console width")
Expand Down
15 changes: 15 additions & 0 deletions internal/fetch/fetch_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package fetch

import (
"testing"
"time"
)

const URL = `https://www.google.com/robots.txt`

func TestFech(t *testing.T) {
_, err := Fetch(URL, "Wget", time.Second*10)
if err != nil {
t.Fail()
}
}
15 changes: 15 additions & 0 deletions internal/hackernews/fetch_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package hackernews

import (
"testing"
"time"
)

const URL = `https://news.ycombinator.com/item?id=3078128`

func TestHNFetch(t *testing.T) {
_, _, err := Fetch(URL, time.Second*10, 10, 2)
if err != nil {
t.Fail()
}
}
15 changes: 15 additions & 0 deletions internal/reddit/fetch_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package reddit

import (
"testing"
"time"
)

const URL = `https://old.reddit.com/r/gamedev/comments/horm1a/ive_started_making_a_teaching_aid_for_people/`

func TestRTFetch(t *testing.T) {
_, err := Fetch(URL, "Reddit_Cli/0.1", time.Second*10)
if err != nil {
t.Fail()
}
}
2 changes: 1 addition & 1 deletion internal/reddit/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (op Op) String() (ret string) {
ret += "\n"
ret += fixupContent(op.selftext, MaxWidth, Padding)
ret += "\n"
ret += fmt.Sprintf("%s(%d) - %s - %d Comment(s)\n\n\n\n",
ret += fmt.Sprintf("%s(%d) - %s - %d Comment(s)\n\n\n",
color.New(AuthorColor).Sprint(op.author),
op.upvotes,
relativeFromUnix(op.createdUTC),
Expand Down
File renamed without changes.
15 changes: 15 additions & 0 deletions internal/twitter/fetch_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package twitter

import (
"testing"
"time"
)

const URL = `https://twitter.com/TwitterDev/status/1443269993676763138`

func TestTWFetch(t *testing.T) {
_, err := Fetch(URL, "Twitter_View/0.1", time.Second*10)
if err != nil {
t.Fail()
}
}

0 comments on commit ac610f8

Please sign in to comment.