1
// Copyright 2023 The CubeFS Authors.
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
7
// http://www.apache.org/licenses/LICENSE-2.0
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
12
// implied. See the License for the specific language governing
13
// permissions and limitations under the License.
20
"github.com/stretchr/testify/assert"
23
func TestKeyController(t *testing.T) {
24
k := NewKeyRateLimit()
25
key1, key2, key3 := "10001", "10002", "10003"
27
assert.Equal(t, 1, k.current[key1].refCount)
29
assert.Equal(t, 2, k.current[key1].refCount)
32
assert.Equal(t, 2, len(k.current))
34
assert.Equal(t, 3, len(k.current))
37
assert.Equal(t, 1, k.current[key1].refCount)
38
assert.Equal(t, 3, len(k.current))
40
_, ok := k.current[key1]
41
assert.Equal(t, false, ok)
42
assert.Equal(t, 2, len(k.current))
44
assert.Equal(t, 1, len(k.current))
46
assert.Equal(t, 0, len(k.current))
48
assert.Panics(t, func() {