Skip to content

Commit

Permalink
Fix 397 (#405)
Browse files Browse the repository at this point in the history
Fix 397
  • Loading branch information
twpayne committed Aug 11, 2019
2 parents a46d04f + 7d513f3 commit aab0d2c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 14 deletions.
7 changes: 0 additions & 7 deletions cmd/apply_posix_test.go
Expand Up @@ -9,13 +9,6 @@ import (
"github.com/twpayne/go-vfs/vfst"
)

type scriptTestCase struct {
name string
root interface{}
data map[string]interface{}
tests []vfst.Test
}

func getApplyScriptTestCases(tempDir string) []scriptTestCase {
return []scriptTestCase{
{
Expand Down
7 changes: 7 additions & 0 deletions cmd/apply_test.go
Expand Up @@ -13,6 +13,13 @@ import (
"github.com/twpayne/go-vfs/vfst"
)

type scriptTestCase struct {
name string
root interface{}
data map[string]interface{}
tests []vfst.Test
}

func TestApplyCommand(t *testing.T) {
for _, tc := range []struct {
name string
Expand Down
7 changes: 0 additions & 7 deletions cmd/apply_windows_test.go
Expand Up @@ -9,13 +9,6 @@ import (
"github.com/twpayne/go-vfs/vfst"
)

type scriptTestCase struct {
name string
root interface{}
data map[string]interface{}
tests []vfst.Test
}

func getApplyScriptTestCases(tempDir string) []scriptTestCase {
return []scriptTestCase{
{
Expand Down
1 change: 1 addition & 0 deletions cmd/diff.go
Expand Up @@ -20,6 +20,7 @@ func init() {
}

func (c *Config) runDiffCmd(fs vfs.FS, args []string) error {
c.DryRun = true
mutator := chezmoi.NewLoggingMutator(c.Stdout(), chezmoi.NullMutator{}, c.colored)
return c.applyArgs(fs, args, mutator)
}
41 changes: 41 additions & 0 deletions cmd/diff_posix_test.go
@@ -0,0 +1,41 @@
// +build !windows

package cmd

import (
"io/ioutil"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
vfs "github.com/twpayne/go-vfs"
"github.com/twpayne/go-vfs/vfst"
)

func TestDiffDoesNotRunScript(t *testing.T) {
tempDir, err := ioutil.TempDir("", "chezmoi")
require.NoError(t, err)
defer func() {
require.NoError(t, os.RemoveAll(tempDir))
}()
fs := vfs.NewPathFS(vfs.OSFS, tempDir)
require.NoError(t, vfst.NewBuilder().Build(
fs,
map[string]interface{}{
"/home/user/.local/share/chezmoi/run_true": "#!/bin/sh\necho foo >>" + filepath.Join(tempDir, "evidence") + "\n",
},
))
c := &Config{
SourceDir: "/home/user/.local/share/chezmoi",
DestDir: "/",
Umask: 022,
}
assert.NoError(t, c.runDiffCmd(fs, nil))
vfst.RunTests(t, vfs.OSFS, "",
vfst.TestPath(filepath.Join(tempDir, "evidence"),
vfst.TestDoesNotExist,
),
)
}

0 comments on commit aab0d2c

Please sign in to comment.