This repository has been archived by the owner on Dec 17, 2023. It is now read-only.
forked from plantimals/rsslay
-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new workflow for tests and firsts tests #10
- Loading branch information
Showing
6 changed files
with
205 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: CI Build & Test | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
|
||
jobs: | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.19 | ||
|
||
- name: Build | ||
run: go build -v ./... | ||
|
||
- name: Test | ||
run: go test -v ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package feed | ||
|
||
import ( | ||
"github.com/mmcdole/gofeed" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
"time" | ||
) | ||
|
||
const samplePubKey = "1870bcd5f6081ef7ea4b17204ffa4e92de51670142be0c8140e0635b355ca85f" | ||
const sampleUrlForPublicKey = "https://nitter.moomoo.me/Bitcoin/rss" | ||
const samplePrivateKeyForPubKey = "27660ab89e69f59bb8d9f0bd60da4a8515cdd3e2ca4f91d72a242b086d6aaaa7" | ||
const testSecret = "test" | ||
|
||
const sampleInvalidUrl = "https:// nostr.example/" | ||
const sampleInvalidUrlContentType = "https://accounts.google.com/.well-known/openid-configuration" | ||
const sampleRedirectingUrl = "https://httpstat.us/301" | ||
const sampleValidDirectFeedUrl = "https://mastodon.social/@Gargron.rss" | ||
const sampleValidIndirectFeedUrl = "https://www.rssboard.org/" | ||
const sampleValidIndirectFeedUrlExpected = "http://feeds.rssboard.org/rssboard" | ||
const sampleValidWithoutFeedUrl = "https://go.dev/" | ||
const sampleValidWithRelativeFeedUrl = "https://golangweekly.com/" | ||
const sampleValidWithRelativeFeedUrlExpected = "https://golangweekly.com/rss" | ||
|
||
var actualTime = time.Now() | ||
var sampleNitterFeed = gofeed.Feed{ | ||
Title: "Coldplay / @coldplay", | ||
Description: "Twitter feed for: @coldplay. Generated by nitter.moomoo.me", | ||
Link: "http://nitter.moomoo.me/coldplay", | ||
FeedLink: "https://nitter.moomoo.me/coldplay/rss", | ||
Links: []string{"http://nitter.moomoo.me/coldplay"}, | ||
PublishedParsed: &actualTime, | ||
Language: "en-us", | ||
Image: &gofeed.Image{ | ||
URL: "http://nitter.moomoo.me/pic/pbs.twimg.com%2Fprofile_images%2F1417506973877211138%2FYIm7dOQH_400x400.jpg", | ||
Title: "Coldplay / @coldplay", | ||
}, | ||
} | ||
var sampleDefaultFeed = gofeed.Feed{ | ||
Title: "Golang Weekly", | ||
Description: "A weekly newsletter about the Go programming language", | ||
Link: "https://golangweekly.com/rss", | ||
FeedLink: "https://golangweekly.com/rss", | ||
Links: []string{"https://golangweekly.com/issues/446"}, | ||
PublishedParsed: &actualTime, | ||
Language: "en-us", | ||
Image: nil, | ||
} | ||
|
||
func TestGetFeedURLWithInvalidURLReturnsEmptyString(t *testing.T) { | ||
feed := GetFeedURL(sampleInvalidUrl) | ||
assert.Empty(t, feed) | ||
} | ||
|
||
func TestGetFeedURLWithInvalidContentTypeReturnsEmptyString(t *testing.T) { | ||
feed := GetFeedURL(sampleInvalidUrlContentType) | ||
assert.Empty(t, feed) | ||
} | ||
|
||
func TestGetFeedURLWithRedirectingURLReturnsEmptyString(t *testing.T) { | ||
feed := GetFeedURL(sampleRedirectingUrl) | ||
assert.Empty(t, feed) | ||
} | ||
|
||
func TestGetFeedURLWithValidUrlOfValidTypesReturnsSameUrl(t *testing.T) { | ||
feed := GetFeedURL(sampleValidDirectFeedUrl) | ||
assert.Equal(t, sampleValidDirectFeedUrl, feed) | ||
} | ||
|
||
func TestGetFeedURLWithValidUrlOfHtmlTypeWithFeedReturnsFoundFeed(t *testing.T) { | ||
feed := GetFeedURL(sampleValidIndirectFeedUrl) | ||
assert.Equal(t, sampleValidIndirectFeedUrlExpected, feed) | ||
} | ||
|
||
func TestGetFeedURLWithValidUrlOfHtmlTypeWithRelativeFeedReturnsFoundFeed(t *testing.T) { | ||
feed := GetFeedURL(sampleValidWithRelativeFeedUrl) | ||
assert.Equal(t, sampleValidWithRelativeFeedUrlExpected, feed) | ||
} | ||
|
||
func TestGetFeedURLWithValidUrlOfHtmlTypeWithoutFeedReturnsEmpty(t *testing.T) { | ||
feed := GetFeedURL(sampleValidWithoutFeedUrl) | ||
assert.Empty(t, feed) | ||
} | ||
|
||
func TestParseFeedWithValidUrlReturnsParsedFeed(t *testing.T) { | ||
feed, err := ParseFeed(sampleValidWithRelativeFeedUrlExpected) | ||
assert.NotNil(t, feed) | ||
assert.NoError(t, err) | ||
} | ||
|
||
func TestParseFeedWithValidUrlWithoutFeedReturnsError(t *testing.T) { | ||
feed, err := ParseFeed(sampleValidWithoutFeedUrl) | ||
assert.Nil(t, feed) | ||
assert.Error(t, err) | ||
} | ||
|
||
func TestParseFeedWithCachedUrlReturnsCachedParsedFeed(t *testing.T) { | ||
_, _ = ParseFeed(sampleValidWithRelativeFeedUrlExpected) | ||
feed, err := ParseFeed(sampleValidWithRelativeFeedUrlExpected) | ||
assert.NotNil(t, feed) | ||
assert.NoError(t, err) | ||
} | ||
|
||
func TestFeedToSetMetadata(t *testing.T) { | ||
testCases := []struct { | ||
pubKey string | ||
feed *gofeed.Feed | ||
originalUrl string | ||
enableAutoRegistration bool | ||
defaultProfilePictureUrl string | ||
}{ | ||
{ | ||
pubKey: samplePubKey, | ||
feed: &sampleNitterFeed, | ||
originalUrl: sampleNitterFeed.FeedLink, | ||
enableAutoRegistration: true, | ||
defaultProfilePictureUrl: "https://image.example", | ||
}, | ||
{ | ||
pubKey: samplePubKey, | ||
feed: &sampleDefaultFeed, | ||
originalUrl: sampleDefaultFeed.FeedLink, | ||
enableAutoRegistration: true, | ||
defaultProfilePictureUrl: "https://image.example", | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
metadata := FeedToSetMetadata(tc.pubKey, tc.feed, tc.originalUrl, tc.enableAutoRegistration, tc.defaultProfilePictureUrl) | ||
assert.NotEmpty(t, metadata) | ||
assert.Equal(t, samplePubKey, metadata.PubKey) | ||
assert.Equal(t, 0, metadata.Kind) | ||
assert.Empty(t, metadata.Sig) | ||
} | ||
} | ||
|
||
func TestPrivateKeyFromFeed(t *testing.T) { | ||
sk := PrivateKeyFromFeed(sampleUrlForPublicKey, testSecret) | ||
assert.Equal(t, samplePrivateKeyForPubKey, sk) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package helpers | ||
|
||
import ( | ||
"fmt" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
const sampleInvalidUrl = "https:// nostr.example/" | ||
const sampleValidUrl = "https://nostr.example" | ||
|
||
func TestJoinWithInvalidUrlReturnsNil(t *testing.T) { | ||
join, err := UrlJoin(sampleInvalidUrl) | ||
assert.Equal(t, join, "") | ||
assert.ErrorContains(t, err, "invalid character") | ||
} | ||
|
||
func TestJoinWithValidUrlAndNoExtraElementsReturnsBaseUrl(t *testing.T) { | ||
join, err := UrlJoin(sampleValidUrl) | ||
assert.Equal(t, sampleValidUrl, join) | ||
assert.NoError(t, err) | ||
} | ||
|
||
func TestJoinWithValidUrlAndExtraElementsReturnsValidUrl(t *testing.T) { | ||
join, err := UrlJoin(sampleValidUrl, "rss") | ||
expectedJoinResult := fmt.Sprintf("%s/%s", sampleValidUrl, "rss") | ||
assert.Equal(t, expectedJoinResult, join) | ||
assert.NoError(t, err) | ||
} |