MCPcopy Index your code
hub / github.com/upper/db / TestInsertIntoArtistsTable

Method TestInsertIntoArtistsTable

internal/testsuite/sql_suite.go:384–467  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

382}
383
384func (s *SQLTestSuite) TestInsertIntoArtistsTable() {
385 sess := s.Session()
386
387 artist := sess.Collection("artist")
388
389 err := artist.Truncate()
390 s.NoError(err)
391
392 itemMap := map[string]string{
393 "name": "Ozzie",
394 }
395
396 record, err := artist.Insert(itemMap)
397 s.NoError(err)
398 s.NotNil(record)
399
400 if pk, ok := record.ID().(int64); !ok || pk == 0 {
401 s.T().Errorf("Expecting an ID.")
402 }
403
404 // Attempt to append a struct.
405 itemStruct := struct {
406 Name string `db:"name"`
407 }{
408 "Flea",
409 }
410
411 record, err = artist.Insert(itemStruct)
412 s.NoError(err)
413 s.NotNil(record)
414
415 if pk, ok := record.ID().(int64); !ok || pk == 0 {
416 s.T().Errorf("Expecting an ID.")
417 }
418
419 // Attempt to append a tagged struct.
420 itemStruct2 := struct {
421 ArtistName string `db:"name"`
422 }{
423 "Slash",
424 }
425
426 record, err = artist.Insert(&itemStruct2)
427 s.NoError(err)
428 s.NotNil(record)
429
430 if pk, ok := record.ID().(int64); !ok || pk == 0 {
431 s.T().Errorf("Expecting an ID.")
432 }
433
434 itemStruct3 := artistType{
435 Name: "Janus",
436 }
437 record, err = artist.Insert(&itemStruct3)
438 s.NoError(err)
439 if s.Adapter() != "ql" {
440 s.NotZero(record) // QL always inserts an ID.
441 }

Callers

nothing calls this directly

Calls 11

OrMethod · 0.80
SessionMethod · 0.65
CollectionMethod · 0.65
TruncateMethod · 0.65
InsertMethod · 0.65
IDMethod · 0.65
ErrorfMethod · 0.65
AdapterMethod · 0.65
CountMethod · 0.65
FindMethod · 0.65
AndMethod · 0.65

Tested by

no test coverage detected