| 110 | } |
| 111 | |
| 112 | func TestGetPlugin(t *testing.T) { |
| 113 | dir := fs.NewDir(t, t.Name(), |
| 114 | fs.WithFile("docker-bbb", ` |
| 115 | #!/bin/sh |
| 116 | echo '{"SchemaVersion":"0.1.0"}'`, fs.WithMode(0o777)), |
| 117 | fs.WithFile("docker-aaa", ` |
| 118 | #!/bin/sh |
| 119 | echo '{"SchemaVersion":"0.1.0"}'`, fs.WithMode(0o777)), |
| 120 | ) |
| 121 | defer dir.Remove() |
| 122 | |
| 123 | cli := test.NewFakeCli(nil) |
| 124 | cli.SetConfigFile(&configfile.ConfigFile{CLIPluginsExtraDirs: []string{dir.Path()}}) |
| 125 | |
| 126 | plugin, err := GetPlugin("bbb", cli, &cobra.Command{}) |
| 127 | assert.NilError(t, err) |
| 128 | assert.Equal(t, plugin.Name, "bbb") |
| 129 | |
| 130 | _, err = GetPlugin("ccc", cli, &cobra.Command{}) |
| 131 | assert.Error(t, err, "Error: No such CLI plugin: ccc") |
| 132 | assert.Assert(t, errdefs.IsNotFound(err)) |
| 133 | } |
| 134 | |
| 135 | func TestListPluginsIsSorted(t *testing.T) { |
| 136 | dir := fs.NewDir(t, t.Name(), |