How to use Modifier method of input Package

Best Rod code snippet using input.Modifier

gallery_test.go

Source:gallery_test.go Github

copy

Full Screen

...113 const galleryIdx = 1114 galleryPath := getGalleryStringValue(galleryIdx, "Path")115 pathCriterion := models.StringCriterionInput{116 Value: galleryPath,117 Modifier: models.CriterionModifierEquals,118 }119 verifyGalleriesPath(t, r.Gallery(), pathCriterion)120 pathCriterion.Modifier = models.CriterionModifierNotEquals121 verifyGalleriesPath(t, r.Gallery(), pathCriterion)122 pathCriterion.Modifier = models.CriterionModifierMatchesRegex123 pathCriterion.Value = "gallery.*1_Path"124 verifyGalleriesPath(t, r.Gallery(), pathCriterion)125 pathCriterion.Modifier = models.CriterionModifierNotMatchesRegex126 verifyGalleriesPath(t, r.Gallery(), pathCriterion)127 return nil128 })129}130func verifyGalleriesPath(t *testing.T, sqb models.GalleryReader, pathCriterion models.StringCriterionInput) {131 galleryFilter := models.GalleryFilterType{132 Path: &pathCriterion,133 }134 galleries, _, err := sqb.Query(&galleryFilter, nil)135 if err != nil {136 t.Errorf("Error querying gallery: %s", err.Error())137 }138 for _, gallery := range galleries {139 verifyNullString(t, gallery.Path, pathCriterion)140 }141}142func TestGalleryQueryPathOr(t *testing.T) {143 const gallery1Idx = 1144 const gallery2Idx = 2145 gallery1Path := getGalleryStringValue(gallery1Idx, "Path")146 gallery2Path := getGalleryStringValue(gallery2Idx, "Path")147 galleryFilter := models.GalleryFilterType{148 Path: &models.StringCriterionInput{149 Value: gallery1Path,150 Modifier: models.CriterionModifierEquals,151 },152 Or: &models.GalleryFilterType{153 Path: &models.StringCriterionInput{154 Value: gallery2Path,155 Modifier: models.CriterionModifierEquals,156 },157 },158 }159 withTxn(func(r models.Repository) error {160 sqb := r.Gallery()161 galleries := queryGallery(t, sqb, &galleryFilter, nil)162 assert.Len(t, galleries, 2)163 assert.Equal(t, gallery1Path, galleries[0].Path.String)164 assert.Equal(t, gallery2Path, galleries[1].Path.String)165 return nil166 })167}168func TestGalleryQueryPathAndRating(t *testing.T) {169 const galleryIdx = 1170 galleryPath := getGalleryStringValue(galleryIdx, "Path")171 galleryRating := getRating(galleryIdx)172 galleryFilter := models.GalleryFilterType{173 Path: &models.StringCriterionInput{174 Value: galleryPath,175 Modifier: models.CriterionModifierEquals,176 },177 And: &models.GalleryFilterType{178 Rating: &models.IntCriterionInput{179 Value: int(galleryRating.Int64),180 Modifier: models.CriterionModifierEquals,181 },182 },183 }184 withTxn(func(r models.Repository) error {185 sqb := r.Gallery()186 galleries := queryGallery(t, sqb, &galleryFilter, nil)187 assert.Len(t, galleries, 1)188 assert.Equal(t, galleryPath, galleries[0].Path.String)189 assert.Equal(t, galleryRating.Int64, galleries[0].Rating.Int64)190 return nil191 })192}193func TestGalleryQueryPathNotRating(t *testing.T) {194 const galleryIdx = 1195 galleryRating := getRating(galleryIdx)196 pathCriterion := models.StringCriterionInput{197 Value: "gallery_.*1_Path",198 Modifier: models.CriterionModifierMatchesRegex,199 }200 ratingCriterion := models.IntCriterionInput{201 Value: int(galleryRating.Int64),202 Modifier: models.CriterionModifierEquals,203 }204 galleryFilter := models.GalleryFilterType{205 Path: &pathCriterion,206 Not: &models.GalleryFilterType{207 Rating: &ratingCriterion,208 },209 }210 withTxn(func(r models.Repository) error {211 sqb := r.Gallery()212 galleries := queryGallery(t, sqb, &galleryFilter, nil)213 for _, gallery := range galleries {214 verifyNullString(t, gallery.Path, pathCriterion)215 ratingCriterion.Modifier = models.CriterionModifierNotEquals216 verifyInt64(t, gallery.Rating, ratingCriterion)217 }218 return nil219 })220}221func TestGalleryIllegalQuery(t *testing.T) {222 assert := assert.New(t)223 const galleryIdx = 1224 subFilter := models.GalleryFilterType{225 Path: &models.StringCriterionInput{226 Value: getGalleryStringValue(galleryIdx, "Path"),227 Modifier: models.CriterionModifierEquals,228 },229 }230 galleryFilter := &models.GalleryFilterType{231 And: &subFilter,232 Or: &subFilter,233 }234 withTxn(func(r models.Repository) error {235 sqb := r.Gallery()236 _, _, err := sqb.Query(galleryFilter, nil)237 assert.NotNil(err)238 galleryFilter.Or = nil239 galleryFilter.Not = &subFilter240 _, _, err = sqb.Query(galleryFilter, nil)241 assert.NotNil(err)242 galleryFilter.And = nil243 galleryFilter.Or = &subFilter244 _, _, err = sqb.Query(galleryFilter, nil)245 assert.NotNil(err)246 return nil247 })248}249func TestGalleryQueryURL(t *testing.T) {250 const sceneIdx = 1251 galleryURL := getGalleryStringValue(sceneIdx, urlField)252 urlCriterion := models.StringCriterionInput{253 Value: galleryURL,254 Modifier: models.CriterionModifierEquals,255 }256 filter := models.GalleryFilterType{257 URL: &urlCriterion,258 }259 verifyFn := func(g *models.Gallery) {260 t.Helper()261 verifyNullString(t, g.URL, urlCriterion)262 }263 verifyGalleryQuery(t, filter, verifyFn)264 urlCriterion.Modifier = models.CriterionModifierNotEquals265 verifyGalleryQuery(t, filter, verifyFn)266 urlCriterion.Modifier = models.CriterionModifierMatchesRegex267 urlCriterion.Value = "gallery_.*1_URL"268 verifyGalleryQuery(t, filter, verifyFn)269 urlCriterion.Modifier = models.CriterionModifierNotMatchesRegex270 verifyGalleryQuery(t, filter, verifyFn)271 urlCriterion.Modifier = models.CriterionModifierIsNull272 urlCriterion.Value = ""273 verifyGalleryQuery(t, filter, verifyFn)274 urlCriterion.Modifier = models.CriterionModifierNotNull275 verifyGalleryQuery(t, filter, verifyFn)276}277func verifyGalleryQuery(t *testing.T, filter models.GalleryFilterType, verifyFn func(s *models.Gallery)) {278 withTxn(func(r models.Repository) error {279 t.Helper()280 sqb := r.Gallery()281 galleries := queryGallery(t, sqb, &filter, nil)282 // assume it should find at least one283 assert.Greater(t, len(galleries), 0)284 for _, gallery := range galleries {285 verifyFn(gallery)286 }287 return nil288 })289}290func TestGalleryQueryRating(t *testing.T) {291 const rating = 3292 ratingCriterion := models.IntCriterionInput{293 Value: rating,294 Modifier: models.CriterionModifierEquals,295 }296 verifyGalleriesRating(t, ratingCriterion)297 ratingCriterion.Modifier = models.CriterionModifierNotEquals298 verifyGalleriesRating(t, ratingCriterion)299 ratingCriterion.Modifier = models.CriterionModifierGreaterThan300 verifyGalleriesRating(t, ratingCriterion)301 ratingCriterion.Modifier = models.CriterionModifierLessThan302 verifyGalleriesRating(t, ratingCriterion)303 ratingCriterion.Modifier = models.CriterionModifierIsNull304 verifyGalleriesRating(t, ratingCriterion)305 ratingCriterion.Modifier = models.CriterionModifierNotNull306 verifyGalleriesRating(t, ratingCriterion)307}308func verifyGalleriesRating(t *testing.T, ratingCriterion models.IntCriterionInput) {309 withTxn(func(r models.Repository) error {310 sqb := r.Gallery()311 galleryFilter := models.GalleryFilterType{312 Rating: &ratingCriterion,313 }314 galleries, _, err := sqb.Query(&galleryFilter, nil)315 if err != nil {316 t.Errorf("Error querying gallery: %s", err.Error())317 }318 for _, gallery := range galleries {319 verifyInt64(t, gallery.Rating, ratingCriterion)320 }321 return nil322 })323}324func TestGalleryQueryIsMissingScene(t *testing.T) {325 withTxn(func(r models.Repository) error {326 qb := r.Gallery()327 isMissing := "scenes"328 galleryFilter := models.GalleryFilterType{329 IsMissing: &isMissing,330 }331 q := getGalleryStringValue(galleryIdxWithScene, titleField)332 findFilter := models.FindFilterType{333 Q: &q,334 }335 galleries, _, err := qb.Query(&galleryFilter, &findFilter)336 if err != nil {337 t.Errorf("Error querying gallery: %s", err.Error())338 }339 assert.Len(t, galleries, 0)340 findFilter.Q = nil341 galleries, _, err = qb.Query(&galleryFilter, &findFilter)342 if err != nil {343 t.Errorf("Error querying gallery: %s", err.Error())344 }345 // ensure non of the ids equal the one with gallery346 for _, gallery := range galleries {347 assert.NotEqual(t, galleryIDs[galleryIdxWithScene], gallery.ID)348 }349 return nil350 })351}352func queryGallery(t *testing.T, sqb models.GalleryReader, galleryFilter *models.GalleryFilterType, findFilter *models.FindFilterType) []*models.Gallery {353 galleries, _, err := sqb.Query(galleryFilter, findFilter)354 if err != nil {355 t.Errorf("Error querying gallery: %s", err.Error())356 }357 return galleries358}359func TestGalleryQueryIsMissingStudio(t *testing.T) {360 withTxn(func(r models.Repository) error {361 sqb := r.Gallery()362 isMissing := "studio"363 galleryFilter := models.GalleryFilterType{364 IsMissing: &isMissing,365 }366 q := getGalleryStringValue(galleryIdxWithStudio, titleField)367 findFilter := models.FindFilterType{368 Q: &q,369 }370 galleries := queryGallery(t, sqb, &galleryFilter, &findFilter)371 assert.Len(t, galleries, 0)372 findFilter.Q = nil373 galleries = queryGallery(t, sqb, &galleryFilter, &findFilter)374 // ensure non of the ids equal the one with studio375 for _, gallery := range galleries {376 assert.NotEqual(t, galleryIDs[galleryIdxWithStudio], gallery.ID)377 }378 return nil379 })380}381func TestGalleryQueryIsMissingPerformers(t *testing.T) {382 withTxn(func(r models.Repository) error {383 sqb := r.Gallery()384 isMissing := "performers"385 galleryFilter := models.GalleryFilterType{386 IsMissing: &isMissing,387 }388 q := getGalleryStringValue(galleryIdxWithPerformer, titleField)389 findFilter := models.FindFilterType{390 Q: &q,391 }392 galleries := queryGallery(t, sqb, &galleryFilter, &findFilter)393 assert.Len(t, galleries, 0)394 findFilter.Q = nil395 galleries = queryGallery(t, sqb, &galleryFilter, &findFilter)396 assert.True(t, len(galleries) > 0)397 // ensure non of the ids equal the one with movies398 for _, gallery := range galleries {399 assert.NotEqual(t, galleryIDs[galleryIdxWithPerformer], gallery.ID)400 }401 return nil402 })403}404func TestGalleryQueryIsMissingTags(t *testing.T) {405 withTxn(func(r models.Repository) error {406 sqb := r.Gallery()407 isMissing := "tags"408 galleryFilter := models.GalleryFilterType{409 IsMissing: &isMissing,410 }411 q := getGalleryStringValue(galleryIdxWithTwoTags, titleField)412 findFilter := models.FindFilterType{413 Q: &q,414 }415 galleries := queryGallery(t, sqb, &galleryFilter, &findFilter)416 assert.Len(t, galleries, 0)417 findFilter.Q = nil418 galleries = queryGallery(t, sqb, &galleryFilter, &findFilter)419 assert.True(t, len(galleries) > 0)420 return nil421 })422}423func TestGalleryQueryIsMissingDate(t *testing.T) {424 withTxn(func(r models.Repository) error {425 sqb := r.Gallery()426 isMissing := "date"427 galleryFilter := models.GalleryFilterType{428 IsMissing: &isMissing,429 }430 galleries := queryGallery(t, sqb, &galleryFilter, nil)431 // three in four scenes have no date432 assert.Len(t, galleries, int(math.Ceil(float64(totalGalleries)/4*3)))433 // ensure date is null, empty or "0001-01-01"434 for _, g := range galleries {435 assert.True(t, !g.Date.Valid || g.Date.String == "" || g.Date.String == "0001-01-01")436 }437 return nil438 })439}440func TestGalleryQueryPerformers(t *testing.T) {441 withTxn(func(r models.Repository) error {442 sqb := r.Gallery()443 performerCriterion := models.MultiCriterionInput{444 Value: []string{445 strconv.Itoa(performerIDs[performerIdxWithGallery]),446 strconv.Itoa(performerIDs[performerIdx1WithGallery]),447 },448 Modifier: models.CriterionModifierIncludes,449 }450 galleryFilter := models.GalleryFilterType{451 Performers: &performerCriterion,452 }453 galleries := queryGallery(t, sqb, &galleryFilter, nil)454 assert.Len(t, galleries, 2)455 // ensure ids are correct456 for _, gallery := range galleries {457 assert.True(t, gallery.ID == galleryIDs[galleryIdxWithPerformer] || gallery.ID == galleryIDs[galleryIdxWithTwoPerformers])458 }459 performerCriterion = models.MultiCriterionInput{460 Value: []string{461 strconv.Itoa(performerIDs[performerIdx1WithGallery]),462 strconv.Itoa(performerIDs[performerIdx2WithGallery]),463 },464 Modifier: models.CriterionModifierIncludesAll,465 }466 galleries = queryGallery(t, sqb, &galleryFilter, nil)467 assert.Len(t, galleries, 1)468 assert.Equal(t, galleryIDs[galleryIdxWithTwoPerformers], galleries[0].ID)469 performerCriterion = models.MultiCriterionInput{470 Value: []string{471 strconv.Itoa(performerIDs[performerIdx1WithGallery]),472 },473 Modifier: models.CriterionModifierExcludes,474 }475 q := getGalleryStringValue(galleryIdxWithTwoPerformers, titleField)476 findFilter := models.FindFilterType{477 Q: &q,478 }479 galleries = queryGallery(t, sqb, &galleryFilter, &findFilter)480 assert.Len(t, galleries, 0)481 return nil482 })483}484func TestGalleryQueryTags(t *testing.T) {485 withTxn(func(r models.Repository) error {486 sqb := r.Gallery()487 tagCriterion := models.HierarchicalMultiCriterionInput{488 Value: []string{489 strconv.Itoa(tagIDs[tagIdxWithGallery]),490 strconv.Itoa(tagIDs[tagIdx1WithGallery]),491 },492 Modifier: models.CriterionModifierIncludes,493 }494 galleryFilter := models.GalleryFilterType{495 Tags: &tagCriterion,496 }497 galleries := queryGallery(t, sqb, &galleryFilter, nil)498 assert.Len(t, galleries, 2)499 // ensure ids are correct500 for _, gallery := range galleries {501 assert.True(t, gallery.ID == galleryIDs[galleryIdxWithTag] || gallery.ID == galleryIDs[galleryIdxWithTwoTags])502 }503 tagCriterion = models.HierarchicalMultiCriterionInput{504 Value: []string{505 strconv.Itoa(tagIDs[tagIdx1WithGallery]),506 strconv.Itoa(tagIDs[tagIdx2WithGallery]),507 },508 Modifier: models.CriterionModifierIncludesAll,509 }510 galleries = queryGallery(t, sqb, &galleryFilter, nil)511 assert.Len(t, galleries, 1)512 assert.Equal(t, galleryIDs[galleryIdxWithTwoTags], galleries[0].ID)513 tagCriterion = models.HierarchicalMultiCriterionInput{514 Value: []string{515 strconv.Itoa(tagIDs[tagIdx1WithGallery]),516 },517 Modifier: models.CriterionModifierExcludes,518 }519 q := getGalleryStringValue(galleryIdxWithTwoTags, titleField)520 findFilter := models.FindFilterType{521 Q: &q,522 }523 galleries = queryGallery(t, sqb, &galleryFilter, &findFilter)524 assert.Len(t, galleries, 0)525 return nil526 })527}528func TestGalleryQueryStudio(t *testing.T) {529 withTxn(func(r models.Repository) error {530 sqb := r.Gallery()531 studioCriterion := models.HierarchicalMultiCriterionInput{532 Value: []string{533 strconv.Itoa(studioIDs[studioIdxWithGallery]),534 },535 Modifier: models.CriterionModifierIncludes,536 }537 galleryFilter := models.GalleryFilterType{538 Studios: &studioCriterion,539 }540 galleries := queryGallery(t, sqb, &galleryFilter, nil)541 assert.Len(t, galleries, 1)542 // ensure id is correct543 assert.Equal(t, galleryIDs[galleryIdxWithStudio], galleries[0].ID)544 studioCriterion = models.HierarchicalMultiCriterionInput{545 Value: []string{546 strconv.Itoa(studioIDs[studioIdxWithGallery]),547 },548 Modifier: models.CriterionModifierExcludes,549 }550 q := getGalleryStringValue(galleryIdxWithStudio, titleField)551 findFilter := models.FindFilterType{552 Q: &q,553 }554 galleries = queryGallery(t, sqb, &galleryFilter, &findFilter)555 assert.Len(t, galleries, 0)556 return nil557 })558}559func TestGalleryQueryStudioDepth(t *testing.T) {560 withTxn(func(r models.Repository) error {561 sqb := r.Gallery()562 depth := 2563 studioCriterion := models.HierarchicalMultiCriterionInput{564 Value: []string{565 strconv.Itoa(studioIDs[studioIdxWithGrandChild]),566 },567 Modifier: models.CriterionModifierIncludes,568 Depth: &depth,569 }570 galleryFilter := models.GalleryFilterType{571 Studios: &studioCriterion,572 }573 galleries := queryGallery(t, sqb, &galleryFilter, nil)574 assert.Len(t, galleries, 1)575 depth = 1576 galleries = queryGallery(t, sqb, &galleryFilter, nil)577 assert.Len(t, galleries, 0)578 studioCriterion.Value = []string{strconv.Itoa(studioIDs[studioIdxWithParentAndChild])}579 galleries = queryGallery(t, sqb, &galleryFilter, nil)580 assert.Len(t, galleries, 1)581 // ensure id is correct582 assert.Equal(t, galleryIDs[galleryIdxWithGrandChildStudio], galleries[0].ID)583 depth = 2584 studioCriterion = models.HierarchicalMultiCriterionInput{585 Value: []string{586 strconv.Itoa(studioIDs[studioIdxWithGrandChild]),587 },588 Modifier: models.CriterionModifierExcludes,589 Depth: &depth,590 }591 q := getGalleryStringValue(galleryIdxWithGrandChildStudio, pathField)592 findFilter := models.FindFilterType{593 Q: &q,594 }595 galleries = queryGallery(t, sqb, &galleryFilter, &findFilter)596 assert.Len(t, galleries, 0)597 depth = 1598 galleries = queryGallery(t, sqb, &galleryFilter, &findFilter)599 assert.Len(t, galleries, 1)600 studioCriterion.Value = []string{strconv.Itoa(studioIDs[studioIdxWithParentAndChild])}601 galleries = queryGallery(t, sqb, &galleryFilter, &findFilter)602 assert.Len(t, galleries, 0)603 return nil604 })605}606func TestGalleryQueryPerformerTags(t *testing.T) {607 withTxn(func(r models.Repository) error {608 sqb := r.Gallery()609 tagCriterion := models.HierarchicalMultiCriterionInput{610 Value: []string{611 strconv.Itoa(tagIDs[tagIdxWithPerformer]),612 strconv.Itoa(tagIDs[tagIdx1WithPerformer]),613 },614 Modifier: models.CriterionModifierIncludes,615 }616 galleryFilter := models.GalleryFilterType{617 PerformerTags: &tagCriterion,618 }619 galleries := queryGallery(t, sqb, &galleryFilter, nil)620 assert.Len(t, galleries, 2)621 // ensure ids are correct622 for _, gallery := range galleries {623 assert.True(t, gallery.ID == galleryIDs[galleryIdxWithPerformerTag] || gallery.ID == galleryIDs[galleryIdxWithPerformerTwoTags])624 }625 tagCriterion = models.HierarchicalMultiCriterionInput{626 Value: []string{627 strconv.Itoa(tagIDs[tagIdx1WithPerformer]),628 strconv.Itoa(tagIDs[tagIdx2WithPerformer]),629 },630 Modifier: models.CriterionModifierIncludesAll,631 }632 galleries = queryGallery(t, sqb, &galleryFilter, nil)633 assert.Len(t, galleries, 1)634 assert.Equal(t, galleryIDs[galleryIdxWithPerformerTwoTags], galleries[0].ID)635 tagCriterion = models.HierarchicalMultiCriterionInput{636 Value: []string{637 strconv.Itoa(tagIDs[tagIdx1WithPerformer]),638 },639 Modifier: models.CriterionModifierExcludes,640 }641 q := getGalleryStringValue(galleryIdxWithPerformerTwoTags, titleField)642 findFilter := models.FindFilterType{643 Q: &q,644 }645 galleries = queryGallery(t, sqb, &galleryFilter, &findFilter)646 assert.Len(t, galleries, 0)647 tagCriterion = models.HierarchicalMultiCriterionInput{648 Modifier: models.CriterionModifierIsNull,649 }650 q = getGalleryStringValue(galleryIdx1WithImage, titleField)651 galleries = queryGallery(t, sqb, &galleryFilter, &findFilter)652 assert.Len(t, galleries, 1)653 assert.Equal(t, galleryIDs[galleryIdx1WithImage], galleries[0].ID)654 q = getGalleryStringValue(galleryIdxWithPerformerTag, titleField)655 galleries = queryGallery(t, sqb, &galleryFilter, &findFilter)656 assert.Len(t, galleries, 0)657 tagCriterion.Modifier = models.CriterionModifierNotNull658 galleries = queryGallery(t, sqb, &galleryFilter, &findFilter)659 assert.Len(t, galleries, 1)660 assert.Equal(t, galleryIDs[galleryIdxWithPerformerTag], galleries[0].ID)661 q = getGalleryStringValue(galleryIdx1WithImage, titleField)662 galleries = queryGallery(t, sqb, &galleryFilter, &findFilter)663 assert.Len(t, galleries, 0)664 return nil665 })666}667func TestGalleryQueryTagCount(t *testing.T) {668 const tagCount = 1669 tagCountCriterion := models.IntCriterionInput{670 Value: tagCount,671 Modifier: models.CriterionModifierEquals,672 }673 verifyGalleriesTagCount(t, tagCountCriterion)674 tagCountCriterion.Modifier = models.CriterionModifierNotEquals675 verifyGalleriesTagCount(t, tagCountCriterion)676 tagCountCriterion.Modifier = models.CriterionModifierGreaterThan677 verifyGalleriesTagCount(t, tagCountCriterion)678 tagCountCriterion.Modifier = models.CriterionModifierLessThan679 verifyGalleriesTagCount(t, tagCountCriterion)680}681func verifyGalleriesTagCount(t *testing.T, tagCountCriterion models.IntCriterionInput) {682 withTxn(func(r models.Repository) error {683 sqb := r.Gallery()684 galleryFilter := models.GalleryFilterType{685 TagCount: &tagCountCriterion,686 }687 galleries := queryGallery(t, sqb, &galleryFilter, nil)688 assert.Greater(t, len(galleries), 0)689 for _, gallery := range galleries {690 ids, err := sqb.GetTagIDs(gallery.ID)691 if err != nil {692 return err693 }694 verifyInt(t, len(ids), tagCountCriterion)695 }696 return nil697 })698}699func TestGalleryQueryPerformerCount(t *testing.T) {700 const performerCount = 1701 performerCountCriterion := models.IntCriterionInput{702 Value: performerCount,703 Modifier: models.CriterionModifierEquals,704 }705 verifyGalleriesPerformerCount(t, performerCountCriterion)706 performerCountCriterion.Modifier = models.CriterionModifierNotEquals707 verifyGalleriesPerformerCount(t, performerCountCriterion)708 performerCountCriterion.Modifier = models.CriterionModifierGreaterThan709 verifyGalleriesPerformerCount(t, performerCountCriterion)710 performerCountCriterion.Modifier = models.CriterionModifierLessThan711 verifyGalleriesPerformerCount(t, performerCountCriterion)712}713func verifyGalleriesPerformerCount(t *testing.T, performerCountCriterion models.IntCriterionInput) {714 withTxn(func(r models.Repository) error {715 sqb := r.Gallery()716 galleryFilter := models.GalleryFilterType{717 PerformerCount: &performerCountCriterion,718 }719 galleries := queryGallery(t, sqb, &galleryFilter, nil)720 assert.Greater(t, len(galleries), 0)721 for _, gallery := range galleries {722 ids, err := sqb.GetPerformerIDs(gallery.ID)723 if err != nil {724 return err725 }726 verifyInt(t, len(ids), performerCountCriterion)727 }728 return nil729 })730}731func TestGalleryQueryAverageResolution(t *testing.T) {732 withTxn(func(r models.Repository) error {733 qb := r.Gallery()734 resolution := models.ResolutionEnumLow735 galleryFilter := models.GalleryFilterType{736 AverageResolution: &models.ResolutionCriterionInput{737 Value: resolution,738 Modifier: models.CriterionModifierEquals,739 },740 }741 // not verifying average - just ensure we get at least one742 galleries := queryGallery(t, qb, &galleryFilter, nil)743 assert.Greater(t, len(galleries), 0)744 return nil745 })746}747func TestGalleryQueryImageCount(t *testing.T) {748 const imageCount = 0749 imageCountCriterion := models.IntCriterionInput{750 Value: imageCount,751 Modifier: models.CriterionModifierEquals,752 }753 verifyGalleriesImageCount(t, imageCountCriterion)754 imageCountCriterion.Modifier = models.CriterionModifierNotEquals755 verifyGalleriesImageCount(t, imageCountCriterion)756 imageCountCriterion.Modifier = models.CriterionModifierGreaterThan757 verifyGalleriesImageCount(t, imageCountCriterion)758 imageCountCriterion.Modifier = models.CriterionModifierLessThan759 verifyGalleriesImageCount(t, imageCountCriterion)760}761func verifyGalleriesImageCount(t *testing.T, imageCountCriterion models.IntCriterionInput) {762 withTxn(func(r models.Repository) error {763 sqb := r.Gallery()764 galleryFilter := models.GalleryFilterType{765 ImageCount: &imageCountCriterion,766 }767 galleries := queryGallery(t, sqb, &galleryFilter, nil)768 assert.Greater(t, len(galleries), -1)769 for _, gallery := range galleries {770 pp := 0771 result, err := r.Image().Query(models.ImageQueryOptions{772 QueryOptions: models.QueryOptions{773 FindFilter: &models.FindFilterType{774 PerPage: &pp,775 },776 Count: true,777 },778 ImageFilter: &models.ImageFilterType{779 Galleries: &models.MultiCriterionInput{780 Value: []string{strconv.Itoa(gallery.ID)},781 Modifier: models.CriterionModifierIncludes,782 },783 },784 })785 if err != nil {786 return err787 }788 verifyInt(t, result.Count, imageCountCriterion)789 }790 return nil791 })792}793// TODO Count794// TODO All795// TODO Query...

Full Screen

Full Screen

filterFactory.go

Source:filterFactory.go Github

copy

Full Screen

...97 }98 config.action = action99 errInvalid := fmt.Errorf("invalid input (%s), the modifier for \"daily\" can be either \"market_ids\" or \"account_ids\" like so 'daily:market_ids=[4c19915f47,db4531d586]' or 'daily:account_ids=[account1,account2]' or 'daily:market_ids=[4c19915f47,db4531d586]:account_ids=[account1,account2]'", configInput)100 if len(limitWindowParts) == 2 {101 e = addModifierToConfig(config, limitWindowParts[1])102 if e != nil {103 return nil, fmt.Errorf("%s: could not addModifierToConfig for %s: %s", errInvalid, limitWindowParts[1], e)104 }105 } else if len(limitWindowParts) == 3 {106 e = addModifierToConfig(config, limitWindowParts[1])107 if e != nil {108 return nil, fmt.Errorf("%s: could not addModifierToConfig for %s: %s", errInvalid, limitWindowParts[1], e)109 }110 e = addModifierToConfig(config, limitWindowParts[2])111 if e != nil {112 return nil, fmt.Errorf("%s: could not addModifierToConfig for %s: %s", errInvalid, limitWindowParts[2], e)113 }114 } else if len(limitWindowParts) != 1 {115 return nil, fmt.Errorf("invalid input (%s), the second part needs to be \"daily\" and can have only one modifier \"market_ids\" like so 'daily:market_ids=[4c19915f47,db4531d586]'", configInput)116 }117 limit, e := strconv.ParseFloat(parts[4], 64)118 if e != nil {119 return nil, fmt.Errorf("could not parse the fourth part as a float value from config value (%s): %s", configInput, e)120 }121 if parts[3] == "base" {122 config.BaseAssetCapInBaseUnits = &limit123 } else if parts[3] == "quote" {124 config.BaseAssetCapInQuoteUnits = &limit125 } else {126 return nil, fmt.Errorf("invalid input (%s), the third part needs to be \"base\" or \"quote\"", configInput)127 }128 if e = config.Validate(); e != nil {129 return nil, fmt.Errorf("invalid input (%s), did not pass validation: %s", configInput, e)130 }131 return config, nil132}133func addModifierToConfig(config *VolumeFilterConfig, modifierMapping string) error {134 ids, modifierType, e := parseVolumeFilterModifier(modifierMapping)135 if e != nil {136 return fmt.Errorf("could not parseVolumeFilterModifier: %s", e)137 }138 if modifierType == "market_ids" {139 config.additionalMarketIDs = ids140 return nil141 } else if modifierType == "account_ids" {142 config.optionalAccountIDs = ids143 return nil144 }145 return fmt.Errorf("programmer error? invalid modifier type '%s', should have thrown an error above when calling parseVolumeFilterModifier", modifierType)146}147func parseVolumeFilterModifier(modifierMapping string) ([]string, string, error) {148 modifierParts := strings.Split(modifierMapping, "=")149 if len(modifierParts) != 2 {150 return nil, "", fmt.Errorf("invalid parts for modifier with length %d, should have been 2", len(modifierParts))151 }152 ids, e := parseIdsArray(modifierParts[1])153 if e != nil {154 return nil, "", fmt.Errorf("%s", e)155 }156 if strings.HasPrefix(modifierMapping, "market_ids=") {157 if len(ids) == 0 {158 return nil, "market_ids", fmt.Errorf("array length required to be greater than 0")159 }160 for _, id := range ids {161 if !filterIDRegex.MatchString(id) {...

Full Screen

Full Screen

filterFactory_test.go

Source:filterFactory_test.go Github

copy

Full Screen

...37 assert.Equal(t, kase.want, output)38 })39 }40}41func TestParseVolumeFilterModifier(t *testing.T) {42 testCases := []struct {43 modifierMapping string44 wantIds []string45 wantModifierType string46 wantError error47 }{48 {49 modifierMapping: "market_ids=[abcde1234Z,01234gFHij]",50 wantIds: []string{"abcde1234Z", "01234gFHij"},51 wantModifierType: "market_ids",52 wantError: nil,53 }, {54 modifierMapping: "account_ids=[abcde1234Z,01234gFHij]",55 wantIds: []string{"abcde1234Z", "01234gFHij"},56 wantModifierType: "account_ids",57 wantError: nil,58 }, {59 modifierMapping: "market_ids=[abcde,01234]",60 wantIds: nil,61 wantModifierType: "market_ids",62 wantError: fmt.Errorf("invalid id entry 'abcde'"),63 }, {64 modifierMapping: "market_ids=[abcde1234Z,01234]",65 wantIds: nil,66 wantModifierType: "market_ids",67 wantError: fmt.Errorf("invalid id entry '01234'"),68 }, {69 modifierMapping: "account_ids=[abcde1234Z,01234]",70 wantIds: []string{"abcde1234Z", "01234"},71 wantModifierType: "account_ids",72 wantError: nil,73 }, {74 modifierMapping: "account_ids=[abcde,01234]",75 wantIds: []string{"abcde", "01234"},76 wantModifierType: "account_ids",77 wantError: nil,78 }, {79 modifierMapping: "market_ids=[]",80 wantIds: nil,81 wantModifierType: "market_ids",82 wantError: fmt.Errorf("array length required to be greater than 0"),83 }, {84 modifierMapping: "account_ids=[]",85 wantIds: []string{},86 wantModifierType: "account_ids",87 wantError: nil,88 },89 }90 for _, k := range testCases {91 t.Run(k.modifierMapping, func(t *testing.T) {92 ids, modifierType, e := parseVolumeFilterModifier(k.modifierMapping)93 assert.Equal(t, k.wantError, e)94 assert.Equal(t, k.wantIds, ids)95 assert.Equal(t, k.wantModifierType, modifierType)96 })97 }98}99func TestAddModifierToConfig(t *testing.T) {100 testCases := []struct {101 modifierMapping string102 wantConfig *VolumeFilterConfig103 }{104 {105 modifierMapping: "market_ids=[abcde1234Z]",106 wantConfig: &VolumeFilterConfig{additionalMarketIDs: []string{"abcde1234Z"}},107 }, {108 modifierMapping: "account_ids=[accountX]",109 wantConfig: &VolumeFilterConfig{optionalAccountIDs: []string{"accountX"}},110 },111 }112 for _, k := range testCases {113 t.Run(k.modifierMapping, func(t *testing.T) {114 config := &VolumeFilterConfig{}115 e := addModifierToConfig(config, k.modifierMapping)116 if !assert.NoError(t, e) {117 return118 }119 assertVolumeFilterConfigEqual(t, k.wantConfig, config)120 })121 }122}123func TestMakeVolumeFilterConfig(t *testing.T) {124 testCases := []struct {125 configInput string126 wantError error127 wantConfig *VolumeFilterConfig128 }{129 // the first %s represents the action (buy or sell), the second %s represents mode (exact or ignore)...

Full Screen

Full Screen

Modifier

Using AI Code Generation

copy

Full Screen

1import "fmt"2type input struct {3}4func (i *input) Modifier(a int, b int) {5}6func main() {7 i := input{2, 3}8 fmt.Println(i.a, i.b)9 i.Modifier(4, 5)10 fmt.Println(i.a, i.b)11}

Full Screen

Full Screen

Modifier

Using AI Code Generation

copy

Full Screen

1import "fmt"2type Input struct {3}4func (i *Input) Modifier() {5}6func main() {7 i := Input{"Sam", 20}8 i.Modifier()9 fmt.Println("Name:", i.name, "Age:", i.age)10}11import "fmt"12type Input struct {13}14func (i *Input) Modifier() {15}16func main() {17 i := &Input{"Sam", 20}18 i.Modifier()19 fmt.Println("Name:", i.name, "Age:", i.age)20}21import "fmt"22type Input struct {23}24func (i *Input) Modifier() {25}26func main() {27 i := &Input{"Sam", 20}28 i.Modifier()29 fmt.Println("Name:", i.name, "Age:", i.age)30}31import "fmt"32type Input struct {33}34func (i *Input) Modifier() {35}

Full Screen

Full Screen

Modifier

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 input = Input{1, 2}4 input.Modifier(3, 4)5 fmt.Println(input)6}7import "fmt"8func main() {9 input = Input{1, 2}10 input.Modifier(3, 4)11 fmt.Println(input)12}13import "fmt"14func main() {15 input = Input{1, 2}16 input.Modifier(3, 4)17 fmt.Println(input)18}19import "fmt"20func main() {21 input = Input{1, 2}22 input.Modifier(3, 4)23 fmt.Println(input)24}25import "fmt"26func main() {27 input = Input{1, 2}28 input.Modifier(3, 4)29 fmt.Println(input)30}31import "fmt"32func main() {33 input = Input{1, 2}34 input.Modifier(3, 4)35 fmt.Println(input)36}37import "fmt"38func main() {39 input = Input{1, 2}40 input.Modifier(3, 4)41 fmt.Println(input)42}43import "fmt"44func main() {45 input = Input{1, 2}46 input.Modifier(3, 4)47 fmt.Println(input)48}49import "fmt"50func main() {51 input = Input{1, 2}

Full Screen

Full Screen

Modifier

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 a := input{5}4 a.Modifier(10)5 fmt.Println(a)6}7type input struct {8}9func (i *input) Modifier(x int) {10}

Full Screen

Full Screen

Modifier

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "input"3func main() {4 fmt.Println("Enter a number: ")5 fmt.Scan(&a)6 b := input.Modifier(a)7 fmt.Println("Modified Value: ", b)8}9func Modifier(a int) int {

Full Screen

Full Screen

Modifier

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 input1 := input{number: 1}4 input1.Modifier()5 fmt.Println(input1.number)6}

Full Screen

Full Screen

Modifier

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 i = input{0}4 i.Modifier(5)5 fmt.Println(i)6}7type input struct {8}9func (i *input) Modifier(j int) {10}11I'm trying to create a function that takes a slice, and returns a slice of the same type, but with the elements in reverse order. I'm trying to do this without using append() or creating a new slice. Here is my code:12func Reverse(s []int) []int {13 for i := 0; i < len(s); i++ {14 s[i] = s[len(s)-i-1]15 s[len(s)-i-1] = temp16 }17}18func main() {19 var s []int = make([]int, 10)20 for i := 0; i < 10; i++ {21 }22 fmt.Println(s)23 fmt.Println(Reverse(s))24}25main.Reverse(0xc0000a2000, 0xa, 0x10, 0x10, 0x10, 0x0)26main.main()27func Count(s string) map[string]int {

Full Screen

Full Screen

Modifier

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 test := input.Input{}4 test.Modifier("hello world")5 fmt.Println(test.Value)6}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Rod automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful