...

Package testutils

Overview ▾

Variables

Errors.

var (
    ErrRenderNotSupported = errors.New("rendering PDF files is not supported on this system")
    ErrImageSizeNotMatch  = errors.New("image sizes don't match")
)

func CombinePNGFiles

func CombinePNGFiles(file1, file2 string) (bool, error)

CombinePNGFiles combines the specified PNG files.

func CompareImages

func CompareImages(img1, img2 image.Image) (bool, error)

CompareImages compares the specified images at pixel level.

func ComparePNGFiles

func ComparePNGFiles(file1, file2 string) (bool, error)

ComparePNGFiles compares the specified PNG files.

func CopyFile

func CopyFile(src, dst string) error

CopyFile copies the `src` file to `dst`.

func CreatePNGDiff

func CreatePNGDiff(src, dst string) (bool, string, float64, float64, error)

CreatePNGDiff creates image differences and returns differences percentage and total.

func HashFile

func HashFile(file string) (string, error)

HashFile generates an MD5 hash from the contents of the specified file.

func ReadPNG

func ReadPNG(file string) (image.Image, error)

ReadPNG reads and returns the specified PNG file.

func RenderPDFToPNGs

func RenderPDFToPNGs(pdfPath string, dpi int, outpathTpl string) error

RenderPDFToPNGs uses ghostscript (gs) to render the specified PDF file into a set of PNG images (one per page). PNG images will be named xxx-N.png where N is the number of page, starting from 1.

func RunRenderOfficeTest

func RunRenderOfficeTest(t *testing.T, pdfPath, outputDir, baselineRenderPath string,
    saveBaseline bool, currentHashMap *ReferenceMap, refFile *ReferenceFile, postfix string)

RunRenderOfficeTest renders the PDF file specified by `pdfPath` to the `outputDir` and compares the output PNG files to the reference files found at the `baselineRenderPath` location. If the specified PDF file is new (there are no reference files) and the `saveBaseline` parameter is set to true, the output render files are saved to the `baselineRenderPath`.

func RunRenderTest

func RunRenderTest(t *testing.T, pdfPath, outputDir, baselineRenderPath string,
    saveBaseline bool, currentHashMap *ReferenceMap, refFile *ReferenceFile)

RunRenderTest renders the PDF file specified by `pdfPath` to the `outputDir` and compares the output PNG files to the reference files found at the `baselineRenderPath` location. If the specified PDF file is new (there are no reference files) and the `saveBaseline` parameter is set to true, the output render files are saved to the `baselineRenderPath`. RunRenderTest is intended for converted from Word documents PDF files

type ReferenceEntry

ReferenceEntry is the reference file single entry.

type ReferenceEntry struct {
    Timestamp   int64   `json:"timestamp"`
    Value       string  `json:"value"`
    ResultSize  int64   `json:"resultSize,omitempty"`
    DiffPercent float64 `json:"diffPercent,omitempty"`
    DiffTotal   float64 `json:"diffValue,omitempty"`
    Invalid     bool    `json:"markedInvalid,omitempty"`
}

type ReferenceFile

ReferenceFile represents the reference file hash map.

type ReferenceFile struct {
    Timestamp time.Time     `json:"timestamp"`
    Map       *ReferenceMap `json:"map,omitempty"`
    // contains filtered or unexported fields
}

func ReadFile

func ReadFile(dirPath, testName string, createEmpty bool) (*ReferenceFile, error)

ReadFile reads the reference file map stored at the 'path'. The 'createEmpty' flag creates empty file if there is no reference stored at provided 'path'.

func (*ReferenceFile) Update

func (f *ReferenceFile) Update(currentMap *ReferenceMap) error

Update updates given reference file.

type ReferenceMap

Map is the reference file map

type ReferenceMap struct {
    sync.Mutex
    // contains filtered or unexported fields
}

func (*ReferenceMap) Copy

func (m *ReferenceMap) Copy() *ReferenceMap

Copy creates a copy of given reference file map.

func (*ReferenceMap) Keys

func (m *ReferenceMap) Keys() (keys []string)

Keys gets the keys of given map.

func (*ReferenceMap) Len

func (m *ReferenceMap) Len() int

Len returns the length of given map.

func (*ReferenceMap) MarshalJSON

func (m *ReferenceMap) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (*ReferenceMap) Read

func (m *ReferenceMap) Read(key string) (ReferenceEntry, bool)

func (*ReferenceMap) UnmarshalJSON

func (m *ReferenceMap) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface.

func (*ReferenceMap) Write

func (m *ReferenceMap) Write(key string, entry ReferenceEntry)

Write write new entry for given key value.