@@ -2,59 +2,24 @@ package configs_test
22
33import (
44 "bytes"
5- "fmt"
65 "github.com/wetor/AnimeGo/pkg/utils"
76 "os"
87 "testing"
98
10- "github.com/jinzhu/copier"
11-
129 "github.com/wetor/AnimeGo/configs"
13- "github.com/wetor/AnimeGo/internal/models"
1410)
1511
16- func TestDefaultConfig ( t * testing.T ) {
12+ func TestMain ( m * testing.M ) {
1713 _ = utils .CreateMutiDir ("data" )
18- _ = configs .DefaultFile ("data/animego_default.yaml" )
14+ m .Run ()
15+ _ = os .RemoveAll ("data" )
1916}
2017
21- func TestCopy (t * testing.T ) {
22- type s1 struct {
23- A int
24- B struct {
25- C string
26- D bool
27- }
28- }
29-
30- type s2 struct {
31- C string
32- B struct {
33- A int
34- D bool
35- E string
36- }
37- }
38-
39- ss1 := s1 {
40- A : 10 ,
41- B : struct {
42- C string
43- D bool
44- }{C : "测试" , D : true },
45- }
46-
47- ss2 := s2 {}
48- err := copier .Copy (& ss2 , & ss1 )
49- if err != nil {
50- panic (err )
51- }
52- fmt .Println (ss1 )
53- fmt .Println (ss2 )
18+ func TestDefaultConfig (t * testing.T ) {
19+ _ = configs .DefaultFile ("data/animego_default.yaml" )
5420}
5521
5622func TestUpdateConfig_120 (t * testing.T ) {
57- _ = utils .CreateMutiDir ("data" )
5823 configs .ConfigVersion = "1.2.0"
5924 file , _ := os .ReadFile ("testdata/animego_110.yaml" )
6025 _ = os .WriteFile ("data/animego.yaml" , file , 0666 )
@@ -65,13 +30,11 @@ func TestUpdateConfig_120(t *testing.T) {
6530 if ! bytes .Equal (got , want ) {
6631 t .Errorf ("UpdateConfig() = %s, want %s" , got , want )
6732 }
68- _ = os .Remove ("data/animego.yaml" )
6933}
7034
7135func TestUpdateConfig_130 (t * testing.T ) {
72- _ = utils .CreateMutiDir ("data" )
7336 configs .ConfigVersion = "1.3.0"
74- file , _ := os .ReadFile ("testdata/animego_120_2 .yaml" )
37+ file , _ := os .ReadFile ("testdata/animego_120 .yaml" )
7538 _ = os .WriteFile ("data/animego.yaml" , file , 0666 )
7639 configs .UpdateConfig ("data/animego.yaml" , false )
7740
@@ -80,11 +43,9 @@ func TestUpdateConfig_130(t *testing.T) {
8043 if ! bytes .Equal (got , want ) {
8144 t .Errorf ("UpdateConfig() = %s, want %s" , got , want )
8245 }
83- _ = os .Remove ("data/animego.yaml" )
8446}
8547
8648func TestUpdateConfig_140 (t * testing.T ) {
87- _ = utils .CreateMutiDir ("data" )
8849 configs .ConfigVersion = "1.4.0"
8950 file , _ := os .ReadFile ("testdata/animego_130.yaml" )
9051 _ = os .WriteFile ("data/animego.yaml" , file , 0666 )
@@ -95,56 +56,4 @@ func TestUpdateConfig_140(t *testing.T) {
9556 if ! bytes .Equal (got , want ) {
9657 t .Errorf ("UpdateConfig() = %s, want %s" , got , want )
9758 }
98- //_ = os.Remove("data/animego.yaml")
99- }
100-
101- func TestConvertPluginInfo (t * testing.T ) {
102-
103- plugins := configs .ConvertPluginInfo ([]configs.PluginInfo {
104- {
105- Enable : true ,
106- Type : "python" ,
107- File : "/aaa" ,
108- Args : map [string ]any {
109- "Cron" : "1111" ,
110- "Retry" : 77 ,
111- },
112- },
113- {
114- Enable : true ,
115- Type : "python" ,
116- File : "/aaa" ,
117- Args : map [string ]any {
118- "Cron" : "777888" ,
119- "Retry" : 13 ,
120- },
121- },
122- })
123- fmt .Println (plugins )
124- }
125-
126- func TestCopy1 (t * testing.T ) {
127- plugins := []* configs.PluginInfo {
128- {
129- Enable : true ,
130- Type : "python" ,
131- File : "/aaa" ,
132- Args : map [string ]any {
133- "Cron" : "1111" ,
134- "Retry" : 77 ,
135- },
136- },
137- {
138- Enable : true ,
139- Type : "python" ,
140- File : "/aaa" ,
141- Args : map [string ]any {
142- "Cron" : "777888" ,
143- "Retry" : 13 ,
144- },
145- },
146- }
147- dst := make ([]* models.Plugin , len (plugins ))
148- copier .Copy (& dst , & plugins )
149- fmt .Println (dst )
15059}
0 commit comments