json

package
v0.8.6 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: MIT Imports: 5 Imported by: 0

README

JSON utilities for godog test suits

Implements a matcher for JSON encoded structures.

Usage Example:

Feature:

Feature: It should be posible to create and retreive users from the service
    
    Scenario: If should be possible to create a user
        When given the following json dump:
        """
            {"key-0" : "value", "key-1" : {"key-key-1": ["value-0", "value-1"]}}
        """
        Then the path ".key-1.key-key-1[1]" should match "value-1"

Backing code:

import (
    "strings"
    "github.com/DATA-DOG/godog"
    "github.com/DATA-DOG/godog/gherkin"
    "github.com/SKF/go-tests-utility/api/godog/json"
)

type state struct {
    dump []byte
}

func (st *state) setJsonDump(input *gherkin.DocString) error {
    st.dump = []byte(strings.TrimSpace(input.Content))
    return nil
}

func (st *state) matchJson(key, pattern string) error {
    return Match(st.dump, key, pattern)
}

func FeatureContext(s *godog.Suite) {
    st := state{}
    s.Step(`^given the following json dump:$`, st.setJsonDump)
    s.Step(`^the path "([^"]*)" should match "([^"]*)"$`, st.matchJson)
}
    

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayLen

func ArrayLen(json []byte, path string, length int) error

func KeyIsMissing added in v0.2.3

func KeyIsMissing(json []byte, path string) error

func KeyIsPresent added in v0.8.0

func KeyIsPresent(json []byte, path string) error

func Match

func Match(json []byte, path string, pattern string) error

func MatchNull

func MatchNull(json []byte, path string) error

func Read

func Read(json []byte, path string) (result string, err error)

func ReadStringArr

func ReadStringArr(json []byte, path string) (result []string, err error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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