(l *log.Logger, args []string, toolVersion, ref string)
| 943 | } |
| 944 | |
| 945 | func pluginTestCommand(l *log.Logger, args []string, toolVersion, ref string) { |
| 946 | conf, err := config.LoadConfig() |
| 947 | if err != nil { |
| 948 | l.Printf("error loading config: %s", err) |
| 949 | cli.OsExiter(1) |
| 950 | return |
| 951 | } |
| 952 | |
| 953 | if len(args) < 2 { |
| 954 | failTest(l, "please provide a plugin name and url") |
| 955 | } |
| 956 | |
| 957 | name := args[0] |
| 958 | url := args[1] |
| 959 | testName := fmt.Sprintf("asdf-test-%s", name) |
| 960 | |
| 961 | // Install plugin |
| 962 | err = plugins.Add(conf, testName, url, ref) |
| 963 | if err != nil { |
| 964 | failTest(l, fmt.Sprintf("%s was not properly installed reason: %s", name, err)) |
| 965 | } |
| 966 | |
| 967 | // Remove plugin |
| 968 | var blackhole strings.Builder |
| 969 | defer plugins.Remove(conf, testName, &blackhole, &blackhole) |
| 970 | |
| 971 | // Assert callbacks are present |
| 972 | plugin := plugins.New(conf, testName) |
| 973 | files, err := os.ReadDir(filepath.Join(plugin.Dir, "bin")) |
| 974 | if _, ok := err.(*fs.PathError); ok { |
| 975 | failTest(l, "bin/ directory does not exist") |
| 976 | } |
| 977 | |
| 978 | callbacks := []string{} |
| 979 | for _, file := range files { |
| 980 | callbacks = append(callbacks, file.Name()) |
| 981 | } |
| 982 | |
| 983 | for _, expectedCallback := range []string{"download", "install", "list-all"} { |
| 984 | if !slices.Contains(callbacks, expectedCallback) { |
| 985 | failTest(l, fmt.Sprintf("missing callback %s", expectedCallback)) |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | allCallbacks := []string{"download", "install", "list-all", "latest-stable", "help.overview", "help.deps", "help.config", "help.links", "list-bin-paths", "exec-env", "exec-path", "uninstall", "list-legacy-filenames", "parse-legacy-file", "post-plugin-add", "post-plugin-update", "pre-plugin-remove"} |
| 990 | |
| 991 | // Assert all callbacks present are executable |
| 992 | for _, file := range files { |
| 993 | // file is a callback... |
| 994 | if slices.Contains(allCallbacks, file.Name()) { |
| 995 | // check if it is executable |
| 996 | info, _ := file.Info() |
| 997 | if !(info.Mode()&0o111 != 0) { |
| 998 | failTest(l, fmt.Sprintf("callback lacks executable permission: %s", file.Name())) |
| 999 | } |
| 1000 | } |
| 1001 | } |
| 1002 |
no test coverage detected