74 lines
1.2 KiB
Go
74 lines
1.2 KiB
Go
|
/*
|
||
|
* 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, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||
|
*/
|
||
|
|
||
|
package fifo
|
||
|
|
||
|
import (
|
||
|
"os"
|
||
|
"path/filepath"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
"github.com/stretchr/testify/require"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
TempDir = ""
|
||
|
Pattern = "kdnotify_fifo_*"
|
||
|
)
|
||
|
|
||
|
func Test_Open(t *testing.T) {
|
||
|
t.Parallel()
|
||
|
cxt := NewCxt(t)
|
||
|
defer cxt.Cleanup()
|
||
|
|
||
|
p := cxt.NewPath("open.fifo")
|
||
|
fifo, err := MkPipe(p)
|
||
|
|
||
|
assert.NoError(t, err)
|
||
|
assert.NotNil(t, fifo)
|
||
|
}
|
||
|
|
||
|
func Test_Existing(t *testing.T) {
|
||
|
t.Parallel()
|
||
|
cxt := NewCxt(t)
|
||
|
defer cxt.Cleanup()
|
||
|
|
||
|
p := cxt.NewPath("existing.fifo")
|
||
|
|
||
|
f1, err := MkPipe(p)
|
||
|
assert.NoError(t, err)
|
||
|
|
||
|
f2, err := MkPipe(p)
|
||
|
assert.NoError(t, err)
|
||
|
|
||
|
assert.NotNil(t, f1)
|
||
|
assert.NotNil(t, f2)
|
||
|
}
|
||
|
|
||
|
func NewCxt(t *testing.T) *TestCxt {
|
||
|
dir, err := os.MkdirTemp(TempDir, Pattern)
|
||
|
require.NoError(t, err)
|
||
|
|
||
|
return &TestCxt{Path: dir}
|
||
|
}
|
||
|
|
||
|
type TestCxt struct {
|
||
|
Path string
|
||
|
}
|
||
|
|
||
|
func (c *TestCxt) NewPath(rest ...string) string {
|
||
|
rest = append(rest, "")
|
||
|
copy(rest[1:], rest[0:])
|
||
|
rest[0] = c.Path
|
||
|
|
||
|
return filepath.Join(rest...)
|
||
|
}
|
||
|
|
||
|
func (c *TestCxt) Cleanup() {
|
||
|
os.RemoveAll(c.Path)
|
||
|
}
|