forked from metafates/mangal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
70 lines (61 loc) · 1.4 KB
/
config_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"testing"
)
func TestParseConfig(t *testing.T) {
configString := `
use = ['manganelo']
format = "pdf"
use_custom_reader = false
custom_reader = "zathura"
download_path = '.'
cache_images = false
[ui]
fullscreen = true
prompt = "🔍"
placeholder = "What shall we look for?"
mark = "▼"
title = "Mangal"
[sources]
[sources.manganelo]
base = 'https://ww5.manganelo.tv'
search = 'https://ww5.manganelo.tv/search/%s'
manga_anchor = '.search-story-item a.item-title'
manga_title = '.search-story-item a.item-title'
chapter_anchor = 'li.a-h a.chapter-name'
chapter_title = 'li.a-h a.chapter-name'
reader_page = '.container-chapter-reader img'
random_delay_ms = 500 # ms
reversed_chapters_order = true
`
config, err := ParseConfig(configString)
if err != nil {
t.Fatal(err)
}
conditions := []bool{
config.UI.Fullscreen == true,
config.Path == ".",
config.Scrapers[0].Source.RandomDelayMs == 500,
config.Scrapers[0].Source.MangaTitle == ".search-story-item a.item-title",
}
for _, condition := range conditions {
if !condition {
t.Error()
}
}
}
func TestGetConfig(t *testing.T) {
config := GetConfig("")
if err := ValidateConfig(config); err != nil {
t.Error(err)
}
}
func TestDefaultConfig(t *testing.T) {
config := DefaultConfig()
if config == nil {
t.Fatal("Error while parsing default config file")
}
if err := ValidateConfig(config); err != nil {
t.Error(err)
}
}