2015-05-10 09:59:42 +00:00
|
|
|
// Copyright (C) 2015 The Syncthing Authors.
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
2017-02-09 06:52:18 +00:00
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
2015-05-10 09:59:42 +00:00
|
|
|
|
2017-09-02 05:52:38 +00:00
|
|
|
package fs
|
2015-05-10 09:59:42 +00:00
|
|
|
|
|
|
|
import (
|
2021-08-29 08:47:53 +00:00
|
|
|
"path/filepath"
|
2015-05-10 09:59:42 +00:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLongTempFilename(t *testing.T) {
|
2021-08-29 08:47:53 +00:00
|
|
|
filename := strings.Repeat("l", 300)
|
2017-01-17 07:33:48 +00:00
|
|
|
tFile := TempName(filename)
|
2021-08-29 08:47:53 +00:00
|
|
|
if len(tFile) < 10 || len(tFile) > 160 {
|
2015-05-10 09:59:42 +00:00
|
|
|
t.Fatal("Invalid long filename")
|
|
|
|
}
|
2017-01-17 07:33:48 +00:00
|
|
|
if !strings.HasSuffix(TempName("short"), "short.tmp") {
|
|
|
|
t.Fatal("Invalid short filename", TempName("short"))
|
2015-05-10 09:59:42 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-29 08:47:53 +00:00
|
|
|
|
|
|
|
func benchmarkTempName(b *testing.B, filename string) {
|
|
|
|
filename = filepath.Join("/Users/marieantoinette", filename)
|
|
|
|
|
|
|
|
b.ReportAllocs()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
TempName(filename)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkTempNameShort(b *testing.B) { benchmarkTempName(b, "somefile.txt") }
|
|
|
|
func BenchmarkTempNameLong(b *testing.B) { benchmarkTempName(b, strings.Repeat("a", 270)) }
|