github.com/kubearmor/cilium@v1.6.12/proxylib/memcached/binary/parser_test.go (about) 1 // Copyright 2018 Authors of Cilium 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 // +build !privileged_tests 16 17 package binary 18 19 import ( 20 "testing" 21 22 . "gopkg.in/check.v1" 23 ) 24 25 func Test(t *testing.T) { TestingT(t) } 26 27 type BinaryMemcachedTestSuite struct{} 28 29 var _ = Suite(&BinaryMemcachedTestSuite{}) 30 31 func (k *BinaryMemcachedTestSuite) TestMemcacheGetKey(c *C) { 32 packet := []byte{ 33 0x80, 0, 0, 0x5, 34 0, 0, 0, 0, 35 0, 0, 0, 0x5, 36 0, 0, 0, 0, 37 0, 0, 0, 0, 38 0, 0, 0, 0, 39 'T', 'e', 's', 't', 40 '1', 41 } 42 43 key := getMemcacheKey(packet, 0, 5) 44 45 c.Assert(string(key), Equals, "Test1") 46 47 packet = []byte{ 48 0x80, 0, 0, 0x5, 49 0x4, 0, 0, 0, 50 0, 0, 0, 0x5, 51 0, 0, 0, 0, 52 0, 0, 0, 0, 53 0, 0, 0, 0, 54 'e', 'x', 't', 'r', 55 'T', 'e', 's', 't', 56 '1', 57 } 58 59 key = getMemcacheKey(packet, 4, 5) 60 61 c.Assert(string(key), Equals, "Test1") 62 63 packet = []byte{ 64 0x80, 0x8, 0, 0x0, 65 0x4, 0, 0, 0, 66 0, 0, 0, 0x4, 67 0, 0, 0, 0, 68 0, 0, 0, 0, 69 0, 0, 0, 0, 70 0, 0, 0x1c, 0x20, 71 } 72 73 key = getMemcacheKey(packet, 4, 0) 74 75 c.Assert(string(key), Equals, "") 76 }