mirror of
https://github.com/rclone/rclone.git
synced 2024-12-25 13:33:40 +08:00
5d6b8141ec
As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code.
110 lines
2.6 KiB
Go
110 lines
2.6 KiB
Go
package genautocomplete
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestCompletionBash(t *testing.T) {
|
|
tempFile, err := os.CreateTemp("", "completion_bash")
|
|
assert.NoError(t, err)
|
|
defer func() {
|
|
_ = tempFile.Close()
|
|
_ = os.Remove(tempFile.Name())
|
|
}()
|
|
|
|
bashCommandDefinition.Run(bashCommandDefinition, []string{tempFile.Name()})
|
|
|
|
bs, err := os.ReadFile(tempFile.Name())
|
|
assert.NoError(t, err)
|
|
assert.NotEmpty(t, string(bs))
|
|
}
|
|
|
|
func TestCompletionBashStdout(t *testing.T) {
|
|
originalStdout := os.Stdout
|
|
tempFile, err := os.CreateTemp("", "completion_zsh")
|
|
assert.NoError(t, err)
|
|
defer func() {
|
|
_ = tempFile.Close()
|
|
_ = os.Remove(tempFile.Name())
|
|
}()
|
|
|
|
os.Stdout = tempFile
|
|
defer func() { os.Stdout = originalStdout }()
|
|
|
|
bashCommandDefinition.Run(bashCommandDefinition, []string{"-"})
|
|
|
|
output, err := os.ReadFile(tempFile.Name())
|
|
assert.NoError(t, err)
|
|
assert.NotEmpty(t, string(output))
|
|
}
|
|
|
|
func TestCompletionZsh(t *testing.T) {
|
|
tempFile, err := os.CreateTemp("", "completion_zsh")
|
|
assert.NoError(t, err)
|
|
defer func() {
|
|
_ = tempFile.Close()
|
|
_ = os.Remove(tempFile.Name())
|
|
}()
|
|
|
|
zshCommandDefinition.Run(zshCommandDefinition, []string{tempFile.Name()})
|
|
|
|
bs, err := os.ReadFile(tempFile.Name())
|
|
assert.NoError(t, err)
|
|
assert.NotEmpty(t, string(bs))
|
|
}
|
|
|
|
func TestCompletionZshStdout(t *testing.T) {
|
|
originalStdout := os.Stdout
|
|
tempFile, err := os.CreateTemp("", "completion_zsh")
|
|
assert.NoError(t, err)
|
|
defer func() {
|
|
_ = tempFile.Close()
|
|
_ = os.Remove(tempFile.Name())
|
|
}()
|
|
|
|
os.Stdout = tempFile
|
|
defer func() { os.Stdout = originalStdout }()
|
|
|
|
zshCommandDefinition.Run(zshCommandDefinition, []string{"-"})
|
|
output, err := os.ReadFile(tempFile.Name())
|
|
assert.NoError(t, err)
|
|
assert.NotEmpty(t, string(output))
|
|
}
|
|
|
|
func TestCompletionFish(t *testing.T) {
|
|
tempFile, err := os.CreateTemp("", "completion_fish")
|
|
assert.NoError(t, err)
|
|
defer func() {
|
|
_ = tempFile.Close()
|
|
_ = os.Remove(tempFile.Name())
|
|
}()
|
|
|
|
fishCommandDefinition.Run(fishCommandDefinition, []string{tempFile.Name()})
|
|
|
|
bs, err := os.ReadFile(tempFile.Name())
|
|
assert.NoError(t, err)
|
|
assert.NotEmpty(t, string(bs))
|
|
}
|
|
|
|
func TestCompletionFishStdout(t *testing.T) {
|
|
originalStdout := os.Stdout
|
|
tempFile, err := os.CreateTemp("", "completion_zsh")
|
|
assert.NoError(t, err)
|
|
defer func() {
|
|
_ = tempFile.Close()
|
|
_ = os.Remove(tempFile.Name())
|
|
}()
|
|
|
|
os.Stdout = tempFile
|
|
defer func() { os.Stdout = originalStdout }()
|
|
|
|
fishCommandDefinition.Run(fishCommandDefinition, []string{"-"})
|
|
|
|
output, err := os.ReadFile(tempFile.Name())
|
|
assert.NoError(t, err)
|
|
assert.NotEmpty(t, string(output))
|
|
}
|