func TestFind(t *testing.T) {
	type findTest struct {
		name        string
		db          *db
		query       interface{}
		expectedIDs []string
		err         string
		rowsErr     string
	}
	tests := []findTest{
		{
			name:  "invalid query",
			query: make(chan int),
			err:   "json: unsupported type: chan int",
		},
		{
			name:  "Invalid JSON query",
			query: "asdf",
			err:   "invalid character 'a' looking for beginning of value",
		},
		{
			name: "No query",
			err:  "Missing required key: selector",
		},
		{
			name:  "empty selector",
			query: `{"selector":{}}`,
			db: func() *db {
				db := setupDB(t, nil)
				for _, id := range []string{"a", "c", "z", "q", "chicken"} {
					if _, err := db.Put(context.Background(), id, map[string]string{"value": id}); err != nil {
						t.Fatal(err)
					}
				}
				return db
			}(),
			expectedIDs: []string{"a", "c", "chicken", "q", "z"},
		},
		{
			name:  "simple selector",
			query: `{"selector":{"value":"chicken"}}`,
			db: func() *db {
				db := setupDB(t, nil)
				for _, id := range []string{"a", "c", "z", "q", "chicken"} {
					if _, err := db.Put(context.Background(), id, map[string]string{"value": id}); err != nil {
						t.Fatal(err)
					}
				}
				return db
			}(),
			expectedIDs: []string{"chicken"},
		},
	}
	for _, test := range tests {
		t.Run(test.name, func(t *testing.T) {
			db := test.db
			if db == nil {
				db = setupDB(t, nil)
			}
			rows, err := db.Find(context.Background(), test.query)
			var msg string
			if err != nil {
				msg = err.Error()
			}
			if msg != test.err {
				t.Errorf("Unexpected error: %s", err)
			}
			if err != nil {
				return
			}
			checkRows(t, rows, test.expectedIDs, test.rowsErr)
		})
	}
}
// TestFind tests selectors, to see that the proper doc IDs are returned.
TestFind tests selectors, to see that the proper doc IDs are returned.
// TestFind tests selectors to see that the proper doc IDs are returned .
func TestFind(t *testing.T) {
	type findTest struct {
		name        string
		db          *db
		query       interface{}
		expectedIDs []string
		err         string
		rowsErr     string
	}
	tests := []findTest{
		{
			name:  "invalid query",
			query: make(chan int),
			err:   "json: unsupported type: chan int",
		},
		{
			name:  "Invalid JSON query",
			query: "asdf",
			err:   "invalid character 'a' looking for beginning of value",
		},
		{
			name: "No query",
			err:  "Missing required key: selector",
		},
		{
			name:  "empty selector",
			query: `{"selector":{}}`,
			db: func() *db {
				db := setupDB(t, nil)
				for _, id := range []string{"a", "c", "z", "q", "chicken"} {
					if _, err := db.Put(context.Background(), id, map[string]string{"value": id}); err != nil {
						t.Fatal(err)
					}
				}
				return db
			}(),
			expectedIDs: []string{"a", "c", "chicken", "q", "z"},
		},
		{
			name:  "simple selector",
			query: `{"selector":{"value":"chicken"}}`,
			db: func() *db {
				db := setupDB(t, nil)
				for _, id := range []string{"a", "c", "z", "q", "chicken"} {
					if _, err := db.Put(context.Background(), id, map[string]string{"value": id}); err != nil {
						t.Fatal(err)
					}
				}
				return db
			}(),
			expectedIDs: []string{"chicken"},
		},
	}
	for _, test := range tests {
		t.Run(test.name, func(t *testing.T) {
			db := test.db
			if db == nil {
				db = setupDB(t, nil)
			}
			rows, err := db.Find(context.Background(), test.query)
			var msg string
			if err != nil {
				msg = err.Error()
			}
			if msg != test.err {
				t.Errorf("Unexpected error: %s", err)
			}
			if err != nil {
				return
			}
			checkRows(t, rows, test.expectedIDs, test.rowsErr)
		})
	}
}
func TestFind ( t * testing . T ) { type findTest struct { name string db * db query interface { } expectedIDs [ ] string err string rowsErr string } tests := [ ] findTest { { name : " " , query : make ( chan int ) , err : " " , } , { name : " " , query : " " , err : " " , } , { name : " " , err : " " , } , { name : " " , query : `{"selector":{}}` , db : func ( ) * db { db := setupDB ( t , nil ) for _ , id := range [ ] string { " " , " " , " " , " " , " " } { if _ , err := db . Put ( context . Background ( ) , id , map [ string ] string { " " : id } ) ; err != nil { t . Fatal ( err ) } } return db } ( ) , expectedIDs : [ ] string { " " , " " , " " , " " , " " } , } , { name : " " , query : `{"selector":{"value":"chicken"}}` , db : func ( ) * db { db := setupDB ( t , nil ) for _ , id := range [ ] string { " " , " " , " " , " " , " " } { if _ , err := db . Put ( context . Background ( ) , id , map [ string ] string { " " : id } ) ; err != nil { t . Fatal ( err ) } } return db } ( ) , expectedIDs : [ ] string { " " } , } , } for _ , test := range tests { t . Run ( test . name , func ( t * testing . T ) { db := test . db if db == nil { db = setupDB ( t , nil ) } rows , err := db . Find ( context . Background ( ) , test . query ) var msg string if err != nil { msg = err . Error ( ) } if msg != test . err { t . Errorf ( " " , err ) } if err != nil { return } checkRows ( t , rows , test . expectedIDs , test . rowsErr ) } ) } }
TestFind tests selectors, to see that the proper doc IDs are returned.
TestFind tests selectors to see that the proper doc IDs are returned .