This file is indexed.

/usr/share/gocode/src/github.com/cloudfoundry/gosigar/concrete_sigar_test.go is in golang-github-cloudfoundry-gosigar-dev 0.0~git20150402.27.3ed7c74-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package sigar_test

import (
	"time"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	sigar "github.com/cloudfoundry/gosigar"
)

var _ = Describe("ConcreteSigar", func() {
	var concreteSigar *sigar.ConcreteSigar

	BeforeEach(func() {
		concreteSigar = &sigar.ConcreteSigar{}
	})

	Describe("CollectCpuStats", func() {
		It("immediately makes first CPU usage available even though it's not very accurate", func() {
			samplesCh, stop := concreteSigar.CollectCpuStats(500 * time.Millisecond)

			firstValue := <-samplesCh
			Expect(firstValue.User).To(BeNumerically(">", 0))

			stop <- struct{}{}
		})

		It("makes CPU usage delta values available", func() {
			samplesCh, stop := concreteSigar.CollectCpuStats(500 * time.Millisecond)

			firstValue := <-samplesCh

			secondValue := <-samplesCh
			Expect(secondValue.User).To(BeNumerically("<", firstValue.User))

			stop <- struct{}{}
		})

		It("does not block", func() {
			_, stop := concreteSigar.CollectCpuStats(10 * time.Millisecond)

			// Sleep long enough for samplesCh to fill at least 2 values
			time.Sleep(20 * time.Millisecond)

			stop <- struct{}{}

			// If CollectCpuStats blocks it will never get here
			Expect(true).To(BeTrue())
		})
	})

	It("GetLoadAverage", func() {
		avg, err := concreteSigar.GetLoadAverage()
		Expect(avg.One).ToNot(BeNil())
		Expect(avg.Five).ToNot(BeNil())
		Expect(avg.Fifteen).ToNot(BeNil())

		Expect(err).ToNot(HaveOccurred())
	})

	It("GetMem", func() {
		mem, err := concreteSigar.GetMem()
		Expect(err).ToNot(HaveOccurred())

		Expect(mem.Total).To(BeNumerically(">", 0))
		Expect(mem.Used + mem.Free).To(BeNumerically("<=", mem.Total))
	})

	It("GetSwap", func() {
		swap, err := concreteSigar.GetSwap()
		Expect(err).ToNot(HaveOccurred())
		Expect(swap.Used + swap.Free).To(BeNumerically("<=", swap.Total))
	})

	It("GetSwap", func() {
		fsusage, err := concreteSigar.GetFileSystemUsage("/")
		Expect(err).ToNot(HaveOccurred())
		Expect(fsusage.Total).ToNot(BeNil())

		fsusage, err = concreteSigar.GetFileSystemUsage("T O T A L L Y B O G U S")
		Expect(err).To(HaveOccurred())
		Expect(fsusage.Total).To(Equal(uint64(0)))
	})
})