This is a mock implementation of the "fs" module for use with tests. It does not actually read from the file system. Instead, it reads from a pre-specified map of file paths to files.

package fs

import (
	
	
	
	
)

type mockFS struct {
	dirs  map[string]DirEntries
	files map[string]string
}

func ( map[string]string) FS {
	 := make(map[string]DirEntries)
	 := make(map[string]string)

	for ,  := range  {
		[] = 
		 := 
Build the directory map
		for {
			 := path.Dir()
			,  := []
			if ! {
				 = DirEntries{, make(map[string]*Entry)}
				[] = 
			}
			if  ==  {
				break
			}
			 := path.Base()
			if  ==  {
				.data[strings.ToLower()] = &Entry{kind: FileEntry, base: }
			} else {
				.data[strings.ToLower()] = &Entry{kind: DirEntry, base: }
			}
			 = 
		}
	}

	return &mockFS{, }
}

func ( *mockFS) ( string) (DirEntries, error) {
	if ,  := .dirs[];  {
		return , nil
	}
	return DirEntries{}, syscall.ENOENT
}

func ( *mockFS) ( string) (string, error) {
	,  := .files[]
	if ! {
		return "", syscall.ENOENT
	}
	return , nil
}

func ( *mockFS) ( string) (ModKey, error) {
	return ModKey{}, errors.New("This is not available during tests")
}

func (*mockFS) ( string) bool {
	return path.IsAbs()
}

func (*mockFS) ( string) (string, bool) {
	return path.Clean(path.Join("/", )), true
}

func (*mockFS) ( string) string {
	return path.Dir()
}

func (*mockFS) ( string) string {
	return path.Base()
}

func (*mockFS) ( string) string {
	return path.Ext()
}

func (*mockFS) ( ...string) string {
	return path.Clean(path.Join(...))
}

func (*mockFS) () string {
	return "/"
}

func ( string) (string, string) {
	if  := strings.IndexByte(, '/');  != -1 {
		return [:], [+1:]
	}
	return , ""
}

Base cases
	if  == "" ||  == "." {
		return , true
	}
	if  ==  {
		return ".", true
	}
Find the common parent directory
	for {
		,  := splitOnSlash()
		,  := splitOnSlash()
		if  !=  {
			break
		}
		 = 
		 = 
	}
Stop now if base is a subpath of target
	if  == "" {
		return , true
	}
Traverse up to the common parent
	 := strings.Repeat("../", strings.Count(, "/")+1)
Stop now if target is a subpath of base
	if  == "" {
		return [:len()-1], true
	}
Otherwise, down to the parent
	return  + , true
}

func ( *mockFS) ( string,  string) ( string,  EntryKind) {
	panic("This should never be called")
}

func ( *mockFS) () WatchData {
	panic("This should never be called")