github.com/MontFerret/ferret@v0.18.0/pkg/drivers/cdp/options_test.go (about)

     1  package cdp_test
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	. "github.com/smartystreets/goconvey/convey"
     8  
     9  	"github.com/MontFerret/ferret/pkg/drivers"
    10  	"github.com/MontFerret/ferret/pkg/drivers/cdp"
    11  )
    12  
    13  func TestNewOptions(t *testing.T) {
    14  	Convey("Should create driver options with initial values", t, func() {
    15  		opts := cdp.NewOptions([]cdp.Option{})
    16  		So(opts.Options, ShouldNotBeNil)
    17  		So(opts.Name, ShouldEqual, cdp.DriverName)
    18  		So(opts.Address, ShouldEqual, cdp.DefaultAddress)
    19  	})
    20  
    21  	Convey("Should use setters to set values", t, func() {
    22  		expectedName := cdp.DriverName + "2"
    23  		expectedAddress := "0.0.0.0:9222"
    24  		expectedUA := "Mozilla"
    25  		expectedProxy := "https://proxy.com"
    26  
    27  		opts := cdp.NewOptions([]cdp.Option{
    28  			cdp.WithCustomName(expectedName),
    29  			cdp.WithAddress(expectedAddress),
    30  			cdp.WithUserAgent(expectedUA),
    31  			cdp.WithProxy(expectedProxy),
    32  			cdp.WithKeepCookies(),
    33  			cdp.WithCookie(drivers.HTTPCookie{
    34  				Name:     "Session",
    35  				Value:    "fsdfsdfs",
    36  				Path:     "dfsdfsd",
    37  				Domain:   "sfdsfs",
    38  				Expires:  time.Time{},
    39  				MaxAge:   0,
    40  				Secure:   false,
    41  				HTTPOnly: false,
    42  				SameSite: 0,
    43  			}),
    44  			cdp.WithCookies([]drivers.HTTPCookie{
    45  				{
    46  					Name:     "Use",
    47  					Value:    "Foos",
    48  					Path:     "",
    49  					Domain:   "",
    50  					Expires:  time.Time{},
    51  					MaxAge:   0,
    52  					Secure:   false,
    53  					HTTPOnly: false,
    54  					SameSite: 0,
    55  				},
    56  			}),
    57  			cdp.WithHeader("Authorization", []string{"Bearer dfsd7f98sd9fsd9fsd"}),
    58  			cdp.WithHeaders(drivers.NewHTTPHeadersWith(map[string][]string{
    59  				"x-correlation-id": {"232483833833839"},
    60  			})),
    61  		})
    62  		So(opts.Options, ShouldNotBeNil)
    63  		So(opts.Name, ShouldEqual, expectedName)
    64  		So(opts.Address, ShouldEqual, expectedAddress)
    65  		So(opts.UserAgent, ShouldEqual, expectedUA)
    66  		So(opts.Proxy, ShouldEqual, expectedProxy)
    67  		So(opts.KeepCookies, ShouldBeTrue)
    68  		So(opts.Cookies.Length(), ShouldEqual, 2)
    69  		So(opts.Headers.Length(), ShouldEqual, 2)
    70  	})
    71  }