예제 #1
0
//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")
}
예제 #2
0
//DELETE
func TestFileDelete(t *testing.T) {
	createTestFile()

	err := engine.Execute(`$file.delete('test')`)
	if err != nil {
		t.Error(err)
	}
}
예제 #3
0
//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")
}
예제 #4
0
func TestFileMoveBadPath(t *testing.T) {
	createTestFile()

	err := engine.Execute(`$file.move('test', '/blah/test');`)
	if err == nil {
		t.Fail()
	}

	defer os.Remove("test")
}
예제 #5
0
//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")
}
예제 #6
0
//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")
}
예제 #7
0
//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")
}
예제 #8
0
func TestFileCopyBadPath(t *testing.T) {
	err := engine.Execute(`$file.copy('test', '/blah/test1');`)
	if err == nil {
		t.Fail()
	}
}
예제 #9
0
func TestFileWriteBadPath(t *testing.T) {
	err := engine.Execute(`$file.write('/blah/test.txt', 'test');`)
	if err == nil {
		t.Fail()
	}
}
예제 #10
0
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.