go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/server/quota/internal/quotakeys/asi_test.go (about) 1 // Copyright 2022 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 quotakeys 16 17 import ( 18 "testing" 19 20 . "github.com/smartystreets/goconvey/convey" 21 . "go.chromium.org/luci/common/testing/assertions" 22 ) 23 24 func TestASI(t *testing.T) { 25 t.Parallel() 26 27 s := func(strs ...string) []string { 28 return strs 29 } 30 31 Convey(`ASI`, t, func() { 32 Convey(`happy path`, func() { 33 tests := []struct { 34 name string 35 in []string 36 out string 37 }{ 38 {name: "empty"}, 39 {name: "single (basic)", in: s("hello"), out: "hello"}, 40 {name: "multi (basic)", in: s("hello", "there"), out: "hello|there"}, 41 {name: "single (enc)", in: s("~single~"), out: "{IWK4@B5D.."}, 42 {name: "multi (enc)", in: s("stuff", "{escape pls}", "more"), out: "stuff|{HY%8.@;od#E,9TD|more"}, 43 } 44 45 for _, tc := range tests { 46 tc := tc 47 Convey(tc.name, func() { 48 SoMsg("encode", AssembleASI(tc.in...), ShouldResemble, tc.out) 49 dec, err := DecodeASI(tc.out) 50 So(err, ShouldBeNil) 51 SoMsg("decode", dec, ShouldResemble, tc.in) 52 }) 53 } 54 }) 55 Convey(`error`, func() { 56 _, err := DecodeASI("{notre~lascii85") 57 So(err, ShouldErrLike, "DecodeASI: section[0]: illegal ascii85 data at input byte 5") 58 }) 59 }) 60 }