MCPcopy
hub / github.com/cli/cli / TestImportRun

Function TestImportRun

pkg/cmd/alias/imports/import_test.go:110–350  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

108}
109
110func TestImportRun(t *testing.T) {
111 tmpFile := filepath.Join(t.TempDir(), "aliases.yml")
112 importFileMsg := fmt.Sprintf(`- Importing aliases from file %q`, tmpFile)
113 importStdinMsg := "- Importing aliases from standard input"
114
115 tests := []struct {
116 name string
117 opts *ImportOptions
118 stdin string
119 fileContents string
120 initConfig string
121 aliasCommands []*cobra.Command
122 wantConfig string
123 wantStderr string
124 }{
125 {
126 name: "with no existing aliases",
127 opts: &ImportOptions{
128 Filename: tmpFile,
129 OverwriteExisting: false,
130 },
131 fileContents: heredoc.Doc(`
132 co: pr checkout
133 igrep: '!gh issue list --label="$1" | grep "$2"'
134 `),
135 wantConfig: heredoc.Doc(`
136 aliases:
137 co: pr checkout
138 igrep: '!gh issue list --label="$1" | grep "$2"'
139 `),
140 wantStderr: importFileMsg + "\n✓ Added alias co\n✓ Added alias igrep\n\n",
141 },
142 {
143 name: "with existing aliases",
144 opts: &ImportOptions{
145 Filename: tmpFile,
146 OverwriteExisting: false,
147 },
148 fileContents: heredoc.Doc(`
149 users: |-
150 api graphql -F name="$1" -f query='
151 query ($name: String!) {
152 user(login: $name) {
153 name
154 }
155 }'
156 co: pr checkout
157 `),
158 initConfig: heredoc.Doc(`
159 aliases:
160 igrep: '!gh issue list --label="$1" | grep "$2"'
161 editor: vim
162 `),
163 aliasCommands: []*cobra.Command{
164 {Use: "igrep"},
165 },
166 wantConfig: heredoc.Doc(`
167 aliases:

Callers

nothing calls this directly

Calls 13

TestFunction · 0.92
StubWriteConfigFunction · 0.92
NewFromStringFunction · 0.92
ValidAliasNameFuncFunction · 0.92
ValidAliasExpansionFuncFunction · 0.92
importRunFunction · 0.85
JoinMethod · 0.80
SetStdinTTYMethod · 0.80
SetStdoutTTYMethod · 0.80
SetStderrTTYMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected