(t *testing.T)
| 108 | } |
| 109 | |
| 110 | func 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: |
nothing calls this directly
no test coverage detected