go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/resultdb/internal/invocations/id_test.go (about) 1 // Copyright 2020 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 invocations 16 17 import ( 18 "testing" 19 20 "cloud.google.com/go/spanner" 21 22 "go.chromium.org/luci/resultdb/internal/spanutil" 23 24 . "github.com/smartystreets/goconvey/convey" 25 ) 26 27 func TestSpannerConversion(t *testing.T) { 28 t.Parallel() 29 Convey(`ID`, t, func() { 30 var b spanutil.Buffer 31 32 Convey(`ID`, func() { 33 id := ID("a") 34 So(id.ToSpanner(), ShouldEqual, "ca978112:a") 35 36 row, err := spanner.NewRow([]string{"a"}, []any{id.ToSpanner()}) 37 So(err, ShouldBeNil) 38 var actual ID 39 err = b.FromSpanner(row, &actual) 40 So(err, ShouldBeNil) 41 So(actual, ShouldEqual, id) 42 }) 43 44 Convey(`IDSet`, func() { 45 ids := NewIDSet("a", "b") 46 So(ids.ToSpanner(), ShouldResemble, []string{"3e23e816:b", "ca978112:a"}) 47 48 row, err := spanner.NewRow([]string{"a"}, []any{ids.ToSpanner()}) 49 So(err, ShouldBeNil) 50 var actual IDSet 51 err = b.FromSpanner(row, &actual) 52 So(err, ShouldBeNil) 53 So(actual, ShouldResemble, ids) 54 }) 55 }) 56 }