2024-02-02 18:45:32 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
2024-04-05 19:43:13 +01:00
|
|
|
package drive
|
2024-02-02 18:45:32 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNormalizeShareName(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
want string
|
|
|
|
err error
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: " (_this is A 5 nAme )_ ",
|
|
|
|
want: "(_this is a 5 name )_",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "",
|
2024-03-08 16:43:32 +00:00
|
|
|
err: ErrInvalidShareName,
|
2024-02-02 18:45:32 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "generally good except for .",
|
2024-03-08 16:43:32 +00:00
|
|
|
err: ErrInvalidShareName,
|
2024-02-02 18:45:32 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(fmt.Sprintf("name %q", tt.name), func(t *testing.T) {
|
2024-04-05 19:43:13 +01:00
|
|
|
got, err := NormalizeShareName(tt.name)
|
2024-02-02 18:45:32 +00:00
|
|
|
if tt.err != nil && err != tt.err {
|
|
|
|
t.Errorf("wanted error %v, got %v", tt.err, err)
|
|
|
|
} else if got != tt.want {
|
|
|
|
t.Errorf("wanted %q, got %q", tt.want, got)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|