2019-08-22 19:45:04 +00:00
|
|
|
/*
|
|
|
|
Copyright 2019 The Kubernetes 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 lock
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
2019-11-14 18:57:11 +00:00
|
|
|
func TestUserMutexSpec(t *testing.T) {
|
|
|
|
forceID = "test"
|
|
|
|
|
2019-08-22 20:19:56 +00:00
|
|
|
var tests = []struct {
|
2019-08-22 19:45:04 +00:00
|
|
|
description string
|
2019-08-22 20:19:56 +00:00
|
|
|
path string
|
|
|
|
expected string
|
2019-08-22 19:45:04 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
description: "standard",
|
2019-08-22 20:19:56 +00:00
|
|
|
path: "/foo/bar",
|
2019-11-14 18:57:11 +00:00
|
|
|
expected: "mfoo-bar-test",
|
2019-08-22 19:45:04 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "deep directory",
|
2019-08-22 20:19:56 +00:00
|
|
|
path: "/foo/bar/baz/bat",
|
2019-11-14 18:57:11 +00:00
|
|
|
expected: "mfoo-bar-baz-bat-test",
|
2019-08-22 19:45:04 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "underscores",
|
2019-08-22 20:19:56 +00:00
|
|
|
path: "/foo_bar/baz",
|
2019-11-14 18:57:11 +00:00
|
|
|
expected: "mfoo-bar-baz-test",
|
2019-08-22 19:45:04 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "starts with number",
|
2019-08-22 20:19:56 +00:00
|
|
|
path: "/foo/2bar/baz",
|
2019-11-14 18:57:11 +00:00
|
|
|
expected: "mfoo-2bar-baz-test",
|
2019-08-22 19:45:04 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "starts with punctuation",
|
2019-08-22 20:19:56 +00:00
|
|
|
path: "/.foo/bar",
|
2019-11-14 18:57:11 +00:00
|
|
|
expected: "mfoo-bar-test",
|
2019-08-22 19:45:04 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "long filename",
|
2019-08-22 20:19:56 +00:00
|
|
|
path: "/very-very-very-very-very-very-very-very-long/bar",
|
2019-11-14 18:57:11 +00:00
|
|
|
expected: "m-very-very-very-very-very-long-bar-test",
|
2019-08-22 19:45:04 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range tests {
|
|
|
|
t.Run(tc.description, func(t *testing.T) {
|
2019-11-14 18:57:11 +00:00
|
|
|
got := UserMutexSpec(tc.path)
|
|
|
|
if got.Name != tc.expected {
|
|
|
|
t.Errorf("%s mutex name = %q, expected %q", tc.path, got.Name, tc.expected)
|
2019-08-22 19:45:04 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2019-08-22 20:19:56 +00:00
|
|
|
}
|