assertxml

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2020 License: MIT Imports: 6 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.T) {
    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 *testing.T, filename string, xmlAssert XMLAssertFunc)

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

func Has

func Has(t *testing.T, 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.

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