github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/testing/true_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/values"
    10  	"github.com/MontFerret/ferret/pkg/stdlib/testing"
    11  	"github.com/MontFerret/ferret/pkg/stdlib/testing/base"
    12  )
    13  
    14  func TestTrue(t *t.T) {
    15  	True := base.NewPositiveAssertion(testing.True)
    16  
    17  	Convey("When arg is not passed", t, func() {
    18  		Convey("It should return an error", func() {
    19  			_, err := True(context.Background())
    20  
    21  			So(err, ShouldBeError)
    22  		})
    23  	})
    24  
    25  	Convey("When arg is not boolean", t, func() {
    26  		Convey("It should return an error", func() {
    27  			_, err := True(context.Background(), values.NewString("true"))
    28  
    29  			So(err, ShouldBeError)
    30  			So(err.Error(), ShouldEqual, base.ErrAssertion.Error()+": expected [string] 'true' to be [boolean] 'true'")
    31  		})
    32  	})
    33  
    34  	Convey("When arg is false", t, func() {
    35  		Convey("It should return an error", func() {
    36  			_, err := True(context.Background(), values.False)
    37  
    38  			So(err, ShouldBeError)
    39  			So(err.Error(), ShouldEqual, base.ErrAssertion.Error()+": expected [boolean] 'false' to be [boolean] 'true'")
    40  		})
    41  	})
    42  
    43  	Convey("When arg is true", t, func() {
    44  		Convey("It should not return an error", func() {
    45  			_, err := True(context.Background(), values.True)
    46  
    47  			So(err, ShouldBeNil)
    48  		})
    49  	})
    50  }
    51  
    52  func TestNotTrue(t *t.T) {
    53  	NotTrue := base.NewNegativeAssertion(testing.True)
    54  
    55  	Convey("When arg is not passed", t, func() {
    56  		Convey("It should return an error", func() {
    57  			_, err := NotTrue(context.Background())
    58  
    59  			So(err, ShouldBeError)
    60  		})
    61  	})
    62  
    63  	Convey("When arg is not boolean", t, func() {
    64  		Convey("It should not return an error", func() {
    65  			_, err := NotTrue(context.Background(), values.NewString("true"))
    66  
    67  			So(err, ShouldBeNil)
    68  		})
    69  	})
    70  
    71  	Convey("When arg is true", t, func() {
    72  		Convey("It should return an error", func() {
    73  			_, err := NotTrue(context.Background(), values.True)
    74  
    75  			So(err, ShouldBeError)
    76  			So(err.Error(), ShouldEqual, base.ErrAssertion.Error()+": expected [boolean] 'true' not to be [boolean] 'true'")
    77  		})
    78  	})
    79  
    80  	Convey("When arg is false", t, func() {
    81  		Convey("It should return an error", func() {
    82  			_, err := NotTrue(context.Background(), values.False)
    83  
    84  			So(err, ShouldBeNil)
    85  		})
    86  	})
    87  }