Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- uses: golangci/golangci-lint-action@v6.5.2
- uses: golangci/golangci-lint-action@v7.0.0
3 changes: 2 additions & 1 deletion cmdStartWaiter/cmdStartWaiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"io"
)

// CmdStartWaiter is a subset of the interface satisfied by exec.Cmd
//go:generate counterfeiter . CmdStartWaiter

// CmdStartWaiter is a subset of the interface satisfied by exec.Cmd
type CmdStartWaiter interface {
Start() error
Wait() error
Expand Down
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ func Load(filename string) (*Config, error) {
func (c Config) Validate() error {
if c.OptionalTests.RunAppSyslogAvailability {
if c.CF != nil && (c.CF.TCPDomain == "" || c.CF.AvailablePort == 0) {
return errors.New("`cf.tcp_domain` and `cf.available_port` must be set in order to run App Syslog Availability tests.")
return errors.New("`cf.tcp_domain` and `cf.available_port` must be set in order to run App Syslog Availability tests")
}
}
if c.OptionalTests.RunTcpAvailability {
if c.CF != nil && (c.CF.TCPDomain == "" || c.CF.TCPPort == 0) {
return errors.New("`cf.tcp_domain` and `cf.tcp_port` must be set in order to run TCP Availability tests.")
return errors.New("`cf.tcp_domain` and `cf.tcp_port` must be set in order to run TCP Availability tests")
}
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions config/config_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package config_test

import (
"testing"

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

"testing"
)

func TestConfig(t *testing.T) {
Expand Down
127 changes: 0 additions & 127 deletions config/config_test.go

This file was deleted.

118 changes: 118 additions & 0 deletions config/validate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package config_test

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/cloudfoundry/uptimer/config"
)

var _ = Describe("Validate", func() {
var (
cfg config.Config

err error
)

Context("when measuring TCP availability", func() {
BeforeEach(func() {
cfg = config.Config{
CF: &config.Cf{
TCPDomain: "tcp.my-cf.com",
TCPPort: 1025,
},
OptionalTests: config.OptionalTests{RunTcpAvailability: true},
}
})

JustBeforeEach(func() {
err = cfg.Validate()
})

It("succeeds", func() {
Expect(err).ToNot(HaveOccurred())
})

Context("when neither a TCP port or domain are provided", func() {
BeforeEach(func() {
cfg.CF.TCPDomain = ""
cfg.CF.TCPPort = 0
})

It("returns an error", func() {
Expect(err).To(MatchError("`cf.tcp_domain` and `cf.tcp_port` must be set in order to run TCP Availability tests"))
})
})

Context("when a TCP domain is not provided", func() {
BeforeEach(func() {
cfg.CF.TCPDomain = ""
})

It("returns an error", func() {
Expect(err).To(MatchError("`cf.tcp_domain` and `cf.tcp_port` must be set in order to run TCP Availability tests"))
})
})

Context("when a TCP port is not provided", func() {
BeforeEach(func() {
cfg.CF.TCPPort = 0
})

It("returns an error", func() {
Expect(err).To(MatchError("`cf.tcp_domain` and `cf.tcp_port` must be set in order to run TCP Availability tests"))
})
})
})

Context("when measuring app syslog availability", func() {
BeforeEach(func() {
cfg = config.Config{
CF: &config.Cf{
TCPDomain: "tcp.my-cf.com",
AvailablePort: 1025,
},
OptionalTests: config.OptionalTests{RunAppSyslogAvailability: true},
}
})

JustBeforeEach(func() {
err = cfg.Validate()
})

It("succeeds", func() {
Expect(err).ToNot(HaveOccurred())
})

Context("when neither a TCP domain or available port are provided", func() {
BeforeEach(func() {
cfg.CF.TCPDomain = ""
cfg.CF.AvailablePort = 0
})

It("returns an error", func() {
Expect(err).To(MatchError("`cf.tcp_domain` and `cf.available_port` must be set in order to run App Syslog Availability tests"))
})
})

Context("when a TCP domain is not provided", func() {
BeforeEach(func() {
cfg.CF.TCPDomain = ""
})

It("returns an error", func() {
Expect(err).To(MatchError("`cf.tcp_domain` and `cf.available_port` must be set in order to run App Syslog Availability tests"))
})
})

Context("when an available port is not provided", func() {
BeforeEach(func() {
cfg.CF.AvailablePort = 0
})

It("returns an error", func() {
Expect(err).To(MatchError("`cf.tcp_domain` and `cf.available_port` must be set in order to run App Syslog Availability tests"))
})
})
})
})
33 changes: 18 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func main() {
performMeasurements = false
}
logger.Println("Finished preparing included app")
defer os.RemoveAll(appPath)
defer os.RemoveAll(appPath) //nolint:errcheck

var tcpPath string
if cfg.OptionalTests.RunTcpAvailability {
Expand All @@ -85,7 +85,7 @@ func main() {
performMeasurements = false
}
logger.Println("Finished preparing included tcp app")
defer os.RemoveAll(tcpPath)
defer os.RemoveAll(tcpPath) //nolint:errcheck
}

var sinkAppPath string
Expand Down Expand Up @@ -290,27 +290,30 @@ func prepareIncludedApp(name, source string) (string, error) {
return "", err
}

if err := os.WriteFile(filepath.Join(dir, "main.go"), []byte(source), 0644); err != nil {
os.RemoveAll(dir)
return "", err
}
defer func() {
if err != nil {
os.RemoveAll(dir) //nolint:errcheck
}
}()

manifest := goManifest(name)
if err := os.WriteFile(filepath.Join(dir, "manifest.yml"), []byte(manifest), 0644); err != nil {
os.RemoveAll(dir)
err = os.WriteFile(filepath.Join(dir, "main.go"), []byte(source), 0644)
if err != nil {
return "", err
}

return dir, nil
}

func goManifest(appName string) string {
return fmt.Sprintf(`applications:
manifest := fmt.Sprintf(`applications:
- name: %s
memory: 64M
disk: 16M
env:
GOPACKAGENAME: github.com/cloudfoundry/uptimer/%s`, appName, appName)
GOPACKAGENAME: github.com/cloudfoundry/uptimer/%s`, name, name)

err = os.WriteFile(filepath.Join(dir, "manifest.yml"), []byte(manifest), 0644)
if err != nil {
return "", err
}

return dir, nil
}

func createWorkflow(cfc *config.Cf, appPath string, useQuotas bool) cfWorkflow.CfWorkflow {
Expand Down
6 changes: 3 additions & 3 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var _ = Describe("uptimer", func() {
tmpDir := GinkgoT().TempDir()
f, err := os.Create(tmpDir + "/config.json")
Expect(err).NotTo(HaveOccurred())
defer f.Close()
defer f.Close() //nolint:errcheck
b, err := json.Marshal(cfg)
Expect(err).NotTo(HaveOccurred())
_, err = f.Write(b)
Expand Down Expand Up @@ -74,7 +74,7 @@ var _ = Describe("uptimer", func() {
})

It("prints an error", func() {
Expect(session.Out).To(Say("`cf.tcp_domain` and `cf.available_port` must be set in order to run App Syslog Availability tests."))
Expect(session.Out).To(Say("`cf.tcp_domain` and `cf.available_port` must be set in order to run App Syslog Availability tests"))
})
})
})
Expand All @@ -96,7 +96,7 @@ var _ = Describe("uptimer", func() {
})

It("prints an error", func() {
Expect(session.Out).To(Say("`cf.tcp_domain` and `cf.tcp_port` must be set in order to run TCP Availability tests."))
Expect(session.Out).To(Say("`cf.tcp_domain` and `cf.tcp_port` must be set in order to run TCP Availability tests"))
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion measurement/availability.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (a *availability) PerformMeasurement() (string, string, string, bool) {
if err != nil {
return err.Error(), "", "", false
}
defer res.Body.Close()
defer res.Body.Close() //nolint:errcheck

if res.StatusCode != http.StatusOK {
buf := new(bytes.Buffer)
Expand Down
Loading
Loading