aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2020-02-11 22:20:47 +0100
committerJulien Dessaux2020-02-11 22:21:29 +0100
commit88757ef736987f23ca9404a1e0e71f04e35132e4 (patch)
treee912e985ffe0bf83fcfb61227ec7c5d7dfdf9ce8
parentAdded LICENSE (diff)
downloadbareos-zabbix-check-88757ef736987f23ca9404a1e0e71f04e35132e4.tar.gz
bareos-zabbix-check-88757ef736987f23ca9404a1e0e71f04e35132e4.tar.bz2
bareos-zabbix-check-88757ef736987f23ca9404a1e0e71f04e35132e4.zip
Added tests for job package
-rw-r--r--README.md5
-rw-r--r--job/job.go2
-rw-r--r--job/job_test.go10
-rw-r--r--job/utils_test.go38
4 files changed, 54 insertions, 1 deletions
diff --git a/README.md b/README.md
index 340244c..884189d 100644
--- a/README.md
+++ b/README.md
@@ -19,6 +19,11 @@ go is required. Only go version >= 1.13.5 on linux amd64 has been tested.
## Building
+To run tests, use :
+```
+go test -cover ./...
+```
+
For a debug build, use :
```
go build
diff --git a/job/job.go b/job/job.go
index e15b2eb..4241844 100644
--- a/job/job.go
+++ b/job/job.go
@@ -10,5 +10,5 @@ type Job struct {
}
func (job Job) String() string {
- return fmt.Sprintf("Name: \"%s\", Timestamp: \"%d\", Success: \"%t\"", job.Name, job.Timestamp, job.Success)
+ return fmt.Sprintf("Job { Name: \"%s\", Timestamp: \"%d\", Success: \"%t\" }", job.Name, job.Timestamp, job.Success)
}
diff --git a/job/job_test.go b/job/job_test.go
new file mode 100644
index 0000000..7420220
--- /dev/null
+++ b/job/job_test.go
@@ -0,0 +1,10 @@
+package job
+
+import "testing"
+
+func TestString(t *testing.T) {
+ j := Job{Name: "name", Timestamp: 10, Success: true}
+ if j.String() != "Job { Name: \"name\", Timestamp: \"10\", Success: \"true\" }" {
+ t.Errorf("test string error : %s", j.String())
+ }
+}
diff --git a/job/utils_test.go b/job/utils_test.go
new file mode 100644
index 0000000..8f7f013
--- /dev/null
+++ b/job/utils_test.go
@@ -0,0 +1,38 @@
+package job
+
+import "testing"
+
+func TestKeepOldestOnly(t *testing.T) {
+ t.Run("test empty list", func(t *testing.T) {
+ var jobs []Job
+ if len(KeepOldestOnly(jobs)) != 0 {
+ t.Error("empty list failed")
+ }
+ })
+ t.Run("test functionality", func(t *testing.T) {
+ var jobs []Job
+ jobs = append(jobs, Job{Name: "a", Timestamp: 10, Success: true})
+ jobs = append(jobs, Job{Name: "a", Timestamp: 20, Success: true})
+ jobs2 := KeepOldestOnly(jobs)
+ if len(jobs2) != 1 || jobs2[0].Timestamp != 20 {
+ t.Error("functionality failed")
+ }
+ })
+}
+
+func TestKeepSuccessOnly(t *testing.T) {
+ t.Run("test empty list", func(t *testing.T) {
+ var jobs []Job
+ if len(KeepSuccessOnly(jobs)) != 0 {
+ t.Error("empty list failed")
+ }
+ })
+ t.Run("test functionality", func(t *testing.T) {
+ var jobs []Job
+ jobs = append(jobs, Job{Name: "a", Timestamp: 10, Success: true})
+ jobs = append(jobs, Job{Name: "b", Timestamp: 20, Success: false})
+ if len(KeepSuccessOnly(jobs)) != 1 || jobs[0].Name != "a" {
+ t.Error("functionality failed")
+ }
+ })
+}