github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/testing/lte_test.go (about)

     1  package testing_test
     2  
     3  import (
     4  	"context"
     5  	t "testing"
     6  
     7  	. "github.com/smartystreets/goconvey/convey"
     8  
     9  	"github.com/MontFerret/ferret/pkg/runtime/core"
    10  	"github.com/MontFerret/ferret/pkg/runtime/values"
    11  	"github.com/MontFerret/ferret/pkg/stdlib/testing"
    12  	"github.com/MontFerret/ferret/pkg/stdlib/testing/base"
    13  )
    14  
    15  func TestLte(t *t.T) {
    16  	Lte := base.NewPositiveAssertion(testing.Lte)
    17  
    18  	Convey("When arg is not passed", t, func() {
    19  		Convey("It should return an error", func() {
    20  			_, err := Lte(context.Background())
    21  
    22  			So(err, ShouldBeError)
    23  
    24  			_, err = Lte(context.Background(), values.NewInt(1))
    25  
    26  			So(err, ShouldBeError)
    27  		})
    28  	})
    29  
    30  	Convey("When args are numbers", t, func() {
    31  		Convey("When 2 and 1", func() {
    32  			Convey("It should return an error", func() {
    33  				_, err := Lte(context.Background(), values.NewInt(2), values.NewInt(1))
    34  
    35  				So(err, ShouldBeError)
    36  				So(err.Error(), ShouldEqual, core.Error(base.ErrAssertion, "expected [int] '2' to be less than or equal to [int] '1'").Error())
    37  			})
    38  		})
    39  
    40  		Convey("When 1 and 1", func() {
    41  			Convey("It should not return an error", func() {
    42  				_, err := Lte(context.Background(), values.NewInt(1), values.NewInt(1))
    43  
    44  				So(err, ShouldBeNil)
    45  			})
    46  		})
    47  
    48  		Convey("When 1 and 2", func() {
    49  			Convey("It should not return an error", func() {
    50  				_, err := Lte(context.Background(), values.NewInt(1), values.NewInt(2))
    51  
    52  				So(err, ShouldBeNil)
    53  			})
    54  		})
    55  	})
    56  }
    57  
    58  func TestNotLte(t *t.T) {
    59  	NotLte := base.NewNegativeAssertion(testing.Lte)
    60  
    61  	Convey("When arg is not passed", t, func() {
    62  		Convey("It should return an error", func() {
    63  			_, err := NotLte(context.Background())
    64  
    65  			So(err, ShouldBeError)
    66  
    67  			_, err = NotLte(context.Background(), values.NewInt(1))
    68  
    69  			So(err, ShouldBeError)
    70  		})
    71  	})
    72  
    73  	Convey("When args are numbers", t, func() {
    74  		Convey("When 1 and 2", func() {
    75  			Convey("It should return an error", func() {
    76  				_, err := NotLte(context.Background(), values.NewInt(1), values.NewInt(2))
    77  
    78  				So(err, ShouldBeError)
    79  				So(err.Error(), ShouldEqual, core.Error(base.ErrAssertion, "expected [int] '1' not to be less than or equal to [int] '2'").Error())
    80  			})
    81  		})
    82  
    83  		Convey("When 1 and 1", func() {
    84  			Convey("It should return an error", func() {
    85  				_, err := NotLte(context.Background(), values.NewInt(1), values.NewInt(1))
    86  
    87  				So(err, ShouldBeError)
    88  				So(err.Error(), ShouldEqual, core.Error(base.ErrAssertion, "expected [int] '1' not to be less than or equal to [int] '1'").Error())
    89  			})
    90  		})
    91  
    92  		Convey("When 2 and 1", func() {
    93  			Convey("It should not return an error", func() {
    94  				_, err := NotLte(context.Background(), values.NewInt(2), values.NewInt(1))
    95  
    96  				So(err, ShouldBeNil)
    97  			})
    98  		})
    99  	})
   100  }