mirror of
https://github.com/jlelse/GoBlog
synced 2024-06-18 04:25:00 +00:00
Add test
This commit is contained in:
parent
81bfa438b1
commit
333e7ffc15
94
blogroll_test.go
Normal file
94
blogroll_test.go
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http/httptest"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_blogroll(t *testing.T) {
|
||||||
|
|
||||||
|
fc := &fakeHttpClient{}
|
||||||
|
|
||||||
|
app := &goBlog{
|
||||||
|
httpClient: fc,
|
||||||
|
cfg: &config{
|
||||||
|
Db: &configDb{
|
||||||
|
File: filepath.Join(t.TempDir(), "test.db"),
|
||||||
|
},
|
||||||
|
Server: &configServer{},
|
||||||
|
DefaultBlog: "en",
|
||||||
|
Blogs: map[string]*configBlog{
|
||||||
|
"en": {
|
||||||
|
Lang: "en",
|
||||||
|
Blogroll: &configBlogroll{
|
||||||
|
Enabled: true,
|
||||||
|
Path: "/br",
|
||||||
|
AuthHeader: "Authheader",
|
||||||
|
AuthValue: "Authtoken",
|
||||||
|
Opml: "https://example.com/opml",
|
||||||
|
Categories: []string{"A", "B"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
User: &configUser{},
|
||||||
|
Cache: &configCache{
|
||||||
|
Enable: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = app.initDatabase(false)
|
||||||
|
app.initComponents(false)
|
||||||
|
|
||||||
|
fc.setFakeResponse(200, `
|
||||||
|
<opml version="2.0">
|
||||||
|
<head>
|
||||||
|
<dateCreated>Tue, 30 Nov 2021 19:34:38 UTC</dateCreated>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<outline text="B">
|
||||||
|
<outline text="A text" xmlUrl="https://a.example.com/feed.xml" htmlUrl="https://a.example.com" title="A title"/>
|
||||||
|
<outline text="B text" xmlUrl="https://b.example.com/feed.xml" htmlUrl="https://b.example.com" title="B title"/>
|
||||||
|
</outline>
|
||||||
|
<outline text="A">
|
||||||
|
<outline text="C text" xmlUrl="https://c.example.com/feed.xml" htmlUrl="https://c.example.com" title="C title"/>
|
||||||
|
<outline text="D text" xmlUrl="https://d.example.com/feed.xml" htmlUrl="https://d.example.com" title="D title"/>
|
||||||
|
</outline>
|
||||||
|
<outline text="C">
|
||||||
|
</outline>
|
||||||
|
</body>
|
||||||
|
</opml>
|
||||||
|
`)
|
||||||
|
|
||||||
|
// Test getting the blogroll
|
||||||
|
// Tests sorting and filtering
|
||||||
|
|
||||||
|
outlines, err := app.getBlogrollOutlines("en")
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, outlines)
|
||||||
|
|
||||||
|
if assert.Len(t, outlines, 2) {
|
||||||
|
assert.Equal(t, "A", outlines[0].Text)
|
||||||
|
assert.Equal(t, "B", outlines[1].Text)
|
||||||
|
if assert.Len(t, outlines[0].Outlines, 2) {
|
||||||
|
assert.Equal(t, "C text", outlines[0].Outlines[0].Text)
|
||||||
|
assert.Equal(t, "C title", outlines[0].Outlines[0].Title)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test getting the OPML
|
||||||
|
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
req := httptest.NewRequest("GET", "/br.opml", nil)
|
||||||
|
req = req.WithContext(context.WithValue(req.Context(), blogKey, "en"))
|
||||||
|
|
||||||
|
app.serveBlogrollExport(rec, req)
|
||||||
|
|
||||||
|
assert.Equal(t, 200, rec.Code)
|
||||||
|
|
||||||
|
}
|
7
go.mod
7
go.mod
|
@ -54,7 +54,6 @@ require (
|
||||||
github.com/yuin/goldmark-highlighting v0.0.0-20210516132338-9216f9c5aa01
|
github.com/yuin/goldmark-highlighting v0.0.0-20210516132338-9216f9c5aa01
|
||||||
golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871
|
golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871
|
||||||
golang.org/x/net v0.0.0-20211123203042-d83791d6bcd9
|
golang.org/x/net v0.0.0-20211123203042-d83791d6bcd9
|
||||||
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8
|
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
|
||||||
golang.org/x/text v0.3.7
|
golang.org/x/text v0.3.7
|
||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
|
||||||
|
@ -65,7 +64,10 @@ require (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Override some modules with own forks
|
// Override some modules with own forks
|
||||||
replace github.com/yuin/goldmark-highlighting => github.com/jlelse/goldmark-highlighting v0.0.0-20211115195757-39f0fea96680
|
replace (
|
||||||
|
github.com/hacdias/indieauth => github.com/jlelse/indieauth v1.5.1-0.20211130162540-343ab6d928fa
|
||||||
|
github.com/yuin/goldmark-highlighting => github.com/jlelse/goldmark-highlighting v0.0.0-20211115195757-39f0fea96680
|
||||||
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/akutz/memconn v0.1.0 // indirect
|
github.com/akutz/memconn v0.1.0 // indirect
|
||||||
|
@ -119,6 +121,7 @@ require (
|
||||||
go4.org/intern v0.0.0-20211027215823-ae77deb06f29 // indirect
|
go4.org/intern v0.0.0-20211027215823-ae77deb06f29 // indirect
|
||||||
go4.org/mem v0.0.0-20201119185036-c04c5a6ff174 // indirect
|
go4.org/mem v0.0.0-20201119185036-c04c5a6ff174 // indirect
|
||||||
go4.org/unsafe/assume-no-moving-gc v0.0.0-20211027215541-db492cf91b37 // indirect
|
go4.org/unsafe/assume-no-moving-gc v0.0.0-20211027215541-db492cf91b37 // indirect
|
||||||
|
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
|
||||||
golang.org/x/sys v0.0.0-20211110154304-99a53858aa08 // indirect
|
golang.org/x/sys v0.0.0-20211110154304-99a53858aa08 // indirect
|
||||||
golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6 // indirect
|
golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6 // indirect
|
||||||
golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224 // indirect
|
golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224 // indirect
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -268,8 +268,6 @@ github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad
|
||||||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
|
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
|
||||||
github.com/hacdias/indieauth v1.5.0 h1:BugufHJs4G3HCHCImTfwziUYhjQ5IssKpGcJ4SFPvfY=
|
|
||||||
github.com/hacdias/indieauth v1.5.0/go.mod h1:e/YWhcIgtz/WR/ZledToHTE3Xx0VBu18y84rhzLpzWY=
|
|
||||||
github.com/hashicorp/consul/api v1.10.1/go.mod h1:XjsvQN+RJGWI2TWy1/kqaE16HrR2J/FWgkYjdZQsX9M=
|
github.com/hashicorp/consul/api v1.10.1/go.mod h1:XjsvQN+RJGWI2TWy1/kqaE16HrR2J/FWgkYjdZQsX9M=
|
||||||
github.com/hashicorp/consul/sdk v0.8.0/go.mod h1:GBvyrGALthsZObzUGsfgHZQDXjg4lOjagTIwIR1vPms=
|
github.com/hashicorp/consul/sdk v0.8.0/go.mod h1:GBvyrGALthsZObzUGsfgHZQDXjg4lOjagTIwIR1vPms=
|
||||||
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||||
|
@ -305,6 +303,8 @@ github.com/jlelse/feeds v1.2.1-0.20210704161900-189f94254ad4 h1:d2oKwfgLl3ef0PyY
|
||||||
github.com/jlelse/feeds v1.2.1-0.20210704161900-189f94254ad4/go.mod h1:vt0iOV52/wq97Ql/jp7mUkqyrlEiGQuhHic4bVoHy0c=
|
github.com/jlelse/feeds v1.2.1-0.20210704161900-189f94254ad4/go.mod h1:vt0iOV52/wq97Ql/jp7mUkqyrlEiGQuhHic4bVoHy0c=
|
||||||
github.com/jlelse/goldmark-highlighting v0.0.0-20211115195757-39f0fea96680 h1:c8Vs/L9WqCXFY0LTJjgbzaRCadEmJZjMn6qY9XwZZNM=
|
github.com/jlelse/goldmark-highlighting v0.0.0-20211115195757-39f0fea96680 h1:c8Vs/L9WqCXFY0LTJjgbzaRCadEmJZjMn6qY9XwZZNM=
|
||||||
github.com/jlelse/goldmark-highlighting v0.0.0-20211115195757-39f0fea96680/go.mod h1:jxhQhWF6W/ybgbZpMP2/Ui0D7b+x8ubBFipwXJJ1qME=
|
github.com/jlelse/goldmark-highlighting v0.0.0-20211115195757-39f0fea96680/go.mod h1:jxhQhWF6W/ybgbZpMP2/Ui0D7b+x8ubBFipwXJJ1qME=
|
||||||
|
github.com/jlelse/indieauth v1.5.1-0.20211130162540-343ab6d928fa h1:wZfWF9FAxlXF0yrXIrOQhXnIn7BqcMxw0K81A0r5Ups=
|
||||||
|
github.com/jlelse/indieauth v1.5.1-0.20211130162540-343ab6d928fa/go.mod h1:3b/smz++Ub9yHiBvHzHbn9uKqdUx7gZbafROtGVqz3c=
|
||||||
github.com/joeshaw/gengen v0.0.0-20190604015154-c77d87825f5a/go.mod h1:v2qvRL8Xwk4OlARK6gPlf2JreZXzv0dYp/8+kUJ0y7Q=
|
github.com/joeshaw/gengen v0.0.0-20190604015154-c77d87825f5a/go.mod h1:v2qvRL8Xwk4OlARK6gPlf2JreZXzv0dYp/8+kUJ0y7Q=
|
||||||
github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ=
|
github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ=
|
||||||
github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
|
github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
@ -14,7 +13,6 @@ import (
|
||||||
"github.com/hacdias/indieauth"
|
"github.com/hacdias/indieauth"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"golang.org/x/oauth2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_indieAuthServer(t *testing.T) {
|
func Test_indieAuthServer(t *testing.T) {
|
||||||
|
@ -147,14 +145,7 @@ func Test_indieAuthServer(t *testing.T) {
|
||||||
|
|
||||||
} else if test == 2 {
|
} else if test == 2 {
|
||||||
|
|
||||||
o := iac.GetOAuth2(&authinfo.Endpoints)
|
token, _, err := iac.GetToken(authinfo, code)
|
||||||
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, iac.Client)
|
|
||||||
token, err := o.Exchange(
|
|
||||||
ctx,
|
|
||||||
code,
|
|
||||||
oauth2.SetAuthURLParam("client_id", iac.ClientID),
|
|
||||||
oauth2.SetAuthURLParam("code_verifier", authinfo.CodeVerifier),
|
|
||||||
)
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotNil(t, token)
|
assert.NotNil(t, token)
|
||||||
assert.NotEqual(t, "", token.AccessToken)
|
assert.NotEqual(t, "", token.AccessToken)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user