File: all_test.go

package info (click to toggle)
golang-github-cznic-fileutil 0.0~git20150708.0.1c9c88f-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 392 kB
  • sloc: makefile: 21
file content (39 lines) | stat: -rw-r--r-- 625 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (c) 2014 The fileutil Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package fileutil

import (
	"os"
	"path/filepath"
	"strings"
	"testing"
)

func TestTempFile(t *testing.T) {
	f, err := TempFile("", "abc", "mno.xyz")
	if err != nil {
		t.Fatal(err)
	}

	n := f.Name()
	t.Log(n)
	defer func() {
		f.Close()
		os.Remove(n)
	}()

	base := filepath.Base(n)
	if base == "abcmno.xyz" {
		t.Fatal(base)
	}

	if !strings.HasPrefix(base, "abc") {
		t.Fatal(base)
	}

	if !strings.HasSuffix(base, "mno.xyz") {
		t.Fatal(base)
	}
}