github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/topgun/core/syslog_test.go (about)

     1  package topgun_test
     2  
     3  import (
     4  	"bufio"
     5  	"os"
     6  	"strings"
     7  
     8  	. "github.com/pf-qiu/concourse/v6/topgun/common"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  )
    12  
    13  var _ = Describe("An ATC with syslog draining set", func() {
    14  	BeforeEach(func() {
    15  		Deploy("deployments/concourse.yml",
    16  			"-o", "operations/syslog_configurations.yml",
    17  			"-v", "syslog.address=localhost:8081",
    18  			"-v", "syslog.hostname=atc1",
    19  			"-v", "syslog.transport=tcp",
    20  			"-v", "syslog.drain_interval=1s",
    21  		)
    22  	})
    23  
    24  	It("sends the build logs to the syslog server.", func() {
    25  		Fly.Run("set-pipeline", "-n", "-c", "pipelines/secrets.yml", "-p", "syslog-pipeline")
    26  
    27  		Fly.Run("unpause-pipeline", "-p", "syslog-pipeline")
    28  		buildSession := Fly.Start("trigger-job", "-w", "-j", "syslog-pipeline/simple-job")
    29  
    30  		<-buildSession.Exited
    31  		Expect(buildSession.ExitCode()).To(Equal(0))
    32  
    33  		Eventually(func() (bool, error) {
    34  			Bosh("scp", "web/0:/var/vcap/store/syslog_storer/syslog.log", "/tmp/syslog.log")
    35  			return checkContent("/tmp/syslog.log", "shhhh")
    36  		}).Should(BeTrue())
    37  	})
    38  })
    39  
    40  func checkContent(path string, stringToCheck string) (bool, error) {
    41  	f, err := os.Open(path)
    42  	if err != nil {
    43  		return false, err
    44  	}
    45  	defer f.Close()
    46  
    47  	// Splits on newlines by default.
    48  	scanner := bufio.NewScanner(f)
    49  
    50  	line := 1
    51  	// https://golang.org/pkg/bufio/#Scanner.Scan
    52  	for scanner.Scan() {
    53  		if strings.Contains(scanner.Text(), stringToCheck) {
    54  			return true, nil
    55  		}
    56  
    57  		line++
    58  	}
    59  	if err := scanner.Err(); err != nil {
    60  		return false, err
    61  	}
    62  	return false, nil
    63  }