testutils

package
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TestCases = []TestCase{
	{
		Name:     "Standard Mode Crawl",
		Target:   "",
		Args:     "-depth 2 -silent",
		Expected: nil,
		CompareFunc: func(target string, got []string) error {
			if len(got) < 3 {
				return errkit.Newf("expected at least 3 URLs, got %d: %v", len(got), got)
			}
			expectedPaths := []string{"/about", "/contact", "/blog"}
			for _, path := range expectedPaths {
				found := false
				for _, u := range got {
					if strings.Contains(u, path) {
						found = true
						break
					}
				}
				if !found {
					return errkit.Newf("expected %s in output, got: %s", path, strings.Join(got, "\n"))
				}
			}
			return nil
		},
	},
	{
		Name:     "Standard Mode Depth 3",
		Target:   "",
		Args:     "-depth 3 -silent",
		Expected: nil,
		CompareFunc: func(target string, got []string) error {
			expectedPaths := []string{"/blog/post-1", "/blog/post-2", "/team"}
			for _, path := range expectedPaths {
				found := false
				for _, u := range got {
					if strings.Contains(u, path) {
						found = true
						break
					}
				}
				if !found {
					return errkit.Newf("depth 3 should discover %s, got: %s", path, strings.Join(got, "\n"))
				}
			}
			return nil
		},
	},
	{
		Name:     "Headless Browser Crawl",
		Target:   "",
		Args:     "-headless -no-incognito -depth 2 -silent -no-sandbox",
		Expected: nil,
		CompareFunc: func(target string, got []string) error {
			if len(got) < 2 {
				return errkit.Newf("expected at least 2 URLs in headless mode, got %d: %v", len(got), got)
			}
			for _, res := range got {
				if strings.Contains(res, target) {
					return nil
				}
			}
			return errkit.Newf("expected %v target in output, but got %v", target, strings.Join(got, "\n"))
		},
	},
}

Functions

func CompareOutput

func CompareOutput(input, expected []string) bool

func RunKatanaBinaryAndGetResults

func RunKatanaBinaryAndGetResults(target string, katanaBinary string, debug bool, args []string) ([]string, error)

Types

type TestCase

type TestCase struct {
	Name        string
	Target      string
	Args        string
	Expected    []string
	CompareFunc func(target string, got []string) error
}

type TestServer added in v1.6.0

type TestServer struct {
	URL string
	// contains filtered or unexported fields
}

TestServer is a local HTTP server for functional tests.

func NewTestServer added in v1.6.0

func NewTestServer() (*TestServer, error)

NewTestServer starts a local HTTP server on a random port with a small site structure suitable for crawl testing.

func (*TestServer) Close added in v1.6.0

func (ts *TestServer) Close() error

Close shuts down the test server.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL