summaryrefslogtreecommitdiffstats
path: root/client/go/util/io_test.go
blob: ddfa2e624ddfeb4fcc3f4267c2191434478752d2 (plain) (blame)
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
40
41
42
43
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package util

import (
	"os"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestPathExists(t *testing.T) {
	assert.Equal(t, true, PathExists("io.go"))
	assert.Equal(t, false, PathExists("nosuchthing.go"))

	tmpDir := t.TempDir()
	err := os.MkdirAll(tmpDir+"/no", 0755)
	assert.Nil(t, err)
	err = os.MkdirAll(tmpDir+"/no/such", 0)
	assert.Nil(t, err)
	assert.Equal(t, false, PathExists(tmpDir+"/no/such/thing.go"))
}

func TestIsDir(t *testing.T) {
	tmpDir := t.TempDir()
	err := os.MkdirAll(tmpDir+"/no", 0755)
	assert.Nil(t, err)
	assert.Equal(t, true, IsDirectory(tmpDir+"/no"))
	err = os.MkdirAll(tmpDir+"/no/such", 0)
	assert.Nil(t, err)
	assert.Equal(t, true, IsDirectory(tmpDir+"/no/such"))
	assert.Equal(t, false, IsDirectory(tmpDir+"/no/such/thing.go"))
}

func TestIsRegularFile(t *testing.T) {
	assert.Equal(t, true, IsRegularFile("io.go"))
	assert.Equal(t, false, IsRegularFile("."))
	tmpDir := t.TempDir()
	err := os.MkdirAll(tmpDir+"/no", 0755)
	assert.Nil(t, err)
	err = os.MkdirAll(tmpDir+"/no/such", 0)
	assert.Nil(t, err)
	assert.Equal(t, false, IsRegularFile(tmpDir+"/no/such/thing.go"))
}