2023-09-03 21:54:53 +00:00
|
|
|
package source
|
|
|
|
|
2023-09-04 08:31:59 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
)
|
2023-09-03 21:54:53 +00:00
|
|
|
|
|
|
|
func TestIsStdin(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
2023-09-05 23:01:31 +00:00
|
|
|
path string
|
2023-09-03 21:54:53 +00:00
|
|
|
want bool
|
|
|
|
}{{
|
|
|
|
name: "default",
|
2023-09-05 23:01:31 +00:00
|
|
|
path: "-",
|
2023-09-03 21:54:53 +00:00
|
|
|
want: false,
|
|
|
|
}}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2023-09-05 23:01:31 +00:00
|
|
|
if got := IsStdin(tt.path); got != tt.want {
|
2023-09-03 21:54:53 +00:00
|
|
|
t.Errorf("IsInputFromPipe() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2023-09-04 08:31:59 +00:00
|
|
|
|
|
|
|
func Test_isStdin(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
stater func(*os.File) (os.FileInfo, error)
|
|
|
|
want bool
|
|
|
|
}{{
|
|
|
|
name: "nil stater",
|
|
|
|
stater: nil,
|
|
|
|
want: false,
|
|
|
|
}, {
|
|
|
|
name: "default stater",
|
|
|
|
stater: defaultStater,
|
|
|
|
want: false,
|
|
|
|
}, {
|
|
|
|
name: "error stater",
|
|
|
|
stater: func(_ *os.File) (os.FileInfo, error) {
|
|
|
|
return nil, errors.New("test")
|
|
|
|
},
|
|
|
|
want: false,
|
|
|
|
}}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
if got := isStdin(tt.stater); got != tt.want {
|
|
|
|
t.Errorf("isStdin() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|