github.com/ppphp/yayagf@v0.0.1/internal/file/file_test.go (about) 1 package file 2 3 import ( 4 "io/ioutil" 5 "os" 6 "path/filepath" 7 "testing" 8 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestGetMod(t *testing.T) { 13 path := os.TempDir() 14 gomod, err := ioutil.ReadFile("../../go.mod") 15 require.NoError(t, err) 16 require.NoError(t, ioutil.WriteFile(filepath.Join(path, "go.mod"), gomod, 0644)) 17 mod, err := GetMod(path) 18 require.NoError(t, err) 19 20 require.Equal(t, "github.com/ppphp/yayagf", mod) 21 } 22 23 func TestGetAppRoot(t *testing.T) { 24 root, err := GetAppRoot() 25 require.NoError(t, err) 26 require.NotEqual(t, "", root) 27 28 require.NoError(t, os.RemoveAll("/tmp/go.mod")) 29 require.NoError(t, os.Chdir("/tmp")) 30 31 root, err = GetAppRoot() 32 require.Error(t, err, "should error but %v", root) 33 require.Equal(t, "", root) 34 35 }