Esempio n. 1
0
func TestSiteDataDir(t *testing.T) {
	for i, test := range testSiteDataDir {
		ret, err := appdirs.SiteDataDir(test.name, test.author, test.version, test.multipath)

		// ok
		// !ok
		// ret exist
		// err exists
		// ret no exist
		// error no exist
		//t.Errorf("/usr/local/share/a_name == /usr/local/share/a_name is %v", "/usr/local/share/a_name" == "/usr/local/share/a_name")

		if platform == "linux" {
			// ok/!ok, ret exist, err exist
			if ret != "" && err != nil {
				t.Errorf("#%d: Both return value and error exist: ret value and error: %v and %v", i, ret, err)
				// ok/!ok, ret not exist, err not exist
			} else if ret != "" && err != nil {
				t.Errorf("#%d: Both return value and error are nil", i)
				// ok, ret exist, err not exist
			} else if test.ok && ret != "" && err == nil {
				shouldBe := filepath.Join("/usr/local/share/", test.name)
				shouldBe2 := filepath.Join("/usr/share/", test.name)
				if test.version != "0" {
					shouldBe = filepath.Join(shouldBe, test.version)
					shouldBe2 = filepath.Join(shouldBe2, test.version)
				}

				if test.multipath {
					shouldBe = shouldBe + ":" + shouldBe2
				}
				if ret != shouldBe {
					t.Errorf("#%d: Incorrect result. Expected:%v Got:%v", i, shouldBe, ret)
				}
				// ok, ret not exist, err exist
			} else if test.ok && ret == "" && err != nil {
				t.Errorf("#%d: result was not ok. Expected ok.", i)
				// !ok, ret exist, err not exist
			} else if !test.ok && ret != "" && err == nil {
				t.Errorf("#%d: result was ok. Expected error. Input was: {%v, %v, %v, %v}. Result was:", i, test.name, test.author, test.version, test.multipath, ret)
				// !ok, ret not exist, err exist
			} else if !test.ok && ret == "" && err != nil {
				//expected error, got it. all good.
			}

		}

	}
}
Esempio n. 2
0
func main() {
	//dataDir,err := appdirs.UserDataDir("myapp","appauthor","1", false)
	//if err != nil{
	//panic(err)
	//}
	//fmt.Println(dataDir)

	//siteDataDir, err := appdirs.SiteDataDir("myapp", "appauthor", "1", false)
	//fmt.Println(siteDataDir)

	//userConfigDir, err := appdirs.UserConfigDir("myapp", "appauthor", "1", false)
	//fmt.Println(userConfigDir)

	siteDataDir, _ := appdirs.SiteDataDir("s", "s", "0", false)
	fmt.Println(siteDataDir)

}