github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/path/match_test.go (about)

     1  package path_test
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	. "github.com/smartystreets/goconvey/convey"
     8  
     9  	"github.com/MontFerret/ferret/pkg/runtime/values"
    10  	"github.com/MontFerret/ferret/pkg/stdlib/path"
    11  )
    12  
    13  func TestMatch(t *testing.T) {
    14  	Convey("When arg is not passed", t, func() {
    15  		Convey("It should return an error", func() {
    16  			_, err := path.Match(context.Background())
    17  
    18  			So(err, ShouldBeError)
    19  		})
    20  	})
    21  
    22  	Convey("First argument is wrong", t, func() {
    23  		var err error
    24  		_, err = path.Match(context.Background(), values.NewInt(0), values.NewString("/"))
    25  
    26  		So(err, ShouldBeError)
    27  	})
    28  
    29  	Convey("Second argument is wrong", t, func() {
    30  		var err error
    31  		_, err = path.Match(context.Background(), values.NewString("/"), values.NewInt(0))
    32  
    33  		So(err, ShouldBeError)
    34  	})
    35  
    36  	Convey("Match('http://site.com/*.csv', 'http://site.com/goods.csv') should return true", t, func() {
    37  		out, _ := path.Match(
    38  			context.Background(),
    39  			values.NewString("http://site.com/*.csv"), values.NewString("http://site.com/goods.csv"),
    40  		)
    41  
    42  		So(out, ShouldEqual, values.True)
    43  	})
    44  
    45  	Convey("Match('ferret*/ferret', 'ferret/bin/ferret') should return false", t, func() {
    46  		out, _ := path.Match(
    47  			context.Background(),
    48  			values.NewString("ferret*/ferret"), values.NewString("ferret/bin/ferret"),
    49  		)
    50  
    51  		So(out, ShouldEqual, values.False)
    52  	})
    53  
    54  	Convey("Match('[x-]', 'x') should return ad error", t, func() {
    55  		_, err := path.Match(
    56  			context.Background(),
    57  			values.NewString("[x-]"), values.NewString("x"),
    58  		)
    59  
    60  		So(err, ShouldBeError)
    61  	})
    62  }