mirror of
https://github.com/tnypxl/rollup.git
synced 2025-12-15 15:03:17 +00:00
test: refactor TestScrapeURL to use local mock functions
This commit is contained in:
@@ -7,10 +7,6 @@ import (
|
|||||||
"github.com/tnypxl/rollup/internal/scraper"
|
"github.com/tnypxl/rollup/internal/scraper"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
extractAndConvertContent func(string) (string, error)
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestConvertPathOverrides(t *testing.T) {
|
func TestConvertPathOverrides(t *testing.T) {
|
||||||
configOverrides := []config.PathOverride{
|
configOverrides := []config.PathOverride{
|
||||||
{
|
{
|
||||||
@@ -100,16 +96,28 @@ func mockExtractLinks(urlStr string) ([]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestScrapeURL(t *testing.T) {
|
func TestScrapeURL(t *testing.T) {
|
||||||
|
// Store the original functions
|
||||||
|
originalExtractAndConvertContent := extractAndConvertContent
|
||||||
|
originalExtractLinks := scraper.ExtractLinks
|
||||||
|
|
||||||
|
// Define mock functions
|
||||||
|
mockExtractAndConvertContent := func(urlStr string) (string, error) {
|
||||||
|
return "Mocked content for " + urlStr, nil
|
||||||
|
}
|
||||||
|
mockExtractLinks := func(urlStr string) ([]string, error) {
|
||||||
|
return []string{"http://example.com/link1", "http://example.com/link2"}, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Replace the actual functions with mocks
|
// Replace the actual functions with mocks
|
||||||
oldExtractAndConvertContent := extractAndConvertContent
|
|
||||||
oldExtractLinks := scraper.ExtractLinks
|
|
||||||
defer func() {
|
|
||||||
extractAndConvertContent = oldExtractAndConvertContent
|
|
||||||
scraper.ExtractLinks = oldExtractLinks
|
|
||||||
}()
|
|
||||||
extractAndConvertContent = mockExtractAndConvertContent
|
extractAndConvertContent = mockExtractAndConvertContent
|
||||||
scraper.ExtractLinks = mockExtractLinks
|
scraper.ExtractLinks = mockExtractLinks
|
||||||
|
|
||||||
|
// Defer the restoration of original functions
|
||||||
|
defer func() {
|
||||||
|
extractAndConvertContent = originalExtractAndConvertContent
|
||||||
|
scraper.ExtractLinks = originalExtractLinks
|
||||||
|
}()
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
url string
|
url string
|
||||||
depth int
|
depth int
|
||||||
|
|||||||
Reference in New Issue
Block a user