expect.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. // Package httpexpect helps with end-to-end HTTP and REST API testing.
  2. //
  3. // # Usage examples
  4. //
  5. // See example directory:
  6. // - https://github.com/kataras/iris/tree/master/_examples
  7. //
  8. // # Communication mode
  9. //
  10. // There are two common ways to test API with httpexpect:
  11. // - start HTTP server and instruct httpexpect to use HTTP client for communication
  12. // - don't start server and instruct httpexpect to invoke http handler directly
  13. //
  14. // The second approach works only if the server is a Go module and its handler can
  15. // be imported in tests.
  16. //
  17. // Concrete behaviour is determined by Client implementation passed to Config struct.
  18. // If you're using http.Client, set its Transport field (http.RoundTriper) to one of
  19. // the following:
  20. // 1. default (nil) - use HTTP transport from net/http (you should start server)
  21. // 2. httpexpect.Binder - invoke given http.Handler directly
  22. //
  23. // Note that http handler can be usually obtained from http framework you're using.
  24. // E.g., echo framework provides either http.Handler.
  25. //
  26. // You can also provide your own implementation of RequestFactory (creates http.Request),
  27. // or Client (gets http.Request and returns http.Response).
  28. //
  29. // If you're starting server from tests, it's very handy to use net/http/httptest.
  30. //
  31. // # Value equality
  32. //
  33. // Whenever values are checked for equality in httpexpect, they are converted
  34. // to "canonical form":
  35. // - structs are converted to map[string]interface{}
  36. // - type aliases are removed
  37. // - numeric types are converted to float64
  38. // - non-nil interfaces pointing to nil slices and maps are replaced with
  39. // nil interfaces
  40. //
  41. // This is equivalent to subsequently json.Marshal() and json.Unmarshal() the value
  42. // and currently is implemented so.
  43. //
  44. // # Failure handling
  45. //
  46. // When some check fails, failure is reported. If non-fatal failures are used
  47. // (see Reporter interface), execution is continued and instance that was checked
  48. // is marked as failed.
  49. //
  50. // If specific instance is marked as failed, all subsequent checks are ignored
  51. // for this instance and for any child instances retrieved after failure.
  52. //
  53. // Example:
  54. //
  55. // array := NewArray(NewAssertReporter(t), []interface{}{"foo", 123})
  56. //
  57. // e0 := array.Value(0) // success
  58. // e1 := array.Value(1) // success
  59. //
  60. // s0 := e0.String() // success
  61. // s1 := e1.String() // failure; e1 and s1 are marked as failed, e0 and s0 are not
  62. //
  63. // s0.IsEqual("foo") // success
  64. // s1.IsEqual("bar") // this check is ignored because s1 is marked as failed
  65. //
  66. // # Assertion handling
  67. //
  68. // If you want to be informed about every asserion made, successful or failed, you
  69. // can use AssertionHandler interface.
  70. //
  71. // Default implementation of this interface ignores successful assertions and reports
  72. // failed assertions using Formatter and Reporter objects.
  73. //
  74. // Custom AssertionHandler can handle all assertions (e.g. dump them in JSON format)
  75. // and is free to use or not to use Formatter and Reporter in its sole discretion.
  76. package httpexpect
  77. import (
  78. "context"
  79. "io"
  80. "net/http"
  81. "github.com/gorilla/websocket"
  82. )
  83. // Expect is a toplevel object that contains user Config and allows
  84. // to construct Request objects.
  85. type Expect struct {
  86. noCopy noCopy
  87. config Config
  88. chain *chain
  89. builders []func(*Request)
  90. matchers []func(*Response)
  91. }
  92. // Config contains various settings.
  93. type Config struct {
  94. // TestName defines the name of the currently running test.
  95. // May be empty.
  96. //
  97. // If non-empty, it will be included in failure report.
  98. // Normally you set this value to t.Name().
  99. TestName string
  100. // BaseURL is a URL to prepended to all requests.
  101. // May be empty.
  102. //
  103. // If non-empty, trailing slash is allowed (but not required) and is appended
  104. // automatically.
  105. BaseURL string
  106. // RequestFactory is used to pass in a custom *http.Request generation func.
  107. // May be nil.
  108. //
  109. // If nil, DefaultRequestFactory is used, which just calls http.NewRequest.
  110. //
  111. // You can use DefaultRequestFactory, or provide custom implementation.
  112. // Useful for Google App Engine testing for example.
  113. RequestFactory RequestFactory
  114. // Client is used to send http.Request and receive http.Response.
  115. // May be nil.
  116. //
  117. // If nil, set to a default client with a non-nil Jar:
  118. // &http.Client{
  119. // Jar: httpexpect.NewCookieJar(),
  120. // }
  121. //
  122. // You can use http.DefaultClient or your own http.Client, or provide
  123. // custom implementation.
  124. Client Client
  125. // WebsocketDialer is used to establish websocket.Conn and receive http.Response
  126. // of handshake result.
  127. // May be nil.
  128. //
  129. // If nil, set to a default dialer:
  130. // &websocket.Dialer{}
  131. //
  132. // You can use websocket.DefaultDialer or websocket.Dialer, or provide
  133. // custom implementation.
  134. WebsocketDialer WebsocketDialer
  135. // Context is passed to all requests. It is typically used for request cancellation,
  136. // either explicit or after a time-out.
  137. // May be nil.
  138. //
  139. // You can use the Request.WithContext for per-request context and Request.WithTimeout
  140. // for per-request timeout.
  141. Context context.Context
  142. // Reporter is used to report formatted failure messages.
  143. // Should NOT be nil, unless custom AssertionHandler is used.
  144. //
  145. // Config.Reporter is used by DefaultAssertionHandler, which is automatically
  146. // constructed when AssertionHandler is nil.
  147. //
  148. // You can use:
  149. // - AssertReporter / RequireReporter
  150. // (non-fatal / fatal failures using testify package)
  151. // - testing.T / FatalReporter
  152. // (non-fatal / fatal failures using standard testing package)
  153. // - PanicReporter
  154. // (failures that panic to be used in multithreaded tests)
  155. // - custom implementation
  156. Reporter Reporter
  157. // Formatter is used to format success and failure messages.
  158. // May be nil.
  159. //
  160. // If nil, DefaultFormatter is used.
  161. //
  162. // Config.Formatter is used by DefaultAssertionHandler, which is automatically
  163. // constructed when AssertionHandler is nil.
  164. //
  165. // Usually you don't need custom formatter. Implementing one is a
  166. // relatively big task.
  167. Formatter Formatter
  168. // AssertionHandler handles successful and failed assertions.
  169. // May be nil.
  170. //
  171. // Every time an assertion is made, AssertionHandler is invoked with detailed
  172. // info about the assertion. On failure, AssertionHandler is responsible to
  173. // format error and report it to the test suite.
  174. //
  175. // If AssertionHandler is nil, DefaultAssertionHandler is constructed, with
  176. // Formatter set to Config.Formatter, Reporter set to Config.Reporter, and
  177. // Logger set to nil. DefaultAssertionHandler will just delegate formatting
  178. // and reporting to Formatter and Reporter.
  179. //
  180. // If you're happy with DefaultAssertionHandler, but want to enable logging
  181. // of successful assertions and non-fatal failures, you can manually construct
  182. // DefaultAssertionHandler and set its Logger field to a non-nil value.
  183. //
  184. // Usually you don't need custom AssertionHandler and it's enough just to
  185. // set Reporter. Use AssertionHandler for more precise control of reports.
  186. AssertionHandler AssertionHandler
  187. // Printers are used to print requests and responses.
  188. // May be nil.
  189. //
  190. // If printer implements WebsocketPrinter interface, it will be also used
  191. // to print Websocket messages.
  192. //
  193. // You can use CompactPrinter, DebugPrinter, CurlPrinter, or provide
  194. // custom implementation.
  195. //
  196. // You can also use builtin printers with alternative Logger if you're happy
  197. // with their format, but want to send logs somewhere else than *testing.T.
  198. Printers []Printer
  199. // Environment provides a container for arbitrary data shared between tests.
  200. // May be nil.
  201. //
  202. // Environment is not used by httpexpect itself, but can be used by tests to
  203. // store and load arbitrary values. Tests can access Environment via
  204. // Expect.Env(). It is also accessible in AssertionHandler via AssertionContext.
  205. //
  206. // If Environment is nil, a new empty environment is automatically created
  207. // when Expect instance is constructed.
  208. Environment *Environment
  209. }
  210. func (config Config) withDefaults() Config {
  211. if config.RequestFactory == nil {
  212. config.RequestFactory = DefaultRequestFactory{}
  213. }
  214. if config.Client == nil {
  215. config.Client = &http.Client{
  216. Jar: NewCookieJar(),
  217. }
  218. }
  219. if config.WebsocketDialer == nil {
  220. config.WebsocketDialer = &websocket.Dialer{}
  221. }
  222. if config.AssertionHandler == nil {
  223. if config.Formatter == nil {
  224. config.Formatter = &DefaultFormatter{}
  225. }
  226. if config.Reporter == nil {
  227. panic("either Config.Reporter or Config.AssertionHandler should be non-nil")
  228. }
  229. config.AssertionHandler = &DefaultAssertionHandler{
  230. Formatter: config.Formatter,
  231. Reporter: config.Reporter,
  232. }
  233. }
  234. return config
  235. }
  236. func (config *Config) validate() {
  237. if config.RequestFactory == nil {
  238. panic("Config.RequestFactory is nil")
  239. }
  240. if config.Client == nil {
  241. panic("Config.Client is nil")
  242. }
  243. if config.AssertionHandler == nil {
  244. panic("Config.AssertionHandler is nil")
  245. }
  246. if handler, ok := config.AssertionHandler.(*DefaultAssertionHandler); ok {
  247. if handler.Formatter == nil {
  248. panic("DefaultAssertionHandler.Formatter is nil")
  249. }
  250. if handler.Reporter == nil {
  251. panic("DefaultAssertionHandler.Reporter is nil")
  252. }
  253. }
  254. }
  255. // RequestFactory is used to create all http.Request objects.
  256. // aetest.Instance from the Google App Engine implements this interface.
  257. type RequestFactory interface {
  258. NewRequest(method, url string, body io.Reader) (*http.Request, error)
  259. }
  260. // RequestFactoryFunc is an adapter that allows a function
  261. // to be used as the RequestFactory
  262. //
  263. // Example:
  264. //
  265. // e := httpexpect.WithConfig(httpexpect.Config{
  266. // RequestFactory: httpextect.RequestFactoryFunc(
  267. // func(method string, url string, body io.Reader) (*http.Request, error) {
  268. // // factory code here
  269. // }),
  270. // })
  271. type RequestFactoryFunc func(
  272. method string, url string, body io.Reader,
  273. ) (*http.Request, error)
  274. func (f RequestFactoryFunc) NewRequest(
  275. method string, url string, body io.Reader,
  276. ) (*http.Request, error) {
  277. return f(method, url, body)
  278. }
  279. // Client is used to send http.Request and receive http.Response.
  280. // http.Client implements this interface.
  281. //
  282. // Binder and FastBinder may be used to obtain this interface implementation.
  283. //
  284. // Example:
  285. //
  286. // httpBinderClient := &http.Client{
  287. // Transport: httpexpect.NewBinder(HTTPHandler),
  288. // }
  289. type Client interface {
  290. // Do sends request and returns response.
  291. Do(*http.Request) (*http.Response, error)
  292. }
  293. // ClientFunc is an adapter that allows a function to be used as the Client
  294. //
  295. // Example:
  296. //
  297. // e := httpexpect.WithConfig(httpexpect.Config{
  298. // Client: httpextect.ClientFunc(
  299. // func(req *http.Request) (*http.Response, error) {
  300. // // client code here
  301. // }),
  302. // })
  303. type ClientFunc func(req *http.Request) (*http.Response, error)
  304. func (f ClientFunc) Do(req *http.Request) (*http.Response, error) {
  305. return f(req)
  306. }
  307. // WebsocketDialer is used to establish websocket.Conn and receive http.Response
  308. // of handshake result.
  309. // websocket.Dialer implements this interface.
  310. //
  311. // NewWebsocketDialer and NewFastWebsocketDialer may be used to obtain this
  312. // interface implementation.
  313. //
  314. // Example:
  315. //
  316. // e := httpexpect.WithConfig(httpexpect.Config{
  317. // WebsocketDialer: httpexpect.NewWebsocketDialer(myHandler),
  318. // })
  319. type WebsocketDialer interface {
  320. // Dial establishes new Websocket connection and returns response
  321. // of handshake result.
  322. Dial(url string, reqH http.Header) (*websocket.Conn, *http.Response, error)
  323. }
  324. // WebsocketDialerFunc is an adapter that allows a function
  325. // to be used as the WebsocketDialer
  326. //
  327. // Example:
  328. //
  329. // e := httpexpect.WithConfig(httpexpect.Config{
  330. // WebsocketDialer: httpextect.WebsocketDialerFunc(
  331. // func(url string, reqH http.Header) (*websocket.Conn, *http.Response, error) {
  332. // // dialer code here
  333. // }),
  334. // })
  335. type WebsocketDialerFunc func(
  336. url string, reqH http.Header,
  337. ) (*websocket.Conn, *http.Response, error)
  338. func (f WebsocketDialerFunc) Dial(
  339. url string, reqH http.Header,
  340. ) (*websocket.Conn, *http.Response, error) {
  341. return f(url, reqH)
  342. }
  343. // Reporter is used to report failures.
  344. // *testing.T, FatalReporter, AssertReporter, RequireReporter, PanicReporter implement it.
  345. type Reporter interface {
  346. // Errorf reports failure.
  347. // Allowed to return normally or terminate test using t.FailNow().
  348. Errorf(message string, args ...interface{})
  349. }
  350. // ReporterFunc is an adapter that allows a function to be used as the Reporter
  351. //
  352. // Example:
  353. //
  354. // e := httpexpect.WithConfig(httpexpect.Config{
  355. // Reporter: httpextect.ReporterFunc(
  356. // func(message string, args ...interface{}) {
  357. // // reporter code here
  358. // }),
  359. // })
  360. type ReporterFunc func(message string, args ...interface{})
  361. func (f ReporterFunc) Errorf(message string, args ...interface{}) {
  362. f(message, args)
  363. }
  364. // Logger is used as output backend for Printer.
  365. // *testing.T implements this interface.
  366. type Logger interface {
  367. // Logf writes message to test log.
  368. Logf(fmt string, args ...interface{})
  369. }
  370. // LoggerFunc is an adapter that allows a function to be used as the Logger
  371. //
  372. // Example:
  373. //
  374. // e := httpexpect.WithConfig(httpexpect.Config{
  375. // Printers: []httpexpect.Printer{
  376. // httpexpect.NewCompactPrinter(
  377. // httpextect.LoggerFunc(
  378. // func(fmt string, args ...interface{}) {
  379. // // logger code here
  380. // })),
  381. // },
  382. // })
  383. type LoggerFunc func(fmt string, args ...interface{})
  384. func (f LoggerFunc) Logf(fmt string, args ...interface{}) {
  385. f(fmt, args)
  386. }
  387. // TestingTB is a subset of testing.TB interface used by httpexpect.
  388. // You can use *testing.T or pass custom implementation.
  389. type TestingTB interface {
  390. Reporter
  391. Logger
  392. Name() string // Returns current test name.
  393. }
  394. // Deprecated: use TestingTB instead.
  395. type LoggerReporter interface {
  396. Logger
  397. Reporter
  398. }
  399. // Deprecated: use Default instead.
  400. func New(t LoggerReporter, baseURL string) *Expect {
  401. return WithConfig(Config{
  402. BaseURL: baseURL,
  403. Reporter: NewAssertReporter(t),
  404. Printers: []Printer{
  405. NewCompactPrinter(t),
  406. },
  407. })
  408. }
  409. // Default returns a new Expect instance with default config.
  410. //
  411. // t is usually *testing.T, but can be any matching implementation.
  412. //
  413. // baseURL specifies URL to be prepended to all requests. May be empty. If non-empty,
  414. // trailing slash is allowed (but not required) and is appended automatically.
  415. //
  416. // Default is a shorthand for WithConfig. It uses:
  417. // - baseURL for Config.BaseURL
  418. // - t.Name() for Config.TestName
  419. // - NewAssertReporter(t) for Config.Reporter
  420. // - NewCompactPrinter(t) for Config.Printers
  421. //
  422. // Example:
  423. //
  424. // func TestSomething(t *testing.T) {
  425. // e := httpexpect.Default(t, "http://example.com/")
  426. //
  427. // e.GET("/path").
  428. // Expect().
  429. // Status(http.StatusOK)
  430. // }
  431. func Default(t TestingTB, baseURL string) *Expect {
  432. return WithConfig(Config{
  433. TestName: t.Name(),
  434. BaseURL: baseURL,
  435. Reporter: NewAssertReporter(t),
  436. Printers: []Printer{
  437. NewCompactPrinter(t),
  438. },
  439. })
  440. }
  441. // WithConfig returns a new Expect instance with custom config.
  442. //
  443. // Either Reporter or AssertionHandler should not be nil,
  444. // otherwise the function panics.
  445. //
  446. // Example:
  447. //
  448. // func TestSomething(t *testing.T) {
  449. // e := httpexpect.WithConfig(httpexpect.Config{
  450. // TestName: t.Name(),
  451. // BaseURL: "http://example.com/",
  452. // Client: &http.Client{
  453. // Transport: httpexpect.NewBinder(myHandler()),
  454. // Jar: httpexpect.NewCookieJar(),
  455. // },
  456. // Reporter: httpexpect.NewAssertReporter(t),
  457. // Printers: []httpexpect.Printer{
  458. // httpexpect.NewCurlPrinter(t),
  459. // httpexpect.NewDebugPrinter(t, true)
  460. // },
  461. // })
  462. //
  463. // e.GET("/path").
  464. // Expect().
  465. // Status(http.StatusOK)
  466. // }
  467. func WithConfig(config Config) *Expect {
  468. config = config.withDefaults()
  469. config.validate()
  470. return &Expect{
  471. chain: newChainWithConfig("", config),
  472. config: config,
  473. }
  474. }
  475. // Env returns Environment associated with Expect instance.
  476. // Tests can use it to store arbitrary data.
  477. //
  478. // Example:
  479. //
  480. // e := httpexpect.Default(t, "http://example.com")
  481. //
  482. // e.Env().Put("key", "value")
  483. // value := e.Env().GetString("key")
  484. func (e *Expect) Env() *Environment {
  485. return e.chain.env()
  486. }
  487. func (e *Expect) clone() *Expect {
  488. return &Expect{
  489. config: e.config,
  490. chain: e.chain.clone(),
  491. builders: append(([]func(*Request))(nil), e.builders...),
  492. matchers: append(([]func(*Response))(nil), e.matchers...),
  493. }
  494. }
  495. // Builder returns a copy of Expect instance with given builder attached to it.
  496. // Returned copy contains all previously attached builders plus a new one.
  497. // Builders are invoked from Request method, after constructing every new request.
  498. //
  499. // Example:
  500. //
  501. // e := httpexpect.Default(t, "http://example.com")
  502. //
  503. // token := e.POST("/login").WithForm(Login{"ford", "betelgeuse7"}).
  504. // Expect().
  505. // Status(http.StatusOK).JSON().Object().Value("token").String().Raw()
  506. //
  507. // auth := e.Builder(func (req *httpexpect.Request) {
  508. // req.WithHeader("Authorization", "Bearer "+token)
  509. // })
  510. //
  511. // auth.GET("/restricted").
  512. // Expect().
  513. // Status(http.StatusOK)
  514. func (e *Expect) Builder(builder func(*Request)) *Expect {
  515. ret := e.clone()
  516. ret.builders = append(ret.builders, builder)
  517. return ret
  518. }
  519. // Matcher returns a copy of Expect instance with given matcher attached to it.
  520. // Returned copy contains all previously attached matchers plus a new one.
  521. // Matchers are invoked from Request.Expect method, after retrieving a new response.
  522. //
  523. // Example:
  524. //
  525. // e := httpexpect.Default(t, "http://example.com")
  526. //
  527. // m := e.Matcher(func (resp *httpexpect.Response) {
  528. // resp.Header("API-Version").NotEmpty()
  529. // })
  530. //
  531. // m.GET("/some-path").
  532. // Expect().
  533. // Status(http.StatusOK)
  534. //
  535. // m.GET("/bad-path").
  536. // Expect().
  537. // Status(http.StatusNotFound)
  538. func (e *Expect) Matcher(matcher func(*Response)) *Expect {
  539. ret := e.clone()
  540. ret.matchers = append(ret.matchers, matcher)
  541. return ret
  542. }
  543. // Request returns a new Request instance.
  544. // Arguments are similar to NewRequest.
  545. // After creating request, all builders attached to Expect instance are invoked.
  546. // See Builder.
  547. func (e *Expect) Request(method, path string, pathargs ...interface{}) *Request {
  548. opChain := e.chain.enter("Request(%q)", method)
  549. defer opChain.leave()
  550. req := newRequest(opChain, e.config, method, path, pathargs...)
  551. for _, builder := range e.builders {
  552. builder(req)
  553. }
  554. for _, matcher := range e.matchers {
  555. req.WithMatcher(matcher)
  556. }
  557. return req
  558. }
  559. // OPTIONS is a shorthand for e.Request("OPTIONS", path, pathargs...).
  560. func (e *Expect) OPTIONS(path string, pathargs ...interface{}) *Request {
  561. return e.Request(http.MethodOptions, path, pathargs...)
  562. }
  563. // HEAD is a shorthand for e.Request("HEAD", path, pathargs...).
  564. func (e *Expect) HEAD(path string, pathargs ...interface{}) *Request {
  565. return e.Request(http.MethodHead, path, pathargs...)
  566. }
  567. // GET is a shorthand for e.Request("GET", path, pathargs...).
  568. func (e *Expect) GET(path string, pathargs ...interface{}) *Request {
  569. return e.Request(http.MethodGet, path, pathargs...)
  570. }
  571. // POST is a shorthand for e.Request("POST", path, pathargs...).
  572. func (e *Expect) POST(path string, pathargs ...interface{}) *Request {
  573. return e.Request(http.MethodPost, path, pathargs...)
  574. }
  575. // PUT is a shorthand for e.Request("PUT", path, pathargs...).
  576. func (e *Expect) PUT(path string, pathargs ...interface{}) *Request {
  577. return e.Request(http.MethodPut, path, pathargs...)
  578. }
  579. // PATCH is a shorthand for e.Request("PATCH", path, pathargs...).
  580. func (e *Expect) PATCH(path string, pathargs ...interface{}) *Request {
  581. return e.Request(http.MethodPatch, path, pathargs...)
  582. }
  583. // DELETE is a shorthand for e.Request("DELETE", path, pathargs...).
  584. func (e *Expect) DELETE(path string, pathargs ...interface{}) *Request {
  585. return e.Request(http.MethodDelete, path, pathargs...)
  586. }
  587. // Deprecated: use NewValue or NewValueC instead.
  588. func (e *Expect) Value(value interface{}) *Value {
  589. opChain := e.chain.enter("Value()")
  590. defer opChain.leave()
  591. return newValue(opChain, value)
  592. }
  593. // Deprecated: use NewObject or NewObjectC instead.
  594. func (e *Expect) Object(value map[string]interface{}) *Object {
  595. opChain := e.chain.enter("Object()")
  596. defer opChain.leave()
  597. return newObject(opChain, value)
  598. }
  599. // Deprecated: use NewArray or NewArrayC instead.
  600. func (e *Expect) Array(value []interface{}) *Array {
  601. opChain := e.chain.enter("Array()")
  602. defer opChain.leave()
  603. return newArray(opChain, value)
  604. }
  605. // Deprecated: use NewString or NewStringC instead.
  606. func (e *Expect) String(value string) *String {
  607. opChain := e.chain.enter("String()")
  608. defer opChain.leave()
  609. return newString(opChain, value)
  610. }
  611. // Deprecated: use NewNumber or NewNumberC instead.
  612. func (e *Expect) Number(value float64) *Number {
  613. opChain := e.chain.enter("Number()")
  614. defer opChain.leave()
  615. return newNumber(opChain, value)
  616. }
  617. // Deprecated: use NewBoolean or NewBooleanC instead.
  618. func (e *Expect) Boolean(value bool) *Boolean {
  619. opChain := e.chain.enter("Boolean()")
  620. defer opChain.leave()
  621. return newBoolean(opChain, value)
  622. }