2023-10-30 08:21:28 +00:00
|
|
|
/*
|
|
|
|
Copyright 2023 The Ceph-CSI Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-04-04 08:53:45 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2023-10-30 08:21:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestReadAffinity_ConstructReadAffinityMapOption(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
crushLocationmap map[string]string
|
|
|
|
wantAny []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "nil crushLocationmap",
|
|
|
|
crushLocationmap: nil,
|
|
|
|
wantAny: []string{""},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "empty crushLocationmap",
|
|
|
|
crushLocationmap: map[string]string{},
|
|
|
|
wantAny: []string{""},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "single entry in crushLocationmap",
|
|
|
|
crushLocationmap: map[string]string{
|
|
|
|
"region": "east",
|
|
|
|
},
|
|
|
|
wantAny: []string{"read_from_replica=localize,crush_location=region:east"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "multiple entries in crushLocationmap",
|
|
|
|
crushLocationmap: map[string]string{
|
|
|
|
"region": "east",
|
|
|
|
"zone": "east-1",
|
|
|
|
},
|
|
|
|
wantAny: []string{
|
|
|
|
"read_from_replica=localize,crush_location=region:east|zone:east-1",
|
|
|
|
"read_from_replica=localize,crush_location=zone:east-1|region:east",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
2024-04-26 08:35:01 +00:00
|
|
|
require.Contains(t, tt.wantAny, ConstructReadAffinityMapOption(tt.crushLocationmap))
|
2023-10-30 08:21:28 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|