api/pkg/path/helpers_test.go
Peter Kurfer 49e58ac2e4 Add advanced matching options to HTTP handler
- move to Gitlab
- make code better testable
- create app abstraction for server
- cleanup
2020-12-26 13:11:49 +00:00

53 lines
899 B
Go

package path
import (
"fmt"
"io/ioutil"
"math/rand"
"os"
"path"
"testing"
)
func TestFileExists(t *testing.T) {
tmpFile, err := ioutil.TempFile("", "inetmock")
if err != nil {
t.Errorf("failed to create temp file: %v", err)
}
defer func() {
tmpFile.Close()
os.Remove(tmpFile.Name())
}()
type args struct {
filename string
}
tests := []struct {
name string
args args
want bool
}{
{
name: "Ensure temp file exists",
want: true,
args: args{
filename: tmpFile.Name(),
},
},
{
name: "Ensure random file name does not exist",
want: false,
args: args{
filename: path.Join(os.TempDir(), fmt.Sprintf("asdf-%d", rand.Uint32())),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := FileExists(tt.args.filename); got != tt.want {
t.Errorf("FileExists() = %v, want %v", got, tt.want)
}
})
}
}