github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/html/document_exists_test.go (about)

     1  package html_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/html"
    11  )
    12  
    13  func TestDocumentExists(t *testing.T) {
    14  	Convey("DOCUMENT_EXISTS", t, func() {
    15  		Convey("Should return error if url is not a string", func() {
    16  			_, err := html.DocumentExists(context.Background(), values.None)
    17  
    18  			So(err, ShouldNotBeNil)
    19  		})
    20  
    21  		Convey("Should return error if options is not an object", func() {
    22  			_, err := html.DocumentExists(context.Background(), values.NewString("http://fsdfsdfdsdsf.fdf"), values.None)
    23  
    24  			So(err, ShouldNotBeNil)
    25  		})
    26  
    27  		Convey("Should return error if headers is not an object", func() {
    28  			opts := values.NewObjectWith(values.NewObjectProperty("headers", values.None))
    29  			_, err := html.DocumentExists(context.Background(), values.NewString("http://fsdfsdfdsdsf.fdf"), opts)
    30  
    31  			So(err, ShouldNotBeNil)
    32  		})
    33  
    34  		Convey("Should return 'false' when a website does not exist by a given url", func() {
    35  			out, err := html.DocumentExists(context.Background(), values.NewString("http://fsdfsdfdsdsf.fdf"))
    36  
    37  			So(err, ShouldBeNil)
    38  			So(out, ShouldEqual, values.False)
    39  		})
    40  
    41  		Convey("Should return 'true' when a website exists by a given url", func() {
    42  			out, err := html.DocumentExists(context.Background(), values.NewString("https://www.google.com/"))
    43  
    44  			So(err, ShouldBeNil)
    45  			So(out, ShouldEqual, values.True)
    46  		})
    47  	})
    48  }