mirror of
https://github.com/restic/restic.git
synced 2026-02-03 12:29:37 -05:00
Rough steps: ``` mv cmd/restic/global* cmd/restic/secondary_repo* internal/global/ sed -i "s/package main/package global/" internal/global/*.go Rename "GlobalOptions" to "Options" in internal/global/ Replace everywhere " GlobalOptions" -> " global.Options" Replace everywhere "\*GlobalOptions" -> " *global.Options" Make SecondaryRepoOptions public Make create public Make version public ```
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/restic/restic/internal/global"
|
|
rtest "github.com/restic/restic/internal/test"
|
|
)
|
|
|
|
func testRunGenerate(t testing.TB, gopts global.Options, opts generateOptions) ([]byte, error) {
|
|
buf, err := withCaptureStdout(t, gopts, func(ctx context.Context, gopts global.Options) error {
|
|
return runGenerate(opts, gopts, []string{}, gopts.Term)
|
|
})
|
|
return buf.Bytes(), err
|
|
}
|
|
|
|
func TestGenerateStdout(t *testing.T) {
|
|
testCases := []struct {
|
|
name string
|
|
opts generateOptions
|
|
}{
|
|
{"bash", generateOptions{BashCompletionFile: "-"}},
|
|
{"fish", generateOptions{FishCompletionFile: "-"}},
|
|
{"zsh", generateOptions{ZSHCompletionFile: "-"}},
|
|
{"powershell", generateOptions{PowerShellCompletionFile: "-"}},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
output, err := testRunGenerate(t, global.Options{}, tc.opts)
|
|
rtest.OK(t, err)
|
|
rtest.Assert(t, strings.Contains(string(output), "# "+tc.name+" completion for restic"), "has no expected completion header")
|
|
})
|
|
}
|
|
|
|
t.Run("Generate shell completions to stdout for two shells", func(t *testing.T) {
|
|
_, err := testRunGenerate(t, global.Options{}, generateOptions{BashCompletionFile: "-", FishCompletionFile: "-"})
|
|
rtest.Assert(t, err != nil, "generate shell completions to stdout for two shells fails")
|
|
})
|
|
}
|