Files
my-rook-config/pkg/operator/k8sutil/volume_test.go
T

58 lines
2.1 KiB
Go
Raw Normal View History

2019-01-28 17:39:10 -07:00
/*
Copyright 2016 The Rook Authors. All rights reserved.
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 k8sutil for Kubernetes helpers.
package k8sutil
import "testing"
func TestPathToVolumeName(t *testing.T) {
tests := []struct {
name string // test name
path string // argument
want string
}{
{"simple", "simple", "simple"},
{"preceding slash", "/preceding", "preceding"},
{"trailing slash", "trailing/", "trailing"},
{"convert to lower case", "ASDFGHJKLQWERTYUIOPZXCVBNM", "asdfghjklqwertyuiopzxcvbnm"},
{"preserve nums", "0123456789", "0123456789"},
{"preserve lower case", "qwertyuiopasdfghjklzxcvbnm", "qwertyuiopasdfghjklzxcvbnm"},
2025-03-13 15:24:58 -07:00
{
"convert any non-lower-case-alphanum symbols to dash",
2019-01-28 17:39:10 -07:00
"a/.;,=[]_~!@`#$%^&*()_+-<>?:\"\\'|}{z", // symbols on U.S. keyboard
2025-03-13 15:24:58 -07:00
"a---------------------------------z",
},
{
"various currency symbols", // only those written left-to-right
2019-01-28 17:39:10 -07:00
"z£¢©®™¥€§฿₽₨₱¤₡₫ƒ₲₴₭č₾֏₣лвдине₤₺₼₥₦₱៛₹₪৳₸₩ła",
2025-03-13 15:24:58 -07:00
"z------------------------------------------a",
},
2019-01-28 17:39:10 -07:00
{"full-width symbols", "q¢¥₩℃℉p", "q-----p"}, // only those written left-to-right
2025-03-13 15:24:58 -07:00
{
"longer than 63 chars", // if you change the arg string, the hash on the end will change
2019-01-28 17:39:10 -07:00
"/this/is/some-path/.that/is_longer/than/$63/chars/1234567890/and/i'm/still/typing",
2025-03-13 15:24:58 -07:00
"this-is-some-path--that-i---7890-and-i-m-still-typing-b6b6f18b",
},
2019-01-28 17:39:10 -07:00
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := PathToVolumeName(tt.path); got != tt.want {
t.Errorf("PathToVolumeName() = %v, want %v", got, tt.want)
}
})
}
}