func TestRootNotExist(t *testing.T) {
	assert := assert.New(t)
	agents := ListExternalAgentPaths("/path/which/does/not/exist")
	assert.Equal(0, len(agents))
}
Test that non-existant /opt/extensions is treated as if no agents were found
package agents
import (
	"bytes"
	"io/ioutil"
	"os"
	"path"
	"testing"
	"github.com/stretchr/testify/assert"
)
type fileInfo struct {
	name   string
	mode   os.FileMode
	size   int64
	target string  
}
func mkFile(name string, size int64, perm os.FileMode) fileInfo {
	return fileInfo{
		name:   name,
		mode:   perm,
		size:   size,
		target: "",
	}
}
func mkDir(name string, perm os.FileMode) fileInfo {
	return fileInfo{
		name:   name,
		mode:   perm | os.ModeDir,
		size:   0,
		target: "",
	}
}
func mkLink(name, target string) fileInfo {
	return fileInfo{
		name:   name,
		mode:   os.ModeSymlink,
		size:   0,
		target: target,
	}
}
func createFileTree(fs []fileInfo) (string, error) {
	root, err := ioutil.TempDir(os.TempDir(), "tmp-")
	if err != nil {
		return "", err
	}
	for _, info := range fs {
		filename := info.name
		dir := path.Join(root, path.Dir(filename))
		name := path.Base(filename)
		err := os.MkdirAll(dir, 0775)
		if err != nil && !os.IsExist(err) {
			return "", err
		}
		if os.ModeDir == info.mode&os.ModeDir {
			err := os.Mkdir(path.Join(dir, name), info.mode&os.ModePerm)
			if err != nil {
				return "", err
			}
		} else if os.ModeSymlink == info.mode&os.ModeSymlink {
			target := path.Join(root, info.target)
			_, err = os.Stat(target)
			if err != nil {
				return "", err
			}
			err := os.Symlink(target, path.Join(dir, name))
			if err != nil {
				return "", err
			}
		} else {
			file, err := os.OpenFile(path.Join(dir, name), os.O_RDWR|os.O_CREATE, info.mode&os.ModePerm)
			if err != nil {
				return "", err
			}
			file.Truncate(info.size)
			file.Close()
		}
	}
	return root, nil
}
func within(fs []fileInfo, closure func()) error {
	var root string
	var cwd string
	var err error
	if root, err = createFileTree(fs); err != nil {
		return err
	}
	defer os.RemoveAll(root)
	if cwd, err = os.Getwd(); err != nil {
		return err
	}
	if err = os.Chdir(root); err != nil {
		return err
	}
	defer os.Chdir(cwd)
	closure()
	return nil
}
func TestRootEmpty(t *testing.T) {
	assert := assert.New(t)
	fs := []fileInfo{
		mkDir("/opt/extensions", 0777),
	}
	assert.NoError(within(fs, func() {
		agents := ListExternalAgentPaths("opt/extensions")
		assert.Equal(0, len(agents))
	}))
}