//EXISTS func TestFileExists(t *testing.T) { createTestFile() err := engine.Execute(`if (!$file.exists('test')) { throw new Error(); }`) if err != nil { t.Error(err) } err = engine.Execute(`if ($file.exists('test2')) { throw new Error(); }`) if err != nil { t.Error(err) } defer os.Remove("test") }
//DELETE func TestFileDelete(t *testing.T) { createTestFile() err := engine.Execute(`$file.delete('test')`) if err != nil { t.Error(err) } }
//READSTRING func TestFileReadString(t *testing.T) { createTestFile() err := engine.Execute(`if ($file.readString('test') != 'test') { throw new Error(); }`) if err != nil { t.Error(err) } defer os.Remove("test") }
func TestFileMoveBadPath(t *testing.T) { createTestFile() err := engine.Execute(`$file.move('test', '/blah/test');`) if err == nil { t.Fail() } defer os.Remove("test") }
//MOVE func TestFileMove(t *testing.T) { createTestFile() err := engine.Execute(`$file.move('test', 'test1');`) if err != nil { t.Error(err) } if !fileExists("test1") { t.Error("destination file does not exist") } defer os.Remove("test1") }
//MKDIR func TestFileMkdir(t *testing.T) { dir, _ := filepath.Abs(filepath.Dir(os.Args[0])) err := engine.Execute(`$file.mkdir('` + dir + `/test/test1');`) if err != nil { t.Error(err) } if !fileExists(dir + "/test/test1") { t.Error("Directory does not exist: ", dir) } defer os.RemoveAll(dir + "/test/test1") }
//WRITE func TestFileWrite(t *testing.T) { err := engine.Execute(`$file.write('write_test.txt', 'test');`) if err != nil { t.Error(err) } data, err := ioutil.ReadFile("write_test.txt") if err != nil { t.Error(err) } if string(data) != "test" { t.Error("expecting contents to be 'test' but got", string(data)) } defer os.Remove("write_test.txt") }
func TestFileCopyBadPath(t *testing.T) { err := engine.Execute(`$file.copy('test', '/blah/test1');`) if err == nil { t.Fail() } }
func TestFileWriteBadPath(t *testing.T) { err := engine.Execute(`$file.write('/blah/test.txt', 'test');`) if err == nil { t.Fail() } }
command to be delivered to it for processing.`, Run: func(cmd *cobra.Command, args []string) { log.Info("Starting...") q := queue.GetQueue() mgr := storage.GetStorage() for { cmd, err := q.Get() if err != nil { log.Error(err.Error()) } if cmd != nil { scriptBody, err := mgr.GetScript(cmd.RemoteScriptUrl) if err != nil { log.Error(err.Error()) } else { err := engine.Execute(scriptBody) if err != nil { log.Error(err.Error()) } else { q.Delete(cmd) } } } } }, } func init() { RootCmd.AddCommand(watchCmd) // Here you will define your flags and configuration settings.