go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/cv/internal/rpc/versioning/status_test.go (about) 1 // Copyright 2021 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 versioning 16 17 import ( 18 "testing" 19 20 apiv0pb "go.chromium.org/luci/cv/api/v0" 21 apiv1pb "go.chromium.org/luci/cv/api/v1" 22 "go.chromium.org/luci/cv/internal/run" 23 "go.chromium.org/luci/cv/internal/tryjob" 24 25 . "github.com/smartystreets/goconvey/convey" 26 ) 27 28 func TestStatusV1(t *testing.T) { 29 t.Parallel() 30 31 Convey("RunStatusV1 returns a valid enum", t, func() { 32 for name, val := range run.Status_value { 33 name, val := name, val 34 Convey("for internal."+name, func() { 35 eq := RunStatusV1(run.Status(val)) 36 37 // check if it's typed with the API enum. 38 So(eq.Descriptor().FullName(), ShouldEqual, 39 apiv1pb.Run_STATUS_UNSPECIFIED.Descriptor().FullName()) 40 // check if it's one of the defined enum ints. 41 _, ok := apiv1pb.Run_Status_name[int32(eq)] 42 So(ok, ShouldBeTrue) 43 }) 44 } 45 }) 46 } 47 48 func TestStatusV0(t *testing.T) { 49 t.Parallel() 50 51 Convey("RunStatusV0 returns a valid enum", t, func() { 52 for name, val := range run.Status_value { 53 name, val := name, val 54 Convey("for internal."+name, func() { 55 eq := RunStatusV0(run.Status(val)) 56 57 // check if it's typed with the API enum. 58 So(eq.Descriptor().FullName(), ShouldEqual, 59 apiv0pb.Run_STATUS_UNSPECIFIED.Descriptor().FullName()) 60 // check if it's one of the defined enum ints. 61 _, ok := apiv0pb.Run_Status_name[int32(eq)] 62 So(ok, ShouldBeTrue) 63 }) 64 } 65 }) 66 67 Convey("TryjobStatusV0 returns a valid enum", t, func() { 68 for name, val := range tryjob.Status_value { 69 name, val := name, val 70 Convey("for internal."+name, func() { 71 eq := LegacyTryjobStatusV0(tryjob.Status(val)) 72 73 // check if it's typed with the API enum. 74 So(eq.Descriptor().FullName(), ShouldEqual, 75 apiv0pb.Tryjob_STATUS_UNSPECIFIED.Descriptor().FullName()) 76 // check if it's one of the defined enum ints. 77 _, ok := apiv0pb.Tryjob_Status_name[int32(eq)] 78 So(ok, ShouldBeTrue) 79 }) 80 } 81 }) 82 83 Convey("TryjobResultStatusV0 returns a valid enum", t, func() { 84 for name, val := range tryjob.Result_Status_value { 85 name, val := name, val 86 Convey("for internal."+name, func() { 87 eq := LegacyTryjobResultStatusV0(tryjob.Result_Status(val)) 88 89 // check if it's typed with the API enum. 90 So(eq.Descriptor().FullName(), ShouldEqual, 91 apiv0pb.Tryjob_Result_RESULT_STATUS_UNSPECIFIED.Descriptor().FullName()) 92 // check if it's one of the defined enum ints. 93 _, ok := apiv0pb.Tryjob_Result_Status_name[int32(eq)] 94 So(ok, ShouldBeTrue) 95 }) 96 } 97 }) 98 }