Skip to content

Commit

Permalink
v0.11.2
Browse files Browse the repository at this point in the history
- 修复未设置redirect时无法请求的问题
- 修复动画命中存在无法作为文件夹名字符的问题
- 优化部分单元测量mock方式
  • Loading branch information
wetor committed Feb 3, 2024
1 parent d261a39 commit e1a87e4
Show file tree
Hide file tree
Showing 13 changed files with 301 additions and 108 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
- **配置文件版本号为`1.7.1`**
- 更新文档
- 修复设置Mikan的redirect时,RSS订阅中未进行替换的问题
- 修复动画命中存在无法作为文件夹名字符的问题
- 优化配置文件升级代码逻辑

### v0.11.1
- 优化代码,调整项目结构
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ require (
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/subcommands v1.0.1 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hekmon/cunits/v2 v2.1.0 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
Expand All @@ -75,6 +76,7 @@ require (
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.7.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/subcommands v1.0.1 h1:/eqq+otEXm5vhfBrbREPCSVQbvofip6kIz+mX5TUH7k=
github.com/google/subcommands v1.0.1/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
github.com/google/wire v0.5.0 h1:I7ELFeVBr3yfPIcc8+MWvrjk+3VjbcSzoXm3JVa+jD8=
github.com/google/wire v0.5.0/go.mod h1:ngWDr9Qvq3yZA10YrxfyGELY/AFWGVpy9c1LTRi1EoU=
Expand Down Expand Up @@ -347,6 +348,7 @@ golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTk
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs=
golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down
75 changes: 29 additions & 46 deletions internal/animego/anisource/anisource_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package anisource_test

import (
"context"
"fmt"
"io"
"net/url"
"os"
"path"
"sync"
"testing"

Expand All @@ -17,61 +15,23 @@ import (
"github.com/wetor/AnimeGo/internal/animego/anisource/mikan"
"github.com/wetor/AnimeGo/internal/animego/anisource/themoviedb"
"github.com/wetor/AnimeGo/internal/api"
"github.com/wetor/AnimeGo/internal/constant"
"github.com/wetor/AnimeGo/internal/exceptions"
"github.com/wetor/AnimeGo/internal/models"
"github.com/wetor/AnimeGo/internal/pkg/request"
"github.com/wetor/AnimeGo/internal/plugin"
"github.com/wetor/AnimeGo/internal/wire"
"github.com/wetor/AnimeGo/pkg/cache"
"github.com/wetor/AnimeGo/pkg/json"
"github.com/wetor/AnimeGo/pkg/log"
"github.com/wetor/AnimeGo/pkg/utils"
"github.com/wetor/AnimeGo/pkg/xpath"
"github.com/wetor/AnimeGo/test"
)

var (
mikanSource api.AniSource
ctx, cancel = context.WithCancel(context.Background())
)

func HookGetWriter(uri string, w io.Writer) error {
log.Infof("Mock HTTP GET %s", uri)
id := path.Base(xpath.P(uri))
jsonData, err := test.GetData("mikan", id)
if err != nil {
return err
}
_, err = w.Write(jsonData)
if err != nil {
return err
}
return nil
}

func HookGet(uri string, body interface{}) error {
log.Infof("Mock HTTP GET %s", uri)
u, err := url.Parse(uri)
if err != nil {
return err
}
id := u.Query().Get("with_text_query")
if len(id) == 0 {
id = path.Base(xpath.P(u.Path))
}

p := test.GetDataPath("themoviedb", id)
if !utils.IsExist(p) {
p = test.GetDataPath("bangumi", id)
}

jsonData, err := os.ReadFile(p)
if err != nil {
return err
}
_ = json.Unmarshal(jsonData, body)
return nil
}

func TestMain(m *testing.M) {
fmt.Println("begin")
_ = utils.CreateMutiDir("data")
Expand Down Expand Up @@ -104,7 +64,33 @@ func TestMain(m *testing.M) {
Cache: b,
CacheTime: int64(7 * 24 * 60 * 60),
})

bangumiHost := test.MockBangumiStart(ctx)
mikanHost := test.MockMikanStart(ctx)
themoviedbHost := test.MockThemoviedbStart(ctx)
request.Init(&request.Options{
Host: map[string]*request.HostOptions{
constant.BangumiHost: {
Redirect: bangumiHost,
},
constant.MikanHost: {
Redirect: mikanHost,
Cookie: map[string]string{
constant.MikanAuthCookie: "MikanAuthCookie",
},
},
constant.ThemoviedbHost: {
Redirect: themoviedbHost,
Params: map[string]string{
constant.ThemoviedbApiKey: "123456",
},
},
},
})

m.Run()

cancel()
b.Close()
bangumiCache.Close()
_ = log.Close()
Expand Down Expand Up @@ -177,9 +163,6 @@ func TestMikan_Parse(t *testing.T) {
},
}

test.Hook(request.GetWriter, HookGetWriter)
test.Hook(request.Get, HookGet)
defer test.UnHook()
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotAnime, err := mikanSource.Parse(tt.args.opts)
Expand Down
15 changes: 10 additions & 5 deletions internal/animego/anisource/bangumi/bangumi_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bangumi_test

import (
"context"
"fmt"
"os"
"sync"
Expand All @@ -10,6 +11,7 @@ import (
"github.com/stretchr/testify/assert"

"github.com/wetor/AnimeGo/internal/animego/anisource/bangumi"
"github.com/wetor/AnimeGo/internal/constant"
"github.com/wetor/AnimeGo/internal/exceptions"
"github.com/wetor/AnimeGo/internal/pkg/request"
"github.com/wetor/AnimeGo/pkg/cache"
Expand All @@ -18,10 +20,9 @@ import (
"github.com/wetor/AnimeGo/test"
)

const testdata = "bangumi"

var (
bangumiInst *bangumi.Bangumi
ctx, cancel = context.WithCancel(context.Background())
)

func TestMain(m *testing.M) {
Expand All @@ -31,11 +32,14 @@ func TestMain(m *testing.M) {
File: "data/log.log",
Debug: true,
})
host := test.MockBangumiStart(ctx)
request.Init(&request.Options{
Debug: true,
Host: map[string]*request.HostOptions{
constant.BangumiHost: {
Redirect: host,
},
},
})
test.HookAll(testdata, nil)
defer test.UnHook()
mutex := sync.Mutex{}

db := cache.NewBolt()
Expand All @@ -50,6 +54,7 @@ func TestMain(m *testing.M) {
})
m.Run()

cancel()
db.Close()
bangumiCache.Close()
_ = log.Close()
Expand Down
23 changes: 18 additions & 5 deletions internal/animego/anisource/mikan/mikan_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mikan_test

import (
"context"
"fmt"
"os"
"testing"
Expand All @@ -9,16 +10,17 @@ import (
"github.com/stretchr/testify/assert"

"github.com/wetor/AnimeGo/internal/animego/anisource/mikan"
"github.com/wetor/AnimeGo/internal/constant"
"github.com/wetor/AnimeGo/internal/exceptions"
"github.com/wetor/AnimeGo/internal/pkg/request"
"github.com/wetor/AnimeGo/pkg/cache"
"github.com/wetor/AnimeGo/pkg/log"
"github.com/wetor/AnimeGo/test"
)

const testdata = "mikan"

var (
mikanInst *mikan.Mikan
mikanInst *mikan.Mikan
ctx, cancel = context.WithCancel(context.Background())
)

func TestMain(m *testing.M) {
Expand All @@ -27,8 +29,18 @@ func TestMain(m *testing.M) {
File: "data/test.log",
Debug: true,
})
test.HookAll(testdata, nil)
defer test.UnHook()

host := test.MockMikanStart(ctx)
request.Init(&request.Options{
Host: map[string]*request.HostOptions{
constant.MikanHost: {
Redirect: host,
Cookie: map[string]string{
constant.MikanAuthCookie: "MikanAuthCookie",
},
},
},
})

db := cache.NewBolt()
db.Open("data/bolt.db")
Expand All @@ -38,6 +50,7 @@ func TestMain(m *testing.M) {
})
m.Run()

cancel()
db.Close()
_ = log.Close()
_ = os.RemoveAll("data")
Expand Down
33 changes: 14 additions & 19 deletions internal/animego/anisource/themoviedb/themoviedb_test.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
package themoviedb_test

import (
"context"
"fmt"
"net/url"
"os"
"path"
"testing"

"github.com/pkg/errors"
"github.com/stretchr/testify/assert"

"github.com/wetor/AnimeGo/internal/animego/anisource/themoviedb"
"github.com/wetor/AnimeGo/internal/constant"
"github.com/wetor/AnimeGo/internal/exceptions"
"github.com/wetor/AnimeGo/internal/pkg/request"
"github.com/wetor/AnimeGo/pkg/cache"
"github.com/wetor/AnimeGo/pkg/log"
"github.com/wetor/AnimeGo/pkg/xpath"
"github.com/wetor/AnimeGo/test"
)

const testdata = "themoviedb"

var (
tmdbInst *themoviedb.Themoviedb
tmdbInst *themoviedb.Themoviedb
ctx, cancel = context.WithCancel(context.Background())
)

func TestMain(m *testing.M) {
Expand All @@ -36,23 +34,20 @@ func TestMain(m *testing.M) {
tmdbInst = themoviedb.NewThemoviedb(&themoviedb.Options{
Cache: db,
})
host := test.MockThemoviedbStart(ctx)
request.Init(&request.Options{
Debug: true,
})
test.HookGet(testdata, func(uri string) string {
u, err := url.Parse(uri)
if err != nil {
return ""
}
id := u.Query().Get("with_text_query")
if len(id) == 0 {
id = path.Base(xpath.P(u.Path))
}
return id
Host: map[string]*request.HostOptions{
constant.ThemoviedbHost: {
Redirect: host,
Params: map[string]string{
constant.ThemoviedbApiKey: "123456",
},
},
},
})
defer test.UnHook()
m.Run()

cancel()
db.Close()
_ = log.Close()
_ = os.RemoveAll("data")
Expand Down
Loading

0 comments on commit e1a87e4

Please sign in to comment.