MCPcopy Index your code
hub / github.com/asdf-vm/asdf / pluginTestCommand

Function pluginTestCommand

internal/cli/cli.go:945–1049  ·  view source on GitHub ↗
(l *log.Logger, args []string, toolVersion, ref string)

Source from the content-addressed store, hash-verified

943}
944
945func 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

Callers 1

ExecuteFunction · 0.85

Calls 8

LoadConfigFunction · 0.92
AddFunction · 0.92
RemoveFunction · 0.92
NewFunction · 0.92
LatestFunction · 0.92
InstallOneVersionFunction · 0.92
failTestFunction · 0.85
RunCallbackMethod · 0.80

Tested by

no test coverage detected