github.com/wuhuizuo/gomplate@v3.5.0+incompatible/tests/integration/basic_nonwindows_test.go (about) 1 //+build integration 2 //+build !windows 3 4 package integration 5 6 import ( 7 "bytes" 8 "io/ioutil" 9 "os" 10 11 . "gopkg.in/check.v1" 12 13 "github.com/gotestyourself/gotestyourself/assert" 14 "github.com/gotestyourself/gotestyourself/icmd" 15 ) 16 17 func (s *BasicSuite) TestRoutesInputsToProperOutputsWithChmod(c *C) { 18 oneOut := s.tmpDir.Join("one.out") 19 twoOut := s.tmpDir.Join("two.out") 20 result := icmd.RunCmd(icmd.Command(GomplateBin, 21 "-f", s.tmpDir.Join("one"), 22 "-f", s.tmpDir.Join("two"), 23 "-o", oneOut, 24 "-o", twoOut, 25 "--chmod", "0600"), func(cmd *icmd.Cmd) { 26 cmd.Stdin = bytes.NewBufferString("hello world") 27 }) 28 result.Assert(c, icmd.Success) 29 30 testdata := []struct { 31 path string 32 mode os.FileMode 33 content string 34 }{ 35 {oneOut, 0600, "hi\n"}, 36 {twoOut, 0600, "hello\n"}, 37 } 38 for _, v := range testdata { 39 info, err := os.Stat(v.path) 40 assert.NilError(c, err) 41 assert.Equal(c, v.mode, info.Mode()) 42 content, err := ioutil.ReadFile(v.path) 43 assert.NilError(c, err) 44 assert.Equal(c, v.content, string(content)) 45 } 46 } 47 48 func (s *BasicSuite) TestOverridesOutputModeWithChmod(c *C) { 49 out := s.tmpDir.Join("two") 50 result := icmd.RunCmd(icmd.Command(GomplateBin, 51 "-f", s.tmpDir.Join("one"), 52 "-o", out, 53 "--chmod", "0600"), func(cmd *icmd.Cmd) { 54 cmd.Stdin = bytes.NewBufferString("hello world") 55 }) 56 result.Assert(c, icmd.Success) 57 58 testdata := []struct { 59 path string 60 mode os.FileMode 61 content string 62 }{ 63 {out, 0600, "hi\n"}, 64 } 65 for _, v := range testdata { 66 info, err := os.Stat(v.path) 67 assert.NilError(c, err) 68 assert.Equal(c, v.mode, info.Mode()) 69 content, err := ioutil.ReadFile(v.path) 70 assert.NilError(c, err) 71 assert.Equal(c, v.content, string(content)) 72 } 73 }