func TestSetFile(t *testing.T) { file := new(File) fs := testfs.NewLocalTestFS() _, err := fs.Create(testFile) assert.NoError(t, err) conf := core.NewConfigInput(map[string]interface{}{ "path": testFile, "action": "set", "content": testData, }) err = file.Configure(conf) assert.NoError(t, err) resp := core.NewResponse() file.Run(fs, resp) assert.True(t, resp.Ok) res, err := fs.Open(testFile) assert.NoError(t, err) out := make([]byte, len(testData)) _, err = res.Read(out) assert.NoError(t, err) assert.Equal(t, testData, out, "File contents should match") }
func TestFileRemove(t *testing.T) { file := new(File) fs := testfs.NewLocalTestFS() _, err := fs.Create(testFile) assert.NoError(t, err) conf := core.NewConfigInput(map[string]interface{}{ "path": testFile, "action": "remove", }) err = file.Configure(conf) assert.NoError(t, err) resp := core.NewResponse() file.Run(fs, resp) assert.True(t, resp.Ok) _, err = os.Stat(testFile) assert.True(t, os.IsNotExist(err)) }
func TestFileTouch(t *testing.T) { file := new(File) fs := testfs.NewLocalTestFS() conf := core.NewConfigInput(map[string]interface{}{ "path": testFile, "mode": 0755, "action": "touch", }) err := file.Configure(conf) assert.NoError(t, err) resp := core.NewResponse() file.Run(fs, resp) assert.True(t, resp.Ok) defer os.Remove(testFile) fi, err := fs.Stat(testFile) assert.NoError(t, err) assert.Equal(t, os.FileMode(0755), fi.Mode(), "File mode should match") }
func init() { resp = core.NewResponse() var out bytes.Buffer log.SetOutput(&out) }