go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/swarming/server/model/botinfo_test.go (about) 1 // Copyright 2024 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package model 16 17 import ( 18 "testing" 19 20 apipb "go.chromium.org/luci/swarming/proto/api_v2" 21 22 . "github.com/smartystreets/goconvey/convey" 23 ) 24 25 func TestBotInfoQuery(t *testing.T) { 26 t.Parallel() 27 28 Convey("Filters", t, func() { 29 q := FilterBotsByState(BotInfoQuery(), StateFilter{ 30 Quarantined: apipb.NullableBool_TRUE, 31 InMaintenance: apipb.NullableBool_TRUE, 32 IsDead: apipb.NullableBool_TRUE, 33 IsBusy: apipb.NullableBool_TRUE, 34 }) 35 36 dims, err := NewFilter([]*apipb.StringPair{ 37 {Key: "k1", Value: "v1|v2"}, 38 {Key: "k2", Value: "v1|v2"}, 39 {Key: "k3", Value: "v1"}, 40 }) 41 So(err, ShouldBeNil) 42 43 qs := FilterBotsByDimensions(q, SplitOptimally, dims) 44 So(qs, ShouldHaveLength, 2) 45 46 q1, err := qs[0].Finalize() 47 So(err, ShouldBeNil) 48 So(q1.GQL(), ShouldEqual, 49 "SELECT * FROM `BotInfo` "+ 50 "WHERE `composite` = 1 AND `composite` = 4 AND "+ 51 "`composite` = 64 AND `composite` = 256 AND "+ 52 "`dimensions_flat` = \"k1:v1\" AND `dimensions_flat` = \"k3:v1\" AND "+ 53 "`dimensions_flat` IN ARRAY(\"k2:v1\", \"k2:v2\") ORDER BY `__key__`") 54 55 q2, err := qs[1].Finalize() 56 So(err, ShouldBeNil) 57 So(q2.GQL(), ShouldEqual, 58 "SELECT * FROM `BotInfo` "+ 59 "WHERE `composite` = 1 AND `composite` = 4 AND "+ 60 "`composite` = 64 AND `composite` = 256 AND "+ 61 "`dimensions_flat` = \"k1:v2\" AND `dimensions_flat` = \"k3:v1\" AND "+ 62 "`dimensions_flat` IN ARRAY(\"k2:v1\", \"k2:v2\") ORDER BY `__key__`") 63 }) 64 }