github.com/geofffranks/garden-linux@v0.0.0-20160715111146-26c893169cfa/integration/lifecycle/logging_test.go (about) 1 package lifecycle_test 2 3 import ( 4 "code.cloudfoundry.org/garden" 5 6 . "github.com/onsi/ginkgo" 7 . "github.com/onsi/gomega" 8 "github.com/onsi/gomega/gbytes" 9 ) 10 11 var _ = Describe("Logging", func() { 12 var container garden.Container 13 var containerSpec garden.ContainerSpec 14 15 BeforeEach(func() { 16 containerSpec = garden.ContainerSpec{} 17 }) 18 19 JustBeforeEach(func() { 20 var err error 21 client = startGarden() 22 container, err = client.Create(containerSpec) 23 Expect(err).ToNot(HaveOccurred()) 24 }) 25 26 Context("when container is created", func() { 27 BeforeEach(func() { 28 containerSpec = garden.ContainerSpec{ 29 Handle: "kumquat", 30 Env: []string{"PASSWORD=MY_SECRET"}, 31 Properties: garden.Properties{ 32 "super": "banana", 33 }, 34 } 35 }) 36 37 It("should log before and after starting with the container handle", func() { 38 Eventually(client).Should(gbytes.Say(`container.start.starting","log_level":0,"data":{"handle":"kumquat"`)) 39 Eventually(client).Should(gbytes.Say(`container.start.ended","log_level":0,"data":{"handle":"kumquat"`)) 40 }) 41 42 It("should not log any environment variables", func() { 43 Consistently(client).ShouldNot(gbytes.Say("PASSWORD")) 44 Consistently(client).ShouldNot(gbytes.Say("MY_SECRET")) 45 }) 46 47 It("should not log any properties", func() { 48 Consistently(client).ShouldNot(gbytes.Say("super")) 49 Consistently(client).ShouldNot(gbytes.Say("banana")) 50 }) 51 52 Context("from a docker url", func() { 53 BeforeEach(func() { 54 containerSpec.RootFSPath = "docker:///cfgarden/with-volume" 55 }) 56 57 It("should not log any environment variables", func() { 58 Consistently(client).ShouldNot(gbytes.Say("test-from-dockerfile")) 59 }) 60 }) 61 }) 62 63 Context("when container spawn a new process", func() { 64 It("should not log any environment variables and command line arguments", func() { 65 process, err := container.Run(garden.ProcessSpec{ 66 User: "alice", 67 Path: "echo", 68 Args: []string{"-username", "banana"}, 69 Env: []string{"PASSWORD=MY_SECRET"}, 70 }, garden.ProcessIO{ 71 Stdout: GinkgoWriter, 72 Stderr: GinkgoWriter, 73 }) 74 Expect(err).ToNot(HaveOccurred()) 75 exitStatus, err := process.Wait() 76 Expect(err).ToNot(HaveOccurred()) 77 Expect(exitStatus).To(Equal(0)) 78 79 Consistently(client).ShouldNot(gbytes.Say("PASSWORD")) 80 Consistently(client).ShouldNot(gbytes.Say("MY_SECRET")) 81 Consistently(client).ShouldNot(gbytes.Say("-username")) 82 Consistently(client).ShouldNot(gbytes.Say("banana")) 83 }) 84 }) 85 86 Context("when working with properties", func() { 87 BeforeEach(func() { 88 containerSpec = garden.ContainerSpec{ 89 Properties: garden.Properties{ 90 "super": "banana", 91 }, 92 } 93 }) 94 95 It("should not log the properties when we are getting them", func() { 96 _, err := container.Properties() 97 Expect(err).ToNot(HaveOccurred()) 98 99 Consistently(client).ShouldNot(gbytes.Say("super")) 100 Consistently(client).ShouldNot(gbytes.Say("banana")) 101 }) 102 103 It("should not log the properties when we are setting them", func() { 104 err := container.SetProperty("super", "banana") 105 Expect(err).ToNot(HaveOccurred()) 106 107 Consistently(client).ShouldNot(gbytes.Say("super")) 108 Consistently(client).ShouldNot(gbytes.Say("banana")) 109 }) 110 }) 111 })