assertxml

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package assertxml provides methods for testing XML values. Selecting XML values provided by XML Path Syntax.

Example usage

import (
    "net/http"
    "net/http/httptest"
    "testing"
    "github.com/muonsoft/api-testing/assertxml"
 )

 func TestYourAPI(t testing.TB) {
    recorder := httptest.NewRecorder()
    handler := createHTTPHandler()

    request, _ := http.NewRequest("GET", "/content", nil)
    handler.ServeHTTP(recorder, request)

    assertxml.Has(t, recorder.Body.Bytes(), func(xml *AssertXML) {
        // common assertions
        xml.Node("/root/stringNode").Exists()
        xml.Node("/root/notExistingNode").DoesNotExist()

        // string assertions
        xml.Node("/root/stringNode").EqualToTheString("stringValue")
    })
 }

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileHas

func FileHas(t TestingT, filename string, xmlAssert XMLAssertFunc)

FileHas loads XML from file and runs user callback for testing its nodes.

func Has

func Has(t TestingT, data []byte, xmlAssert XMLAssertFunc)

Has loads XML from byte slice and runs user callback for testing its nodes.

Types

type AssertNode

type AssertNode struct {
	// contains filtered or unexported fields
}

AssertNode - structure for asserting XML node.

func (*AssertNode) DoesNotExist

func (node *AssertNode) DoesNotExist(msgAndArgs ...interface{})

DoesNotExist asserts that the XML node does not exist.

func (*AssertNode) EqualToTheString

func (node *AssertNode) EqualToTheString(expectedValue string, msgAndArgs ...interface{})

EqualToTheString asserts that the XML node has a string value equals to the given value.

func (*AssertNode) Exists

func (node *AssertNode) Exists(msgAndArgs ...interface{})

Exists asserts that the XML node exists.

type AssertXML

type AssertXML struct {
	// contains filtered or unexported fields
}

AssertXML - main structure that holds parsed XML.

func (*AssertXML) Node

func (x *AssertXML) Node(path string) *AssertNode

Node searches for XML node by XML Path Syntax. Returns struct for asserting the node values.

func (*AssertXML) Nodef added in v0.3.0

func (x *AssertXML) Nodef(format string, a ...interface{}) *AssertNode

Nodef searches for XML node by XML Path Syntax. Returns struct for asserting the node values. It calculates path by applying fmt.Sprintf function.

type TestingT added in v0.8.0

type TestingT interface {
	Helper()
	Error(args ...interface{})
	Errorf(format string, args ...interface{})
	Log(args ...interface{})
}

TestingT is an interface wrapper around *testing.T.

type XMLAssertFunc

type XMLAssertFunc func(xml *AssertXML)

XMLAssertFunc - callback function used for asserting XML nodes.

Jump to

Keyboard shortcuts

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