-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(case): add test for modify task config proxy function
- Loading branch information
黄崇正
committed
Jun 9, 2022
1 parent
852cbd2
commit b97a82a
Showing
3 changed files
with
50 additions
and
8 deletions.
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
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,45 @@ | ||
package pkg_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/Qianlitp/crawlergo/pkg" | ||
"github.com/Qianlitp/crawlergo/pkg/config" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestTaskConfigOptFunc(t *testing.T) { | ||
// 测试 https://github.com/Qianlitp/crawlergo/pull/101 修改的代码 | ||
var taskConf pkg.TaskConfig | ||
for _, fn := range []pkg.TaskConfigOptFunc{ | ||
pkg.WithTabRunTimeout(config.TabRunTimeout), | ||
pkg.WithMaxTabsCount(config.MaxTabsCount), | ||
pkg.WithMaxCrawlCount(config.MaxCrawlCount), | ||
pkg.WithDomContentLoadedTimeout(config.DomContentLoadedTimeout), | ||
pkg.WithEventTriggerInterval(config.EventTriggerInterval), | ||
pkg.WithBeforeExitDelay(config.BeforeExitDelay), | ||
pkg.WithEventTriggerMode(config.DefaultEventTriggerMode), | ||
pkg.WithIgnoreKeywords(config.DefaultIgnoreKeywords), | ||
} { | ||
fn(&taskConf) | ||
} | ||
|
||
// 应该都要等于默认配置 | ||
assert.Equal(t, taskConf.TabRunTimeout, config.TabRunTimeout) | ||
assert.Equal(t, taskConf.MaxTabsCount, config.MaxTabsCount) | ||
assert.Equal(t, taskConf.MaxCrawlCount, config.MaxCrawlCount) | ||
assert.Equal(t, taskConf.DomContentLoadedTimeout, config.DomContentLoadedTimeout) | ||
assert.Equal(t, taskConf.EventTriggerInterval, config.EventTriggerInterval) | ||
assert.Equal(t, taskConf.BeforeExitDelay, config.BeforeExitDelay) | ||
assert.Equal(t, taskConf.EventTriggerMode, config.DefaultEventTriggerMode) | ||
assert.Equal(t, taskConf.IgnoreKeywords, config.DefaultIgnoreKeywords) | ||
|
||
// 重设超时时间 | ||
taskConf.TabRunTimeout = time.Minute * 5 | ||
|
||
// 企图覆盖自定义的时间, 不应该允许, 程序初始化时只能配置一次, 先由用户配置 | ||
pkg.WithTabRunTimeout(time.Second * 5)(&taskConf) | ||
assert.NotEqual(t, taskConf.TabRunTimeout, time.Second*5) | ||
assert.NotEqual(t, taskConf.TabRunTimeout, config.TabRunTimeout) | ||
} |