github.com/go-kivik/kivik/v4@v4.3.2/mockdb/stringer_test.go (about) 1 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 2 // use this file except in compliance with the License. You may obtain a copy of 3 // the License at 4 // 5 // http://www.apache.org/licenses/LICENSE-2.0 6 // 7 // Unless required by applicable law or agreed to in writing, software 8 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 9 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 10 // License for the specific language governing permissions and limitations under 11 // the License. 12 13 package mockdb 14 15 import ( 16 "errors" 17 "fmt" 18 "testing" 19 "time" 20 21 "gitlab.com/flimzy/testy" 22 23 "github.com/go-kivik/kivik/v4" 24 "github.com/go-kivik/kivik/v4/driver" 25 ) 26 27 type stringerTest struct { 28 input fmt.Stringer 29 expected string 30 } 31 32 func testStringer(t *testing.T, test stringerTest) { 33 t.Helper() 34 result := test.input.String() 35 if test.expected != result { 36 t.Errorf("Unexpected String() output.\nWant: %s\n Got: %s\n", test.expected, result) 37 } 38 } 39 40 func TestCloseString(t *testing.T) { 41 tests := testy.NewTable() 42 tests.Add("standard", stringerTest{ 43 input: &ExpectedClose{}, 44 expected: "call to Close()", 45 }) 46 tests.Add("error", stringerTest{ 47 input: &ExpectedClose{commonExpectation: commonExpectation{err: errors.New("foo error")}}, 48 expected: `call to Close() which: 49 - should return error: foo error`, 50 }) 51 tests.Add("delay", stringerTest{ 52 input: &ExpectedClose{commonExpectation: commonExpectation{delay: time.Second}}, 53 expected: `call to Close() which: 54 - should delay for: 1s`, 55 }) 56 tests.Run(t, testStringer) 57 } 58 59 func TestReplicateString(t *testing.T) { 60 tests := testy.NewTable() 61 tests.Add("standard", stringerTest{ 62 input: &ExpectedReplicate{}, 63 expected: `call to Replicate() which: 64 - has any target 65 - has any source 66 - has any options`, 67 }) 68 tests.Add("target", stringerTest{ 69 input: &ExpectedReplicate{arg0: "foo"}, 70 expected: `call to Replicate() which: 71 - has target: foo 72 - has any source 73 - has any options`, 74 }) 75 tests.Add("source", stringerTest{ 76 input: &ExpectedReplicate{arg1: "http://example.com/bar"}, 77 expected: `call to Replicate() which: 78 - has any target 79 - has source: http://example.com/bar 80 - has any options`, 81 }) 82 tests.Add("return", stringerTest{ 83 input: &ExpectedReplicate{ret0: &Replication{id: "foo"}}, 84 expected: `call to Replicate() which: 85 - has any target 86 - has any source 87 - has any options 88 - should return: {"replication_id":"foo"}`, 89 }) 90 tests.Add("options", stringerTest{ 91 input: &ExpectedReplicate{commonExpectation: commonExpectation{options: kivik.Param("foo", 123)}}, 92 expected: `call to Replicate() which: 93 - has any target 94 - has any source 95 - has options: map[foo:123]`, 96 }) 97 tests.Add("error", stringerTest{ 98 input: &ExpectedReplicate{commonExpectation: commonExpectation{err: errors.New("foo error")}}, 99 expected: `call to Replicate() which: 100 - has any target 101 - has any source 102 - has any options 103 - should return error: foo error`, 104 }) 105 tests.Add("delay", stringerTest{ 106 input: &ExpectedReplicate{commonExpectation: commonExpectation{delay: time.Second}}, 107 expected: `call to Replicate() which: 108 - has any target 109 - has any source 110 - has any options 111 - should delay for: 1s`, 112 }) 113 tests.Run(t, testStringer) 114 } 115 116 func TestGetReplicationsString(t *testing.T) { 117 tests := testy.NewTable() 118 tests.Add("standard", stringerTest{ 119 input: &ExpectedGetReplications{}, 120 expected: `call to GetReplications() which: 121 - has any options`, 122 }) 123 tests.Add("options", stringerTest{ 124 input: &ExpectedGetReplications{commonExpectation: commonExpectation{options: kivik.Param("foo", 123)}}, 125 expected: `call to GetReplications() which: 126 - has options: map[foo:123]`, 127 }) 128 tests.Add("return", stringerTest{ 129 input: &ExpectedGetReplications{ret0: []*Replication{{}, {}}}, 130 expected: `call to GetReplications() which: 131 - has any options 132 - should return: 2 results`, 133 }) 134 tests.Add("error", stringerTest{ 135 input: &ExpectedGetReplications{commonExpectation: commonExpectation{err: errors.New("foo error")}}, 136 expected: `call to GetReplications() which: 137 - has any options 138 - should return error: foo error`, 139 }) 140 tests.Add("delay", stringerTest{ 141 input: &ExpectedGetReplications{commonExpectation: commonExpectation{delay: time.Second}}, 142 expected: `call to GetReplications() which: 143 - has any options 144 - should delay for: 1s`, 145 }) 146 tests.Run(t, testStringer) 147 } 148 149 func TestAllDBsString(t *testing.T) { 150 tests := testy.NewTable() 151 tests.Add("standard", stringerTest{ 152 input: &ExpectedAllDBs{}, 153 expected: `call to AllDBs() which: 154 - has any options`, 155 }) 156 tests.Add("options", stringerTest{ 157 input: &ExpectedAllDBs{commonExpectation: commonExpectation{options: kivik.Param("foo", 123)}}, 158 expected: `call to AllDBs() which: 159 - has options: map[foo:123]`, 160 }) 161 tests.Add("error", stringerTest{ 162 input: &ExpectedAllDBs{commonExpectation: commonExpectation{err: errors.New("foo err")}}, 163 expected: `call to AllDBs() which: 164 - has any options 165 - should return error: foo err`, 166 }) 167 tests.Add("delay", stringerTest{ 168 input: &ExpectedAllDBs{commonExpectation: commonExpectation{delay: time.Second}}, 169 expected: `call to AllDBs() which: 170 - has any options 171 - should delay for: 1s`, 172 }) 173 tests.Run(t, testStringer) 174 } 175 176 func TestClusterSetupString(t *testing.T) { 177 tests := testy.NewTable() 178 tests.Add("empty", stringerTest{ 179 input: &ExpectedClusterSetup{}, 180 expected: `call to ClusterSetup() which: 181 - has any action`, 182 }) 183 tests.Add("action", stringerTest{ 184 input: &ExpectedClusterSetup{arg0: map[string]string{"foo": "bar"}}, 185 expected: `call to ClusterSetup() which: 186 - has the action: map[foo:bar]`, 187 }) 188 tests.Add("error", stringerTest{ 189 input: &ExpectedClusterSetup{commonExpectation: commonExpectation{err: errors.New("foo error")}}, 190 expected: `call to ClusterSetup() which: 191 - has any action 192 - should return error: foo error`, 193 }) 194 tests.Add("delay", stringerTest{ 195 input: &ExpectedClusterSetup{commonExpectation: commonExpectation{delay: time.Second}}, 196 expected: `call to ClusterSetup() which: 197 - has any action 198 - should delay for: 1s`, 199 }) 200 tests.Run(t, testStringer) 201 } 202 203 func TestClusterStatusString(t *testing.T) { 204 tests := testy.NewTable() 205 tests.Add("empty", stringerTest{ 206 input: &ExpectedClusterStatus{}, 207 expected: `call to ClusterStatus() which: 208 - has any options`, 209 }) 210 tests.Add("options", stringerTest{ 211 input: &ExpectedClusterStatus{commonExpectation: commonExpectation{options: kivik.Param("foo", 123)}}, 212 expected: `call to ClusterStatus() which: 213 - has options: map[foo:123]`, 214 }) 215 tests.Add("error", stringerTest{ 216 input: &ExpectedClusterStatus{commonExpectation: commonExpectation{err: errors.New("foo error")}}, 217 expected: `call to ClusterStatus() which: 218 - has any options 219 - should return error: foo error`, 220 }) 221 tests.Add("delay", stringerTest{ 222 input: &ExpectedClusterStatus{commonExpectation: commonExpectation{delay: time.Second}}, 223 expected: `call to ClusterStatus() which: 224 - has any options 225 - should delay for: 1s`, 226 }) 227 tests.Run(t, testStringer) 228 } 229 230 func TestMembershipString(t *testing.T) { 231 tests := testy.NewTable() 232 tests.Add("empty", stringerTest{ 233 input: &ExpectedMembership{}, 234 expected: `call to Membership()`, 235 }) 236 tests.Add("error", stringerTest{ 237 input: &ExpectedMembership{commonExpectation: commonExpectation{err: errors.New("foo error")}}, 238 expected: `call to Membership() which: 239 - should return error: foo error`, 240 }) 241 tests.Add("delay", stringerTest{ 242 input: &ExpectedMembership{commonExpectation: commonExpectation{delay: time.Second}}, 243 expected: `call to Membership() which: 244 - should delay for: 1s`, 245 }) 246 tests.Run(t, testStringer) 247 } 248 249 func TestDBExistsString(t *testing.T) { 250 tests := testy.NewTable() 251 tests.Add("empty", stringerTest{ 252 input: &ExpectedDBExists{}, 253 expected: `call to DBExists() which: 254 - has any name 255 - has any options 256 - should return: false`, 257 }) 258 tests.Add("full", stringerTest{ 259 input: &ExpectedDBExists{arg0: "foo", ret0: true, commonExpectation: commonExpectation{options: kivik.Param("foo", 123)}}, 260 expected: `call to DBExists() which: 261 - has name: foo 262 - has options: map[foo:123] 263 - should return: true`, 264 }) 265 tests.Add("error", stringerTest{ 266 input: &ExpectedDBExists{commonExpectation: commonExpectation{err: errors.New("foo err")}}, 267 expected: `call to DBExists() which: 268 - has any name 269 - has any options 270 - should return error: foo err`, 271 }) 272 tests.Add("delay", stringerTest{ 273 input: &ExpectedDBExists{commonExpectation: commonExpectation{delay: time.Second}}, 274 expected: `call to DBExists() which: 275 - has any name 276 - has any options 277 - should delay for: 1s 278 - should return: false`, 279 }) 280 tests.Run(t, testStringer) 281 } 282 283 func TestDestroyDBString(t *testing.T) { 284 tests := testy.NewTable() 285 tests.Add("empty", stringerTest{ 286 input: &ExpectedDestroyDB{}, 287 expected: `call to DestroyDB() which: 288 - has any name 289 - has any options`, 290 }) 291 tests.Add("name", stringerTest{ 292 input: &ExpectedDestroyDB{arg0: "foo"}, 293 expected: `call to DestroyDB() which: 294 - has name: foo 295 - has any options`, 296 }) 297 tests.Add("delay", stringerTest{ 298 input: &ExpectedDestroyDB{commonExpectation: commonExpectation{delay: time.Second}}, 299 expected: `call to DestroyDB() which: 300 - has any name 301 - has any options 302 - should delay for: 1s`, 303 }) 304 tests.Run(t, testStringer) 305 } 306 307 func TestDBsStatsString(t *testing.T) { 308 tests := testy.NewTable() 309 tests.Add("empty", stringerTest{ 310 input: &ExpectedDBsStats{}, 311 expected: `call to DBsStats() which: 312 - has any names`, 313 }) 314 tests.Add("names", stringerTest{ 315 input: &ExpectedDBsStats{arg0: []string{"a", "b"}}, 316 expected: `call to DBsStats() which: 317 - has names: [a b]`, 318 }) 319 tests.Add("delay", stringerTest{ 320 input: &ExpectedDBsStats{commonExpectation: commonExpectation{delay: time.Second}}, 321 expected: `call to DBsStats() which: 322 - has any names 323 - should delay for: 1s`, 324 }) 325 tests.Add("error", stringerTest{ 326 input: &ExpectedDBsStats{commonExpectation: commonExpectation{err: errors.New("foo err")}}, 327 expected: `call to DBsStats() which: 328 - has any names 329 - should return error: foo err`, 330 }) 331 tests.Run(t, testStringer) 332 } 333 334 func TestAllDBsStatsString(t *testing.T) { 335 tests := testy.NewTable() 336 tests.Add("empty", stringerTest{ 337 input: &ExpectedAllDBsStats{}, 338 expected: `call to AllDBsStats() which: 339 - has any options`, 340 }) 341 342 tests.Run(t, testStringer) 343 } 344 345 func TestPingString(t *testing.T) { 346 tests := testy.NewTable() 347 tests.Add("empty", stringerTest{ 348 input: &ExpectedPing{}, 349 expected: `call to Ping()`, 350 }) 351 tests.Add("error", stringerTest{ 352 input: &ExpectedPing{commonExpectation: commonExpectation{err: errors.New("foo err")}}, 353 expected: `call to Ping() which: 354 - should return error: foo err`, 355 }) 356 tests.Add("delay", stringerTest{ 357 input: &ExpectedPing{commonExpectation: commonExpectation{delay: time.Second}}, 358 expected: `call to Ping() which: 359 - should delay for: 1s`, 360 }) 361 tests.Run(t, testStringer) 362 } 363 364 func TestSessionString(t *testing.T) { 365 tests := testy.NewTable() 366 tests.Add("empty", stringerTest{ 367 input: &ExpectedSession{}, 368 expected: `call to Session()`, 369 }) 370 tests.Add("session", stringerTest{ 371 input: &ExpectedSession{ret0: &driver.Session{Name: "bob"}}, 372 expected: `call to Session() which: 373 - should return: &{bob [] [] []}`, 374 }) 375 tests.Run(t, testStringer) 376 } 377 378 func TestVersionString(t *testing.T) { 379 tests := testy.NewTable() 380 tests.Add("empty", stringerTest{ 381 input: &ExpectedVersion{}, 382 expected: `call to Version()`, 383 }) 384 tests.Add("session", stringerTest{ 385 input: &ExpectedVersion{ret0: &driver.Version{Version: "1.2"}}, 386 expected: `call to Version() which: 387 - should return: &{1.2 [] []}`, 388 }) 389 tests.Run(t, testStringer) 390 } 391 392 func TestCreateDBString(t *testing.T) { 393 tests := testy.NewTable() 394 tests.Add("empty", stringerTest{ 395 input: &ExpectedCreateDB{}, 396 expected: `call to CreateDB() which: 397 - has any name 398 - has any options`, 399 }) 400 tests.Add("name", stringerTest{ 401 input: &ExpectedCreateDB{arg0: "foo"}, 402 expected: `call to CreateDB() which: 403 - has name: foo 404 - has any options`, 405 }) 406 tests.Add("db", stringerTest{ 407 input: &ExpectedCreateDB{commonExpectation: commonExpectation{db: &DB{count: 50}}}, 408 expected: `call to CreateDB() which: 409 - has any name 410 - has any options 411 - should return database with 50 expectations`, 412 }) 413 tests.Run(t, testStringer) 414 } 415 416 func TestDBString(t *testing.T) { 417 tests := testy.NewTable() 418 tests.Add("empty", stringerTest{ 419 input: &ExpectedDB{}, 420 expected: `call to DB() which: 421 - has any name 422 - has any options`, 423 }) 424 tests.Add("name", stringerTest{ 425 input: &ExpectedDB{arg0: "foo"}, 426 expected: `call to DB() which: 427 - has name: foo 428 - has any options`, 429 }) 430 tests.Add("db", stringerTest{ 431 input: &ExpectedDB{commonExpectation: commonExpectation{db: &DB{count: 50}}}, 432 expected: `call to DB() which: 433 - has any name 434 - has any options 435 - should return database with 50 expectations`, 436 }) 437 tests.Run(t, testStringer) 438 } 439 440 func TestDBCloseString(t *testing.T) { 441 tests := testy.NewTable() 442 tests.Add("standard", stringerTest{ 443 input: &ExpectedDBClose{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 444 expected: "call to DB(foo#0).Close()", 445 }) 446 tests.Add("error", stringerTest{ 447 input: &ExpectedDBClose{commonExpectation: commonExpectation{db: &DB{name: "foo"}, err: errors.New("foo error")}}, 448 expected: `call to DB(foo#0).Close() which: 449 - should return error: foo error`, 450 }) 451 tests.Add("delay", stringerTest{ 452 input: &ExpectedDBClose{commonExpectation: commonExpectation{db: &DB{name: "foo"}, delay: time.Second}}, 453 expected: `call to DB(foo#0).Close() which: 454 - should delay for: 1s`, 455 }) 456 tests.Run(t, testStringer) 457 } 458 459 func TestAllDocsString(t *testing.T) { 460 tests := testy.NewTable() 461 tests.Add("empty", stringerTest{ 462 input: &ExpectedAllDocs{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 463 expected: `call to DB(foo#0).AllDocs() which: 464 - has any options`, 465 }) 466 tests.Add("results", stringerTest{ 467 input: &ExpectedAllDocs{ 468 commonExpectation: commonExpectation{db: &DB{name: "foo"}}, 469 ret0: &Rows{iter: iter{items: []*item{ 470 {item: &driver.Row{}}, 471 {item: &driver.Row{}}, 472 {delay: 15}, 473 {item: &driver.Row{}}, 474 {item: &driver.Row{}}, 475 }}}, 476 }, 477 expected: `call to DB(foo#0).AllDocs() which: 478 - has any options 479 - should return: 4 results`, 480 }) 481 tests.Run(t, testStringer) 482 } 483 484 func TestBulkGetString(t *testing.T) { 485 tests := testy.NewTable() 486 tests.Add("empty", stringerTest{ 487 input: &ExpectedBulkGet{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 488 expected: `call to DB(foo#0).BulkGet() which: 489 - has any doc references 490 - has any options`, 491 }) 492 tests.Add("docs", stringerTest{ 493 input: &ExpectedBulkGet{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg0: []driver.BulkGetReference{ 494 {ID: "foo"}, 495 {ID: "bar"}, 496 }}, 497 expected: `call to DB(foo#0).BulkGet() which: 498 - has doc references: [{"id":"foo"},{"id":"bar"}] 499 - has any options`, 500 }) 501 tests.Add("results", stringerTest{ 502 input: &ExpectedBulkGet{ 503 commonExpectation: commonExpectation{db: &DB{name: "foo"}}, 504 ret0: &Rows{iter: iter{items: []*item{ 505 {item: &driver.Row{}}, 506 {item: &driver.Row{}}, 507 {delay: 15}, 508 {item: &driver.Row{}}, 509 {item: &driver.Row{}}, 510 }}}, 511 }, 512 expected: `call to DB(foo#0).BulkGet() which: 513 - has any doc references 514 - has any options 515 - should return: 4 results`, 516 }) 517 tests.Run(t, testStringer) 518 } 519 520 func TestFindString(t *testing.T) { 521 tests := testy.NewTable() 522 tests.Add("empty", stringerTest{ 523 input: &ExpectedFind{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 524 expected: `call to DB(foo#0).Find() which: 525 - has any query 526 - has any options`, 527 }) 528 tests.Add("query", stringerTest{ 529 input: &ExpectedFind{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg0: map[string]string{"foo": "bar"}}, 530 expected: `call to DB(foo#0).Find() which: 531 - has query: map[foo:bar] 532 - has any options`, 533 }) 534 tests.Add("results", stringerTest{ 535 input: &ExpectedFind{ 536 commonExpectation: commonExpectation{db: &DB{name: "foo"}}, 537 ret0: &Rows{iter: iter{items: []*item{ 538 {item: &driver.Row{}}, 539 {item: &driver.Row{}}, 540 {delay: 15}, 541 {item: &driver.Row{}}, 542 {item: &driver.Row{}}, 543 }}}, 544 }, 545 expected: `call to DB(foo#0).Find() which: 546 - has any query 547 - has any options 548 - should return: 4 results`, 549 }) 550 tests.Run(t, testStringer) 551 } 552 553 func TestCreateIndexString(t *testing.T) { 554 tests := testy.NewTable() 555 tests.Add("empty", stringerTest{ 556 input: &ExpectedCreateIndex{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 557 expected: `call to DB(foo#0).CreateIndex() which: 558 - has any ddoc 559 - has any name 560 - has any index`, 561 }) 562 tests.Add("ddoc", stringerTest{ 563 input: &ExpectedCreateIndex{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg0: "foo"}, 564 expected: `call to DB(foo#0).CreateIndex() which: 565 - has ddoc: foo 566 - has any name 567 - has any index`, 568 }) 569 tests.Add("name", stringerTest{ 570 input: &ExpectedCreateIndex{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg1: "foo"}, 571 expected: `call to DB(foo#0).CreateIndex() which: 572 - has any ddoc 573 - has name: foo 574 - has any index`, 575 }) 576 tests.Add("index", stringerTest{ 577 input: &ExpectedCreateIndex{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg2: map[string]string{"foo": "bar"}}, 578 expected: `call to DB(foo#0).CreateIndex() which: 579 - has any ddoc 580 - has any name 581 - has index: map[foo:bar]`, 582 }) 583 tests.Run(t, testStringer) 584 } 585 586 func TestExpectedGetIndexesString(t *testing.T) { 587 tests := testy.NewTable() 588 tests.Add("empty", stringerTest{ 589 input: &ExpectedGetIndexes{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 590 expected: `call to DB(foo#0).GetIndexes()`, 591 }) 592 tests.Add("error", stringerTest{ 593 input: &ExpectedGetIndexes{commonExpectation: commonExpectation{db: &DB{name: "foo"}, err: errors.New("foo err")}}, 594 expected: `call to DB(foo#0).GetIndexes() which: 595 - should return error: foo err`, 596 }) 597 tests.Add("indexes", stringerTest{ 598 input: &ExpectedGetIndexes{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, ret0: []driver.Index{{Name: "foo"}}}, 599 expected: `call to DB(foo#0).GetIndexes() which: 600 - should return indexes: [{ foo <nil>}]`, 601 }) 602 tests.Run(t, testStringer) 603 } 604 605 func TestDeleteIndexString(t *testing.T) { 606 tests := testy.NewTable() 607 tests.Add("empty", stringerTest{ 608 input: &ExpectedDeleteIndex{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 609 expected: `call to DB(foo#0).DeleteIndex() which: 610 - has any ddoc 611 - has any name`, 612 }) 613 tests.Add("ddoc", stringerTest{ 614 input: &ExpectedDeleteIndex{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg0: "foo"}, 615 expected: `call to DB(foo#0).DeleteIndex() which: 616 - has ddoc: foo 617 - has any name`, 618 }) 619 tests.Add("name", stringerTest{ 620 input: &ExpectedDeleteIndex{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg1: "foo"}, 621 expected: `call to DB(foo#0).DeleteIndex() which: 622 - has any ddoc 623 - has name: foo`, 624 }) 625 tests.Run(t, testStringer) 626 } 627 628 func TestExplainString(t *testing.T) { 629 tests := testy.NewTable() 630 tests.Add("empty", stringerTest{ 631 input: &ExpectedExplain{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 632 expected: `call to DB(foo#0).Explain() which: 633 - has any query`, 634 }) 635 tests.Add("query", stringerTest{ 636 input: &ExpectedExplain{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg0: map[string]string{"foo": "bar"}}, 637 expected: `call to DB(foo#0).Explain() which: 638 - has query: map[foo:bar]`, 639 }) 640 tests.Add("plan", stringerTest{ 641 input: &ExpectedExplain{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, ret0: &driver.QueryPlan{DBName: "foo"}}, 642 expected: `call to DB(foo#0).Explain() which: 643 - has any query 644 - should return query plan: &{foo map[] map[] map[] 0 0 [] map[]}`, 645 }) 646 tests.Add("error", stringerTest{ 647 input: &ExpectedExplain{commonExpectation: commonExpectation{db: &DB{name: "foo"}, err: errors.New("foo err")}}, 648 expected: `call to DB(foo#0).Explain() which: 649 - has any query 650 - should return error: foo err`, 651 }) 652 tests.Run(t, testStringer) 653 } 654 655 func TestCreateDocString(t *testing.T) { 656 tests := testy.NewTable() 657 tests.Add("empty", stringerTest{ 658 input: &ExpectedCreateDoc{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 659 expected: `call to DB(foo#0).CreateDoc() which: 660 - has any doc 661 - has any options`, 662 }) 663 tests.Add("doc", stringerTest{ 664 input: &ExpectedCreateDoc{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg0: map[string]string{"foo": "bar"}}, 665 expected: `call to DB(foo#0).CreateDoc() which: 666 - has doc: {"foo":"bar"} 667 - has any options`, 668 }) 669 tests.Add("options", stringerTest{ 670 input: &ExpectedCreateDoc{commonExpectation: commonExpectation{db: &DB{name: "foo"}, options: kivik.Param("foo", "bar")}}, 671 expected: `call to DB(foo#0).CreateDoc() which: 672 - has any doc 673 - has options: map[foo:bar]`, 674 }) 675 tests.Add("error", stringerTest{ 676 input: &ExpectedCreateDoc{commonExpectation: commonExpectation{db: &DB{name: "foo"}, err: errors.New("foo err")}}, 677 expected: `call to DB(foo#0).CreateDoc() which: 678 - has any doc 679 - has any options 680 - should return error: foo err`, 681 }) 682 tests.Add("delay", stringerTest{ 683 input: &ExpectedCreateDoc{commonExpectation: commonExpectation{db: &DB{name: "foo"}, delay: time.Second}}, 684 expected: `call to DB(foo#0).CreateDoc() which: 685 - has any doc 686 - has any options 687 - should delay for: 1s`, 688 }) 689 tests.Add("docID", stringerTest{ 690 input: &ExpectedCreateDoc{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, ret0: "foo"}, 691 expected: `call to DB(foo#0).CreateDoc() which: 692 - has any doc 693 - has any options 694 - should return docID: foo`, 695 }) 696 tests.Add("rev", stringerTest{ 697 input: &ExpectedCreateDoc{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, ret1: "1-foo"}, 698 expected: `call to DB(foo#0).CreateDoc() which: 699 - has any doc 700 - has any options 701 - should return rev: 1-foo`, 702 }) 703 tests.Run(t, testStringer) 704 } 705 706 func TestCompactString(t *testing.T) { 707 tests := testy.NewTable() 708 tests.Add("empty", stringerTest{ 709 input: &ExpectedCompact{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 710 expected: `call to DB(foo#0).Compact()`, 711 }) 712 tests.Add("error", stringerTest{ 713 input: &ExpectedCompact{commonExpectation: commonExpectation{db: &DB{name: "foo"}, err: errors.New("foo err")}}, 714 expected: `call to DB(foo#0).Compact() which: 715 - should return error: foo err`, 716 }) 717 tests.Add("delay", stringerTest{ 718 input: &ExpectedCompact{commonExpectation: commonExpectation{db: &DB{name: "foo"}, delay: time.Second}}, 719 expected: `call to DB(foo#0).Compact() which: 720 - should delay for: 1s`, 721 }) 722 723 tests.Run(t, testStringer) 724 } 725 726 func TestViewCleanupString(t *testing.T) { 727 tests := testy.NewTable() 728 tests.Add("empty", stringerTest{ 729 input: &ExpectedViewCleanup{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 730 expected: `call to DB(foo#0).ViewCleanup()`, 731 }) 732 tests.Add("error", stringerTest{ 733 input: &ExpectedViewCleanup{commonExpectation: commonExpectation{db: &DB{name: "foo"}, err: errors.New("foo err")}}, 734 expected: `call to DB(foo#0).ViewCleanup() which: 735 - should return error: foo err`, 736 }) 737 tests.Add("delay", stringerTest{ 738 input: &ExpectedViewCleanup{commonExpectation: commonExpectation{db: &DB{name: "foo"}, delay: time.Second}}, 739 expected: `call to DB(foo#0).ViewCleanup() which: 740 - should delay for: 1s`, 741 }) 742 743 tests.Run(t, testStringer) 744 } 745 746 func TestPutString(t *testing.T) { 747 tests := testy.NewTable() 748 tests.Add("empty", stringerTest{ 749 input: &ExpectedPut{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 750 expected: `call to DB(foo#0).Put() which: 751 - has any docID 752 - has any doc 753 - has any options`, 754 }) 755 tests.Add("docID", stringerTest{ 756 input: &ExpectedPut{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg0: "foo"}, 757 expected: `call to DB(foo#0).Put() which: 758 - has docID: foo 759 - has any doc 760 - has any options`, 761 }) 762 tests.Add("doc", stringerTest{ 763 input: &ExpectedPut{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg1: map[string]string{"foo": "bar"}}, 764 expected: `call to DB(foo#0).Put() which: 765 - has any docID 766 - has doc: {"foo":"bar"} 767 - has any options`, 768 }) 769 tests.Add("error", stringerTest{ 770 input: &ExpectedPut{commonExpectation: commonExpectation{db: &DB{name: "foo"}, err: errors.New("foo err")}}, 771 expected: `call to DB(foo#0).Put() which: 772 - has any docID 773 - has any doc 774 - has any options 775 - should return error: foo err`, 776 }) 777 tests.Add("delay", stringerTest{ 778 input: &ExpectedPut{commonExpectation: commonExpectation{db: &DB{name: "foo"}, delay: time.Second}}, 779 expected: `call to DB(foo#0).Put() which: 780 - has any docID 781 - has any doc 782 - has any options 783 - should delay for: 1s`, 784 }) 785 tests.Run(t, testStringer) 786 } 787 788 func TestGetRevString(t *testing.T) { 789 tests := testy.NewTable() 790 tests.Add("empty", stringerTest{ 791 input: &ExpectedGetRev{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 792 expected: `call to DB(foo#0).GetRev() which: 793 - has any docID 794 - has any options`, 795 }) 796 tests.Add("docID", stringerTest{ 797 input: &ExpectedGetRev{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg0: "foo"}, 798 expected: `call to DB(foo#0).GetRev() which: 799 - has docID: foo 800 - has any options`, 801 }) 802 tests.Add("rev", stringerTest{ 803 input: &ExpectedGetRev{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, ret0: "1-xxx"}, 804 expected: `call to DB(foo#0).GetRev() which: 805 - has any docID 806 - has any options 807 - should return rev: 1-xxx`, 808 }) 809 tests.Add("error", stringerTest{ 810 input: &ExpectedGetRev{commonExpectation: commonExpectation{db: &DB{name: "foo"}, err: errors.New("foo err")}}, 811 expected: `call to DB(foo#0).GetRev() which: 812 - has any docID 813 - has any options 814 - should return error: foo err`, 815 }) 816 tests.Add("delay", stringerTest{ 817 input: &ExpectedGetRev{commonExpectation: commonExpectation{db: &DB{name: "foo"}, delay: time.Second}}, 818 expected: `call to DB(foo#0).GetRev() which: 819 - has any docID 820 - has any options 821 - should delay for: 1s`, 822 }) 823 tests.Run(t, testStringer) 824 } 825 826 func TestCompactViewString(t *testing.T) { 827 tests := testy.NewTable() 828 tests.Add("empty", stringerTest{ 829 input: &ExpectedCompactView{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 830 expected: `call to DB(foo#0).CompactView() which: 831 - has any ddocID`, 832 }) 833 tests.Add("ddocID", stringerTest{ 834 input: &ExpectedCompactView{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg0: "foo"}, 835 expected: `call to DB(foo#0).CompactView() which: 836 - has ddocID: foo`, 837 }) 838 tests.Add("error", stringerTest{ 839 input: &ExpectedCompactView{commonExpectation: commonExpectation{db: &DB{name: "foo"}, err: errors.New("foo err")}}, 840 expected: `call to DB(foo#0).CompactView() which: 841 - has any ddocID 842 - should return error: foo err`, 843 }) 844 tests.Add("delay", stringerTest{ 845 input: &ExpectedCompactView{commonExpectation: commonExpectation{db: &DB{name: "foo"}, delay: time.Second}}, 846 expected: `call to DB(foo#0).CompactView() which: 847 - has any ddocID 848 - should delay for: 1s`, 849 }) 850 tests.Run(t, testStringer) 851 } 852 853 func TestFlushString(t *testing.T) { 854 tests := testy.NewTable() 855 tests.Add("empty", stringerTest{ 856 input: &ExpectedFlush{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 857 expected: `call to DB(foo#0).Flush()`, 858 }) 859 tests.Run(t, testStringer) 860 } 861 862 func TestDeleteAttachmentString(t *testing.T) { 863 tests := testy.NewTable() 864 tests.Add("empty", stringerTest{ 865 input: &ExpectedDeleteAttachment{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 866 expected: `call to DB(foo#0).DeleteAttachment() which: 867 - has any docID 868 - has any filename 869 - has any options`, 870 }) 871 tests.Add("docID", stringerTest{ 872 input: &ExpectedDeleteAttachment{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg0: "foo"}, 873 expected: `call to DB(foo#0).DeleteAttachment() which: 874 - has docID: foo 875 - has any filename 876 - has any options`, 877 }) 878 tests.Add("filename", stringerTest{ 879 input: &ExpectedDeleteAttachment{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg1: "foo.txt"}, 880 expected: `call to DB(foo#0).DeleteAttachment() which: 881 - has any docID 882 - has filename: foo.txt 883 - has any options`, 884 }) 885 tests.Add("return", stringerTest{ 886 input: &ExpectedDeleteAttachment{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, ret0: "2-bar"}, 887 expected: `call to DB(foo#0).DeleteAttachment() which: 888 - has any docID 889 - has any filename 890 - has any options 891 - should return rev: 2-bar`, 892 }) 893 tests.Run(t, testStringer) 894 } 895 896 func TestDeleteString(t *testing.T) { 897 tests := testy.NewTable() 898 tests.Add("empty", stringerTest{ 899 input: &ExpectedDelete{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 900 expected: `call to DB(foo#0).Delete() which: 901 - has any docID 902 - has any options`, 903 }) 904 tests.Add("docID", stringerTest{ 905 input: &ExpectedDelete{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg0: "foo"}, 906 expected: `call to DB(foo#0).Delete() which: 907 - has docID: foo 908 - has any options`, 909 }) 910 tests.Add("options", stringerTest{ 911 input: &ExpectedDelete{commonExpectation: commonExpectation{db: &DB{name: "foo"}, options: kivik.Param("foo", "bar")}}, 912 expected: `call to DB(foo#0).Delete() which: 913 - has any docID 914 - has options: map[foo:bar]`, 915 }) 916 tests.Add("return", stringerTest{ 917 input: &ExpectedDelete{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, ret0: "2-bar"}, 918 expected: `call to DB(foo#0).Delete() which: 919 - has any docID 920 - has any options 921 - should return rev: 2-bar`, 922 }) 923 tests.Run(t, testStringer) 924 } 925 926 func TestCopyString(t *testing.T) { 927 tests := testy.NewTable() 928 tests.Add("empty", stringerTest{ 929 input: &ExpectedCopy{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 930 expected: `call to DB(foo#0).Copy() which: 931 - has any targetID 932 - has any sourceID 933 - has any options`, 934 }) 935 tests.Add("targetID", stringerTest{ 936 input: &ExpectedCopy{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg0: "foo"}, 937 expected: `call to DB(foo#0).Copy() which: 938 - has targetID: foo 939 - has any sourceID 940 - has any options`, 941 }) 942 tests.Add("sourceID", stringerTest{ 943 input: &ExpectedCopy{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg1: "foo"}, 944 expected: `call to DB(foo#0).Copy() which: 945 - has any targetID 946 - has sourceID: foo 947 - has any options`, 948 }) 949 tests.Add("return value", stringerTest{ 950 input: &ExpectedCopy{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, ret0: "1-foo"}, 951 expected: `call to DB(foo#0).Copy() which: 952 - has any targetID 953 - has any sourceID 954 - has any options 955 - should return rev: 1-foo`, 956 }) 957 tests.Run(t, testStringer) 958 } 959 960 func TestGetString(t *testing.T) { 961 tests := testy.NewTable() 962 tests.Add("empty", stringerTest{ 963 input: &ExpectedGet{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 964 expected: `call to DB(foo#0).Get() which: 965 - has any docID 966 - has any options`, 967 }) 968 tests.Add("docID", stringerTest{ 969 input: &ExpectedGet{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg0: "foo"}, 970 expected: `call to DB(foo#0).Get() which: 971 - has docID: foo 972 - has any options`, 973 }) 974 tests.Add("return value", stringerTest{ 975 input: &ExpectedGet{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, ret0: &driver.Document{Rev: "1-foo"}}, 976 expected: `call to DB(foo#0).Get() which: 977 - has any docID 978 - has any options 979 - should return document with rev: 1-foo`, 980 }) 981 tests.Run(t, testStringer) 982 } 983 984 func TestOpenRevsString(t *testing.T) { 985 tests := testy.NewTable() 986 tests.Add("empty", stringerTest{ 987 input: &ExpectedOpenRevs{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 988 expected: `call to DB(foo#0).OpenRevs() which: 989 - has any docID 990 - has any revs 991 - has any options`, 992 }) 993 tests.Add("docID", stringerTest{ 994 input: &ExpectedOpenRevs{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg0: "foo"}, 995 expected: `call to DB(foo#0).OpenRevs() which: 996 - has docID: foo 997 - has any revs 998 - has any options`, 999 }) 1000 tests.Add("revs", stringerTest{ 1001 input: &ExpectedOpenRevs{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg1: []string{"foo", "bar"}}, 1002 expected: `call to DB(foo#0).OpenRevs() which: 1003 - has any docID 1004 - with revs: [foo bar] 1005 - has any options`, 1006 }) 1007 tests.Add("return value", stringerTest{ 1008 input: &ExpectedOpenRevs{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, ret0: NewRows().AddRow(&driver.Row{Rev: "1-foo"})}, 1009 expected: `call to DB(foo#0).OpenRevs() which: 1010 - has any docID 1011 - has any revs 1012 - has any options 1013 - should return: 1 results`, 1014 }) 1015 tests.Run(t, testStringer) 1016 } 1017 1018 func TestGetAttachmentMetaString(t *testing.T) { 1019 tests := testy.NewTable() 1020 tests.Add("empty", stringerTest{ 1021 input: &ExpectedGetAttachmentMeta{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 1022 expected: `call to DB(foo#0).GetAttachmentMeta() which: 1023 - has any docID 1024 - has any filename 1025 - has any options`, 1026 }) 1027 tests.Add("docID", stringerTest{ 1028 input: &ExpectedGetAttachmentMeta{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg0: "foo"}, 1029 expected: `call to DB(foo#0).GetAttachmentMeta() which: 1030 - has docID: foo 1031 - has any filename 1032 - has any options`, 1033 }) 1034 tests.Add("filename", stringerTest{ 1035 input: &ExpectedGetAttachmentMeta{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg1: "foo.txt"}, 1036 expected: `call to DB(foo#0).GetAttachmentMeta() which: 1037 - has any docID 1038 - has filename: foo.txt 1039 - has any options`, 1040 }) 1041 tests.Add("return value", stringerTest{ 1042 input: &ExpectedGetAttachmentMeta{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, ret0: &driver.Attachment{Filename: "foo.txt"}}, 1043 expected: `call to DB(foo#0).GetAttachmentMeta() which: 1044 - has any docID 1045 - has any filename 1046 - has any options 1047 - should return attachment: foo.txt`, 1048 }) 1049 tests.Run(t, testStringer) 1050 } 1051 1052 func TestLocalDocsString(t *testing.T) { 1053 tests := testy.NewTable() 1054 tests.Add("empty", stringerTest{ 1055 input: &ExpectedLocalDocs{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 1056 expected: `call to DB(foo#0).LocalDocs() which: 1057 - has any options`, 1058 }) 1059 tests.Add("results", stringerTest{ 1060 input: &ExpectedLocalDocs{ 1061 commonExpectation: commonExpectation{db: &DB{name: "foo"}}, 1062 ret0: &Rows{iter: iter{items: []*item{ 1063 {item: &driver.Row{}}, 1064 {item: &driver.Row{}}, 1065 {delay: 15}, 1066 {item: &driver.Row{}}, 1067 {item: &driver.Row{}}, 1068 }}}, 1069 }, 1070 expected: `call to DB(foo#0).LocalDocs() which: 1071 - has any options 1072 - should return: 4 results`, 1073 }) 1074 tests.Run(t, testStringer) 1075 } 1076 1077 func TestPurgeString(t *testing.T) { 1078 tests := testy.NewTable() 1079 tests.Add("empty", stringerTest{ 1080 input: &ExpectedPurge{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 1081 expected: `call to DB(foo#0).Purge() which: 1082 - has any docRevMap`, 1083 }) 1084 tests.Add("docRevMap", stringerTest{ 1085 input: &ExpectedPurge{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg0: map[string][]string{"foo": {"a", "b"}}}, 1086 expected: `call to DB(foo#0).Purge() which: 1087 - has docRevMap: map[foo:[a b]]`, 1088 }) 1089 tests.Add("return", stringerTest{ 1090 input: &ExpectedPurge{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, ret0: &driver.PurgeResult{Seq: 123}}, 1091 expected: `call to DB(foo#0).Purge() which: 1092 - has any docRevMap 1093 - should return result: &{123 map[]}`, 1094 }) 1095 tests.Run(t, testStringer) 1096 } 1097 1098 func TestPutAttachmentString(t *testing.T) { 1099 tests := testy.NewTable() 1100 tests.Add("empty", stringerTest{ 1101 input: &ExpectedPutAttachment{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 1102 expected: `call to DB(foo#0).PutAttachment() which: 1103 - has any docID 1104 - has any attachment 1105 - has any options`, 1106 }) 1107 tests.Add("docID", stringerTest{ 1108 input: &ExpectedPutAttachment{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg0: "foo"}, 1109 expected: `call to DB(foo#0).PutAttachment() which: 1110 - has docID: foo 1111 - has any attachment 1112 - has any options`, 1113 }) 1114 tests.Add("attachment", stringerTest{ 1115 input: &ExpectedPutAttachment{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg1: &driver.Attachment{Filename: "foo.txt"}}, 1116 expected: `call to DB(foo#0).PutAttachment() which: 1117 - has any docID 1118 - has attachment: foo.txt 1119 - has any options`, 1120 }) 1121 tests.Add("error", stringerTest{ 1122 input: &ExpectedPutAttachment{commonExpectation: commonExpectation{db: &DB{name: "foo"}, err: errors.New("foo err")}}, 1123 expected: `call to DB(foo#0).PutAttachment() which: 1124 - has any docID 1125 - has any attachment 1126 - has any options 1127 - should return error: foo err`, 1128 }) 1129 tests.Add("return value", stringerTest{ 1130 input: &ExpectedPutAttachment{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, ret0: "2-bar"}, 1131 expected: `call to DB(foo#0).PutAttachment() which: 1132 - has any docID 1133 - has any attachment 1134 - has any options 1135 - should return rev: 2-bar`, 1136 }) 1137 tests.Run(t, testStringer) 1138 } 1139 1140 func TestQueryString(t *testing.T) { 1141 tests := testy.NewTable() 1142 tests.Add("empty", stringerTest{ 1143 input: &ExpectedQuery{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 1144 expected: `call to DB(foo#0).Query() which: 1145 - has any ddocID 1146 - has any view 1147 - has any options`, 1148 }) 1149 tests.Add("docID", stringerTest{ 1150 input: &ExpectedQuery{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg0: "foo"}, 1151 expected: `call to DB(foo#0).Query() which: 1152 - has ddocID: foo 1153 - has any view 1154 - has any options`, 1155 }) 1156 tests.Add("view", stringerTest{ 1157 input: &ExpectedQuery{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg1: "1-foo"}, 1158 expected: `call to DB(foo#0).Query() which: 1159 - has any ddocID 1160 - has view: 1-foo 1161 - has any options`, 1162 }) 1163 tests.Add("results", stringerTest{ 1164 input: &ExpectedQuery{ 1165 commonExpectation: commonExpectation{db: &DB{name: "foo"}}, 1166 ret0: &Rows{iter: iter{items: []*item{ 1167 {item: &driver.Row{}}, 1168 {item: &driver.Row{}}, 1169 {delay: 15}, 1170 {item: &driver.Row{}}, 1171 {item: &driver.Row{}}, 1172 }}}, 1173 }, 1174 expected: `call to DB(foo#0).Query() which: 1175 - has any ddocID 1176 - has any view 1177 - has any options 1178 - should return: 4 results`, 1179 }) 1180 tests.Run(t, testStringer) 1181 } 1182 1183 func TestGetAttachmentString(t *testing.T) { 1184 tests := testy.NewTable() 1185 tests.Add("empty", stringerTest{ 1186 input: &ExpectedGetAttachment{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 1187 expected: `call to DB(foo#0).GetAttachment() which: 1188 - has any docID 1189 - has any filename 1190 - has any options`, 1191 }) 1192 tests.Add("docID", stringerTest{ 1193 input: &ExpectedGetAttachment{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg0: "foo"}, 1194 expected: `call to DB(foo#0).GetAttachment() which: 1195 - has docID: foo 1196 - has any filename 1197 - has any options`, 1198 }) 1199 tests.Add("filename", stringerTest{ 1200 input: &ExpectedGetAttachment{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg1: "foo.txt"}, 1201 expected: `call to DB(foo#0).GetAttachment() which: 1202 - has any docID 1203 - has filename: foo.txt 1204 - has any options`, 1205 }) 1206 tests.Add("return value", stringerTest{ 1207 input: &ExpectedGetAttachment{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, ret0: &driver.Attachment{Filename: "foo.txt"}}, 1208 expected: `call to DB(foo#0).GetAttachment() which: 1209 - has any docID 1210 - has any filename 1211 - has any options 1212 - should return attachment: foo.txt`, 1213 }) 1214 tests.Run(t, testStringer) 1215 } 1216 1217 func TestStatsString(t *testing.T) { 1218 tests := testy.NewTable() 1219 tests.Add("empty", stringerTest{ 1220 input: &ExpectedStats{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 1221 expected: `call to DB(foo#0).Stats()`, 1222 }) 1223 tests.Add("delay", stringerTest{ 1224 input: &ExpectedStats{commonExpectation: commonExpectation{db: &DB{name: "foo"}, delay: time.Second}}, 1225 expected: `call to DB(foo#0).Stats() which: 1226 - should delay for: 1s`, 1227 }) 1228 tests.Add("return value", stringerTest{ 1229 input: &ExpectedStats{ret0: &driver.DBStats{Name: "foo"}, commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 1230 expected: `call to DB(foo#0).Stats() which: 1231 - should return stats: &{foo false 0 0 0 0 0 <nil> []}`, 1232 }) 1233 tests.Add("error", stringerTest{ 1234 input: &ExpectedStats{commonExpectation: commonExpectation{db: &DB{name: "foo"}, err: errors.New("foo err")}}, 1235 expected: `call to DB(foo#0).Stats() which: 1236 - should return error: foo err`, 1237 }) 1238 tests.Run(t, testStringer) 1239 } 1240 1241 func TestBulkDocsString(t *testing.T) { 1242 tests := testy.NewTable() 1243 tests.Add("empty", stringerTest{ 1244 input: &ExpectedBulkDocs{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 1245 expected: `call to DB(foo#0).BulkDocs() which: 1246 - has any docs 1247 - has any options`, 1248 }) 1249 tests.Add("docs", stringerTest{ 1250 input: &ExpectedBulkDocs{arg0: []interface{}{1, 2, 3}, commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 1251 expected: `call to DB(foo#0).BulkDocs() which: 1252 - has: 3 docs 1253 - has any options`, 1254 }) 1255 tests.Add("delay", stringerTest{ 1256 input: &ExpectedBulkDocs{commonExpectation: commonExpectation{db: &DB{name: "foo"}, delay: time.Second}}, 1257 expected: `call to DB(foo#0).BulkDocs() which: 1258 - has any docs 1259 - has any options 1260 - should delay for: 1s`, 1261 }) 1262 tests.Add("return value", stringerTest{ 1263 input: &ExpectedBulkDocs{ 1264 commonExpectation: commonExpectation{db: &DB{name: "foo"}}, 1265 ret0: []driver.BulkResult{ 1266 {}, 1267 {}, 1268 {}, 1269 }, 1270 }, 1271 expected: `call to DB(foo#0).BulkDocs() which: 1272 - has any docs 1273 - has any options 1274 - should return: 3 results`, 1275 }) 1276 tests.Add("error", stringerTest{ 1277 input: &ExpectedBulkDocs{commonExpectation: commonExpectation{db: &DB{name: "foo"}, err: errors.New("foo err")}}, 1278 expected: `call to DB(foo#0).BulkDocs() which: 1279 - has any docs 1280 - has any options 1281 - should return error: foo err`, 1282 }) 1283 tests.Run(t, testStringer) 1284 } 1285 1286 func TestChangesString(t *testing.T) { 1287 tests := testy.NewTable() 1288 tests.Add("empty", stringerTest{ 1289 input: &ExpectedChanges{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 1290 expected: `call to DB(foo#0).Changes() which: 1291 - has any options`, 1292 }) 1293 tests.Add("results", stringerTest{ 1294 input: &ExpectedChanges{ 1295 commonExpectation: commonExpectation{db: &DB{name: "foo"}}, 1296 ret0: &Changes{iter: iter{items: []*item{ 1297 {item: &driver.Change{}}, 1298 {item: &driver.Change{}}, 1299 {delay: 15}, 1300 {item: &driver.Change{}}, 1301 {item: &driver.Change{}}, 1302 }}}, 1303 }, 1304 expected: `call to DB(foo#0).Changes() which: 1305 - has any options 1306 - should return: 4 results`, 1307 }) 1308 tests.Run(t, testStringer) 1309 } 1310 1311 func TestDBUpdatesString(t *testing.T) { 1312 tests := testy.NewTable() 1313 tests.Add("empty", stringerTest{ 1314 input: &ExpectedDBUpdates{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 1315 expected: `call to DBUpdates()`, 1316 }) 1317 tests.Add("results", stringerTest{ 1318 input: &ExpectedDBUpdates{ 1319 commonExpectation: commonExpectation{db: &DB{name: "foo"}}, 1320 ret0: &Updates{iter: iter{items: []*item{ 1321 {item: &driver.DBUpdate{}}, 1322 {item: &driver.DBUpdate{}}, 1323 {delay: 15}, 1324 {item: &driver.DBUpdate{}}, 1325 {item: &driver.DBUpdate{}}, 1326 }}}, 1327 }, 1328 expected: `call to DBUpdates() which: 1329 - should return: 4 results`, 1330 }) 1331 tests.Run(t, testStringer) 1332 } 1333 1334 func TestConfigString(t *testing.T) { 1335 tests := testy.NewTable() 1336 tests.Add("empty", stringerTest{ 1337 input: &ExpectedConfig{}, 1338 expected: `call to Config() which: 1339 - has any node`, 1340 }) 1341 tests.Add("node", stringerTest{ 1342 input: &ExpectedConfig{arg0: "local"}, 1343 expected: `call to Config() which: 1344 - has node: local`, 1345 }) 1346 tests.Add("results", stringerTest{ 1347 input: &ExpectedConfig{ret0: driver.Config{"foo": driver.ConfigSection{"bar": "baz"}}}, 1348 expected: `call to Config() which: 1349 - has any node 1350 - should return: map[foo:map[bar:baz]]`, 1351 }) 1352 1353 tests.Run(t, testStringer) 1354 } 1355 1356 func TestConfigSectionString(t *testing.T) { 1357 tests := testy.NewTable() 1358 tests.Add("empty", stringerTest{ 1359 input: &ExpectedConfigSection{}, 1360 expected: `call to ConfigSection() which: 1361 - has any node 1362 - has any section`, 1363 }) 1364 tests.Add("full", stringerTest{ 1365 input: &ExpectedConfigSection{arg0: "local", arg1: "httpd"}, 1366 expected: `call to ConfigSection() which: 1367 - has node: local 1368 - has section: httpd`, 1369 }) 1370 tests.Add("results", stringerTest{ 1371 input: &ExpectedConfigSection{ret0: driver.ConfigSection{"bar": "baz"}}, 1372 expected: `call to ConfigSection() which: 1373 - has any node 1374 - has any section 1375 - should return: map[bar:baz]`, 1376 }) 1377 1378 tests.Run(t, testStringer) 1379 } 1380 1381 func TestConfigValueString(t *testing.T) { 1382 tests := testy.NewTable() 1383 tests.Add("empty", stringerTest{ 1384 input: &ExpectedConfigValue{}, 1385 expected: `call to ConfigValue() which: 1386 - has any node 1387 - has any section 1388 - has any key`, 1389 }) 1390 tests.Add("full", stringerTest{ 1391 input: &ExpectedConfigValue{arg0: "local", arg1: "httpd", arg2: "foo"}, 1392 expected: `call to ConfigValue() which: 1393 - has node: local 1394 - has section: httpd 1395 - has key: foo`, 1396 }) 1397 tests.Add("results", stringerTest{ 1398 input: &ExpectedConfigValue{ret0: "baz"}, 1399 expected: `call to ConfigValue() which: 1400 - has any node 1401 - has any section 1402 - has any key 1403 - should return: baz`, 1404 }) 1405 1406 tests.Run(t, testStringer) 1407 } 1408 1409 func TestSetConfigValueString(t *testing.T) { 1410 tests := testy.NewTable() 1411 tests.Add("empty", stringerTest{ 1412 input: &ExpectedSetConfigValue{}, 1413 expected: `call to SetConfigValue() which: 1414 - has any node 1415 - has any section 1416 - has any key 1417 - has any value`, 1418 }) 1419 tests.Add("full", stringerTest{ 1420 input: &ExpectedSetConfigValue{arg0: "local", arg1: "httpd", arg2: "foo", arg3: "bar"}, 1421 expected: `call to SetConfigValue() which: 1422 - has node: local 1423 - has section: httpd 1424 - has key: foo 1425 - has value: bar`, 1426 }) 1427 tests.Add("results", stringerTest{ 1428 input: &ExpectedSetConfigValue{ret0: "baz"}, 1429 expected: `call to SetConfigValue() which: 1430 - has any node 1431 - has any section 1432 - has any key 1433 - has any value 1434 - should return: baz`, 1435 }) 1436 1437 tests.Run(t, testStringer) 1438 } 1439 1440 func TestDeleteConfigKeyString(t *testing.T) { 1441 tests := testy.NewTable() 1442 tests.Add("empty", stringerTest{ 1443 input: &ExpectedDeleteConfigKey{}, 1444 expected: `call to DeleteConfigKey() which: 1445 - has any node 1446 - has any section 1447 - has any key`, 1448 }) 1449 tests.Add("full", stringerTest{ 1450 input: &ExpectedDeleteConfigKey{arg0: "local", arg1: "httpd", arg2: "foo"}, 1451 expected: `call to DeleteConfigKey() which: 1452 - has node: local 1453 - has section: httpd 1454 - has key: foo`, 1455 }) 1456 tests.Add("results", stringerTest{ 1457 input: &ExpectedDeleteConfigKey{ret0: "baz"}, 1458 expected: `call to DeleteConfigKey() which: 1459 - has any node 1460 - has any section 1461 - has any key 1462 - should return: baz`, 1463 }) 1464 1465 tests.Run(t, testStringer) 1466 } 1467 1468 func TestRevsDiffString(t *testing.T) { 1469 tests := testy.NewTable() 1470 tests.Add("empty", stringerTest{ 1471 input: &ExpectedRevsDiff{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 1472 expected: `call to DB(foo#0).RevsDiff() which: 1473 - has any revMap`, 1474 }) 1475 tests.Add("revMap", stringerTest{ 1476 input: &ExpectedRevsDiff{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg0: map[string][]string{"foo": {"1", "2"}}}, 1477 expected: `call to DB(foo#0).RevsDiff() which: 1478 - with revMap: map[foo:[1 2]]`, 1479 }) 1480 tests.Add("results", stringerTest{ 1481 input: &ExpectedRevsDiff{ 1482 commonExpectation: commonExpectation{db: &DB{name: "foo"}}, 1483 ret0: &Rows{}, 1484 }, 1485 expected: `call to DB(foo#0).RevsDiff() which: 1486 - has any revMap 1487 - should return: 0 results`, 1488 }) 1489 1490 tests.Run(t, testStringer) 1491 } 1492 1493 func TestPartitionStatsString(t *testing.T) { 1494 tests := testy.NewTable() 1495 tests.Add("empty", stringerTest{ 1496 input: &ExpectedPartitionStats{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 1497 expected: `call to DB(foo#0).PartitionStats() which: 1498 - has any name`, 1499 }) 1500 tests.Add("name", stringerTest{ 1501 input: &ExpectedPartitionStats{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, arg0: "foo"}, 1502 expected: `call to DB(foo#0).PartitionStats() which: 1503 - with name: foo`, 1504 }) 1505 tests.Add("error", stringerTest{ 1506 input: &ExpectedPartitionStats{commonExpectation: commonExpectation{db: &DB{name: "foo"}, err: errors.New("foo err")}}, 1507 expected: `call to DB(foo#0).PartitionStats() which: 1508 - has any name 1509 - should return error: foo err`, 1510 }) 1511 tests.Add("delay", stringerTest{ 1512 input: &ExpectedPartitionStats{commonExpectation: commonExpectation{db: &DB{name: "foo"}, delay: time.Second}}, 1513 expected: `call to DB(foo#0).PartitionStats() which: 1514 - has any name 1515 - should delay for: 1s`, 1516 }) 1517 tests.Add("return", stringerTest{ 1518 input: &ExpectedPartitionStats{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, ret0: &driver.PartitionStats{DBName: "foo"}}, 1519 expected: `call to DB(foo#0).PartitionStats() which: 1520 - has any name 1521 - should return: {"DBName":"foo","DocCount":0,"DeletedDocCount":0,"Partition":"","ActiveSize":0,"ExternalSize":0,"RawResponse":null}`, 1522 }) 1523 tests.Run(t, testStringer) 1524 } 1525 1526 func TestSecurityString(t *testing.T) { 1527 tests := testy.NewTable() 1528 tests.Add("empty", stringerTest{ 1529 input: &ExpectedSecurity{commonExpectation: commonExpectation{db: &DB{name: "foo"}}}, 1530 expected: `call to DB(foo#0).Security()`, 1531 }) 1532 tests.Add("error", stringerTest{ 1533 input: &ExpectedSecurity{commonExpectation: commonExpectation{db: &DB{name: "foo"}, err: errors.New("foo err")}}, 1534 expected: `call to DB(foo#0).Security() which: 1535 - should return error: foo err`, 1536 }) 1537 tests.Add("delay", stringerTest{ 1538 input: &ExpectedSecurity{commonExpectation: commonExpectation{db: &DB{name: "foo"}, delay: time.Second}}, 1539 expected: `call to DB(foo#0).Security() which: 1540 - should delay for: 1s`, 1541 }) 1542 tests.Add("return", stringerTest{ 1543 input: &ExpectedSecurity{commonExpectation: commonExpectation{db: &DB{name: "foo"}}, ret0: &driver.Security{Admins: driver.Members{Names: []string{"bob", "alice"}}}}, 1544 expected: `call to DB(foo#0).Security() which: 1545 - should return: {"admins":{"names":["bob","alice"]}}`, 1546 }) 1547 tests.Run(t, testStringer) 1548 }