Skip to content

A package that helps you test skipper `.eskip` files routing matching logic

License

Notifications You must be signed in to change notification settings

rbarilani/eskip-match

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

92 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status codecov Go Report Card GoDoc git tag

eskip-match

A package that helps you test skipper .eskip files routing matching logic.

Install

go get github.com/rbarilani/eskip-match/...

Usage

Given an .eskip file:

routes.eskip

foo: Path("/foo") -> http://foo.com
bar: Path("/bar") -> http://bar.com

You can write a go test able to check if the matching logic is what you expect. A simple example:

main_test.go

package main

import (
	"testing"

	"github.com/rbarilani/eskip-match/matcher"
)

func TestExample(t *testing.T) {
	m, err := matcher.New(&matcher.Options{
		RoutesFile: "./routes.eskip",
	})

	if err != nil {
		t.Fatal(err)
		return
	}

	res := m.Test(&matcher.RequestAttributes{
		Method: "GET",
		Path:   "/bar",
	})

	route := res.Route()

	if route == nil {
		t.Error("Expect matching but no match")
		return
	}
	if route.Id != "bar" {
		t.Errorf("Expect matching route: %s but got %s", "bar", route.Id)
	}
}

CLI

The package provide a binary cli tool: eskip-match

NAME:
   eskip-match - A command line tool that helps you test .eskip files routing matching logic

USAGE:
   eskip-match [global options] command [command options] [arguments...]

COMMANDS:
     test, t  Given a routes file and request attributes, checks a route matches
     help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --config FILE, -c FILE  Load configuration from FILE
   --help, -h              show help
   --version, -v           print the version

Commands

Test

With eskip-match test command you can check if a route matches given specific request attributes.

Examples

Test if a request to path /foo matches a route:

eskip-match test routes.eskip -p /foo

Test if a request to path /foo using GET method matches a route:

eskip-match test routes.eskip -p /foo -m GET

Specifying headers:

eskip-match test routes.eskip -p /foo -H Accept=application/json -H Authorization="Bearer XXX"

Using verbose output might help when something doesn't seem to work as expected:

eskip-match test routes.eskip -v -p /foo

If your routes are using custom filters the tool must be informed via a configuration file named .eskip-match.yml, eg:

.eskip-match.yml

customfilters:
  - myCustomFilter1
  - myCustomFilter2
eskip-match test routes.eskip -p /foo

By default the tool will try to load .eskip-match.yml in the current working directory, but you can provide a custom location with -c global option, eg:

eskip-match -c config.yml test routes.eskip -p /foo

License

Copyright 2018 Ruben Barilani

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

A package that helps you test skipper `.eskip` files routing matching logic

Resources

License

Stars

Watchers

Forks

Packages

No packages published