func testsCompareFiles(path1, path2 string) error { //skip dirs if util.DoesDirExist(path1) || util.DoesDirExist(path2) { return nil } file1, err := ioutil.ReadFile(path1) if err != nil { return err } file2, err := ioutil.ReadFile(path2) if err != nil { return err } if !bytes.Equal(file1, file2) { return fmt.Errorf("Error: Got %s\nExpected %s", string(file1), string(file1)) } return nil }
func TestInitErisRootDir(t *testing.T) { _, err := checkThenInitErisRoot(false) if err != nil { ifExit(err) } for _, dir := range common.MajorDirs { if !util.DoesDirExist(dir) { ifExit(fmt.Errorf("Could not find the %s subdirectory", dir)) } } }
func checkThenInitErisRoot(force bool) (bool, error) { var newDir bool if force { //for testing only log.Warn("Force initializing eris root directory") if err := common.InitErisDir(); err != nil { return true, fmt.Errorf("Error:\tcould not initialize the eris root directory.\n%s\n", err) } return true, nil } if !util.DoesDirExist(common.ErisRoot) { log.Warn("Eris root directory does not exist. The marmots will initialize this directory for you") if err := common.InitErisDir(); err != nil { return true, fmt.Errorf("Error:\tcould not initialize the eris root directory.\n%s\n", err) } newDir = true } else { // ErisRoot exists, prompt for overwrite newDir = false } return newDir, nil }
func drops(files []string, typ, dir, from string) error { //to get from rawgit var repo string if typ == "services" { repo = "eris-services" } else if typ == "actions" { repo = "eris-actions" } else if typ == "chains" { repo = "eris-chains" } if !util.DoesDirExist(dir) { if err := os.MkdirAll(dir, 0777); err != nil { return err } } buf := new(bytes.Buffer) if from == "toadserver" { for _, file := range files { url := fmt.Sprintf("%s:11113/getfile/%s", ipfs.SexyUrl(), file) log.WithField(file, url).Debug("Getting file from url") log.WithField(file, dir).Debug("Dropping file to") if err := ipfs.DownloadFromUrlToFile(url, file, dir, buf); err != nil { return err } } } else if from == "rawgit" { for _, file := range files { log.WithField(file, dir).Debug("Getting file from GitHub, dropping into:") if err := util.GetFromGithub("eris-ltd", repo, "master", file, dir, file, buf); err != nil { return err } } } return nil }