Compare commits

...

33 Commits

Author SHA1 Message Date
semantic-release-bot
a9bb22f16c release(rc): v1.3.2-rc.3
## [1.3.2-rc.3](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.2-rc.2...v1.3.2-rc.3) (2024-08-20)

### Build system and dependencies

* **deps:** update all non-major dependencies ([65f30a6](65f30a6b09))
2024-08-20 21:18:09 +00:00
65f30a6b09 build(deps): update all non-major dependencies
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-08-20 21:15:17 +00:00
semantic-release-bot
c269e64231 release(rc): v1.3.2-rc.2
## [1.3.2-rc.2](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.2-rc.1...v1.3.2-rc.2) (2024-08-20)

### Build system and dependencies

* **deps:** update golang docker tag to v1.23 ([0ad5148](0ad514865c))
2024-08-20 20:46:31 +00:00
0ad514865c
build(deps): update golang docker tag to v1.23
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-08-20 22:45:44 +02:00
semantic-release-bot
8f8d6eb47f release(rc): v1.3.2-rc.1
## [1.3.2-rc.1](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.1...v1.3.2-rc.1) (2024-08-20)

### Build system and dependencies

* **deps:** update all major dependencies ([48aa72b](48aa72b375))
2024-08-20 20:36:05 +00:00
48aa72b375 build(deps): update all major dependencies
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-06-01 00:02:40 +00:00
semantic-release-bot
7f5d2fd5e2 release(stable): v1.3.1
## [1.3.1](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.0...v1.3.1) (2024-05-27)

### Refactoring

* **formatting:** change line terminators from CRLF to LF ([ec44d7f](ec44d7f643))
* **probes:** rename `ProbeFunction` to `Probe` ([8dc7f27](8dc7f27400))

### Continuous Integrations

* **deps:** pin `conventional-changelog-conventionalcommits` to version 7.x ([b15846a](b15846aa58))
* **test:** remove `group` directive ([a1bab99](a1bab99cbd))

### Build system and dependencies

* **deps:** update all non-major dependencies ([a68663c](a68663cff0))
* **deps:** update dependency @semantic-release/commit-analyzer to v12 ([2a79a68](2a79a6878f))
* **deps:** update dependency @semantic-release/npm to v12 ([fdee33a](fdee33a1e7))
* **deps:** update dependency @semantic-release/release-notes-generator to v13 ([0cba4d2](0cba4d2a50))
* **deps:** update dependency conventional-changelog-conventionalcommits to v8 ([8918072](8918072d5c))
* **deps:** update dependency semantic-release to v23.0.3 ([cea539f](cea539fd6d))
* **deps:** update dependency semantic-release to v23.0.4 ([2d5b101](2d5b101b8d))
* **deps:** update dependency semantic-release to v23.0.5 ([061100e](061100e432))
* **deps:** update dependency semantic-release to v23.0.8 ([b98f6ef](b98f6ef609))
2024-05-27 23:55:53 +00:00
semantic-release-bot
e830e25560 release(rc): v1.3.1-rc.11
All checks were successful
ci/woodpecker/push/release Pipeline was successful
## [1.3.1-rc.11](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.1-rc.10...v1.3.1-rc.11) (2024-05-27)

### Refactoring

* **formatting:** change line terminators from CRLF to LF ([ec44d7f](ec44d7f643))
2024-05-27 23:54:51 +00:00
ec44d7f643
refactor(formatting): change line terminators from CRLF to LF
All checks were successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-05-28 01:54:25 +02:00
df80db0e29
docs(readme): add badges 2024-05-28 01:54:24 +02:00
semantic-release-bot
c8471ec264 release(rc): v1.3.1-rc.10
## [1.3.1-rc.10](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.1-rc.9...v1.3.1-rc.10) (2024-05-27)

### Continuous Integrations

* **test:** remove `group` directive ([a1bab99](a1bab99cbd))
2024-05-27 23:49:39 +00:00
7a54da4c57
docs(readme): update README.md
All checks were successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-05-28 01:43:09 +02:00
a1bab99cbd
ci(test): remove group directive 2024-05-28 01:39:29 +02:00
semantic-release-bot
eeb0d8f522 release(rc): v1.3.1-rc.9
## [1.3.1-rc.9](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.1-rc.8...v1.3.1-rc.9) (2024-05-21)

### Continuous Integrations

* **deps:** pin `conventional-changelog-conventionalcommits` to version 7.x ([b15846a](b15846aa58))

### Build system and dependencies

* **deps:** update all non-major dependencies ([a68663c](a68663cff0))
* **deps:** update dependency conventional-changelog-conventionalcommits to v8 ([8918072](8918072d5c))
2024-05-21 21:01:49 +00:00
b15846aa58
ci(deps): pin conventional-changelog-conventionalcommits to version 7.x
All checks were successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
2024-05-21 23:00:55 +02:00
a68663cff0 build(deps): update all non-major dependencies
Some checks failed
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline failed
ci/woodpecker/push/test Pipeline was successful
2024-05-15 13:15:19 +02:00
8918072d5c build(deps): update dependency conventional-changelog-conventionalcommits to v8
Some checks failed
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline failed
ci/woodpecker/push/test Pipeline was successful
2024-05-04 00:02:17 +00:00
semantic-release-bot
71c370f53a release(rc): v1.3.1-rc.8
## [1.3.1-rc.8](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.1-rc.7...v1.3.1-rc.8) (2024-04-12)

### Build system and dependencies

* **deps:** update dependency semantic-release to v23.0.8 ([b98f6ef](b98f6ef609))
2024-04-12 12:44:11 +00:00
b98f6ef609 build(deps): update dependency semantic-release to v23.0.8
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-04-12 12:41:33 +00:00
semantic-release-bot
16f29ebfc1 release(rc): v1.3.1-rc.7
## [1.3.1-rc.7](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.1-rc.6...v1.3.1-rc.7) (2024-04-12)

### Build system and dependencies

* **deps:** update dependency @semantic-release/release-notes-generator to v13 ([0cba4d2](0cba4d2a50))
2024-04-12 12:39:03 +00:00
0cba4d2a50 build(deps): update dependency @semantic-release/release-notes-generator to v13
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
2024-03-27 00:02:50 +00:00
semantic-release-bot
b441b35d48 release(rc): v1.3.1-rc.6
## [1.3.1-rc.6](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.1-rc.5...v1.3.1-rc.6) (2024-03-23)

### Build system and dependencies

* **deps:** update dependency semantic-release to v23.0.5 ([061100e](061100e432))
2024-03-23 23:21:53 +00:00
061100e432 build(deps): update dependency semantic-release to v23.0.5
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-03-23 23:20:30 +00:00
semantic-release-bot
9288fcd144 release(rc): v1.3.1-rc.5
## [1.3.1-rc.5](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.1-rc.4...v1.3.1-rc.5) (2024-03-23)

### Build system and dependencies

* **deps:** update dependency @semantic-release/commit-analyzer to v12 ([2a79a68](2a79a6878f))
2024-03-23 23:18:28 +00:00
2a79a6878f build(deps): update dependency @semantic-release/commit-analyzer to v12
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-03-19 00:02:43 +00:00
semantic-release-bot
d0a17892a1 release(rc): v1.3.1-rc.4
## [1.3.1-rc.4](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.1-rc.3...v1.3.1-rc.4) (2024-03-17)

### Build system and dependencies

* **deps:** update dependency @semantic-release/npm to v12 ([fdee33a](fdee33a1e7))
2024-03-17 11:36:51 +00:00
fdee33a1e7 build(deps): update dependency @semantic-release/npm to v12
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-03-17 11:34:40 +00:00
semantic-release-bot
d89fd7fdd7 release(rc): v1.3.1-rc.3
## [1.3.1-rc.3](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.1-rc.2...v1.3.1-rc.3) (2024-03-17)

### Build system and dependencies

* **deps:** update dependency semantic-release to v23.0.4 ([2d5b101](2d5b101b8d))
2024-03-17 11:31:08 +00:00
2d5b101b8d build(deps): update dependency semantic-release to v23.0.4
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-03-17 00:02:45 +00:00
semantic-release-bot
100c32969f release(rc): v1.3.1-rc.2
## [1.3.1-rc.2](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.1-rc.1...v1.3.1-rc.2) (2024-03-16)

### Build system and dependencies

* **deps:** update dependency semantic-release to v23.0.3 ([cea539f](cea539fd6d))
2024-03-16 00:06:53 +00:00
cea539fd6d build(deps): update dependency semantic-release to v23.0.3
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-03-16 00:03:37 +00:00
semantic-release-bot
2a779b10db release(rc): v1.3.1-rc.1
## [1.3.1-rc.1](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.0...v1.3.1-rc.1) (2024-03-03)

### Refactoring

* **probes:** rename `ProbeFunction` to `Probe` ([8dc7f27](8dc7f27400))
2024-03-03 22:27:55 +00:00
8dc7f27400
refactor(probes): rename ProbeFunction to Probe
All checks were successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-03-03 23:25:56 +01:00
12 changed files with 2402 additions and 1459 deletions

View File

@ -5,7 +5,6 @@ when:
steps: steps:
test: test:
group: test image: golang:1.23-alpine
image: golang:1.22-alpine
commands: commands:
- go test -v ./... - go test -v ./...

View File

@ -1,3 +1,131 @@
## [1.3.2-rc.3](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.2-rc.2...v1.3.2-rc.3) (2024-08-20)
### Build system and dependencies
* **deps:** update all non-major dependencies ([65f30a6](https://git.ext.icikowski.pl/go/kubeprobes/commit/65f30a6b09628b6e58f40318279e2034f92790ba))
## [1.3.2-rc.2](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.2-rc.1...v1.3.2-rc.2) (2024-08-20)
### Build system and dependencies
* **deps:** update golang docker tag to v1.23 ([0ad5148](https://git.ext.icikowski.pl/go/kubeprobes/commit/0ad514865ca927f9f87747b2710f6be9f8b43590))
## [1.3.2-rc.1](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.1...v1.3.2-rc.1) (2024-08-20)
### Build system and dependencies
* **deps:** update all major dependencies ([48aa72b](https://git.ext.icikowski.pl/go/kubeprobes/commit/48aa72b3757830fb05ed136765cb7389ba1d7285))
## [1.3.1](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.0...v1.3.1) (2024-05-27)
### Refactoring
* **formatting:** change line terminators from CRLF to LF ([ec44d7f](https://git.ext.icikowski.pl/go/kubeprobes/commit/ec44d7f643e78cfb1e9724b36416458782a6c775))
* **probes:** rename `ProbeFunction` to `Probe` ([8dc7f27](https://git.ext.icikowski.pl/go/kubeprobes/commit/8dc7f27400075fabca9525f42eb20404736fb1cb))
### Continuous Integrations
* **deps:** pin `conventional-changelog-conventionalcommits` to version 7.x ([b15846a](https://git.ext.icikowski.pl/go/kubeprobes/commit/b15846aa58864f5809e2226cad9c52770f84aae9))
* **test:** remove `group` directive ([a1bab99](https://git.ext.icikowski.pl/go/kubeprobes/commit/a1bab99cbdbf903256be3172036fc9b8c44f9992))
### Build system and dependencies
* **deps:** update all non-major dependencies ([a68663c](https://git.ext.icikowski.pl/go/kubeprobes/commit/a68663cff022fa135d48fae6f00e39ea684983f1))
* **deps:** update dependency @semantic-release/commit-analyzer to v12 ([2a79a68](https://git.ext.icikowski.pl/go/kubeprobes/commit/2a79a6878f647049ca2f01711d74561f6c4974c6))
* **deps:** update dependency @semantic-release/npm to v12 ([fdee33a](https://git.ext.icikowski.pl/go/kubeprobes/commit/fdee33a1e7c05bd19f0f5d675df434ad4d844911))
* **deps:** update dependency @semantic-release/release-notes-generator to v13 ([0cba4d2](https://git.ext.icikowski.pl/go/kubeprobes/commit/0cba4d2a50319cc0250dc3cb14e32dee813b4fc0))
* **deps:** update dependency conventional-changelog-conventionalcommits to v8 ([8918072](https://git.ext.icikowski.pl/go/kubeprobes/commit/8918072d5c818bad10542957b93440730d50baf1))
* **deps:** update dependency semantic-release to v23.0.3 ([cea539f](https://git.ext.icikowski.pl/go/kubeprobes/commit/cea539fd6d68608635ec19ae8840da749695bfac))
* **deps:** update dependency semantic-release to v23.0.4 ([2d5b101](https://git.ext.icikowski.pl/go/kubeprobes/commit/2d5b101b8d38d7af7c6b4ba570f1045fe9e9dc7b))
* **deps:** update dependency semantic-release to v23.0.5 ([061100e](https://git.ext.icikowski.pl/go/kubeprobes/commit/061100e432a61ed6bcb310de297880db369e2f24))
* **deps:** update dependency semantic-release to v23.0.8 ([b98f6ef](https://git.ext.icikowski.pl/go/kubeprobes/commit/b98f6ef609c278bfbd25c25316ad166fba75f255))
## [1.3.1-rc.11](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.1-rc.10...v1.3.1-rc.11) (2024-05-27)
### Refactoring
* **formatting:** change line terminators from CRLF to LF ([ec44d7f](https://git.ext.icikowski.pl/go/kubeprobes/commit/ec44d7f643e78cfb1e9724b36416458782a6c775))
## [1.3.1-rc.10](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.1-rc.9...v1.3.1-rc.10) (2024-05-27)
### Continuous Integrations
* **test:** remove `group` directive ([a1bab99](https://git.ext.icikowski.pl/go/kubeprobes/commit/a1bab99cbdbf903256be3172036fc9b8c44f9992))
## [1.3.1-rc.9](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.1-rc.8...v1.3.1-rc.9) (2024-05-21)
### Continuous Integrations
* **deps:** pin `conventional-changelog-conventionalcommits` to version 7.x ([b15846a](https://git.ext.icikowski.pl/go/kubeprobes/commit/b15846aa58864f5809e2226cad9c52770f84aae9))
### Build system and dependencies
* **deps:** update all non-major dependencies ([a68663c](https://git.ext.icikowski.pl/go/kubeprobes/commit/a68663cff022fa135d48fae6f00e39ea684983f1))
* **deps:** update dependency conventional-changelog-conventionalcommits to v8 ([8918072](https://git.ext.icikowski.pl/go/kubeprobes/commit/8918072d5c818bad10542957b93440730d50baf1))
## [1.3.1-rc.8](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.1-rc.7...v1.3.1-rc.8) (2024-04-12)
### Build system and dependencies
* **deps:** update dependency semantic-release to v23.0.8 ([b98f6ef](https://git.ext.icikowski.pl/go/kubeprobes/commit/b98f6ef609c278bfbd25c25316ad166fba75f255))
## [1.3.1-rc.7](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.1-rc.6...v1.3.1-rc.7) (2024-04-12)
### Build system and dependencies
* **deps:** update dependency @semantic-release/release-notes-generator to v13 ([0cba4d2](https://git.ext.icikowski.pl/go/kubeprobes/commit/0cba4d2a50319cc0250dc3cb14e32dee813b4fc0))
## [1.3.1-rc.6](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.1-rc.5...v1.3.1-rc.6) (2024-03-23)
### Build system and dependencies
* **deps:** update dependency semantic-release to v23.0.5 ([061100e](https://git.ext.icikowski.pl/go/kubeprobes/commit/061100e432a61ed6bcb310de297880db369e2f24))
## [1.3.1-rc.5](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.1-rc.4...v1.3.1-rc.5) (2024-03-23)
### Build system and dependencies
* **deps:** update dependency @semantic-release/commit-analyzer to v12 ([2a79a68](https://git.ext.icikowski.pl/go/kubeprobes/commit/2a79a6878f647049ca2f01711d74561f6c4974c6))
## [1.3.1-rc.4](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.1-rc.3...v1.3.1-rc.4) (2024-03-17)
### Build system and dependencies
* **deps:** update dependency @semantic-release/npm to v12 ([fdee33a](https://git.ext.icikowski.pl/go/kubeprobes/commit/fdee33a1e7c05bd19f0f5d675df434ad4d844911))
## [1.3.1-rc.3](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.1-rc.2...v1.3.1-rc.3) (2024-03-17)
### Build system and dependencies
* **deps:** update dependency semantic-release to v23.0.4 ([2d5b101](https://git.ext.icikowski.pl/go/kubeprobes/commit/2d5b101b8d38d7af7c6b4ba570f1045fe9e9dc7b))
## [1.3.1-rc.2](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.1-rc.1...v1.3.1-rc.2) (2024-03-16)
### Build system and dependencies
* **deps:** update dependency semantic-release to v23.0.3 ([cea539f](https://git.ext.icikowski.pl/go/kubeprobes/commit/cea539fd6d68608635ec19ae8840da749695bfac))
## [1.3.1-rc.1](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.3.0...v1.3.1-rc.1) (2024-03-03)
### Refactoring
* **probes:** rename `ProbeFunction` to `Probe` ([8dc7f27](https://git.ext.icikowski.pl/go/kubeprobes/commit/8dc7f27400075fabca9525f42eb20404736fb1cb))
## [1.3.0](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.2.0...v1.3.0) (2024-03-02) ## [1.3.0](https://git.ext.icikowski.pl/go/kubeprobes/compare/v1.2.0...v1.3.0) (2024-03-02)

View File

@ -1,5 +1,7 @@
# kubeprobes # kubeprobes
[![Go Report Card](https://goreportcard.com/badge/pkg.icikowski.pl/kubeprobes)](https://goreportcard.com/report/pkg.icikowski.pl/kubeprobes)
Simple and effective package for implementing [Kubernetes liveness and readiness probes](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/)' handler. Simple and effective package for implementing [Kubernetes liveness and readiness probes](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/)' handler.
## Installation ## Installation
@ -21,22 +23,22 @@ Default paths can be overriden with options described below. Accessing any other
The `kubeprobes.New` function accepts following options as arguments: The `kubeprobes.New` function accepts following options as arguments:
- `kubeprobes.WithLivenessProbes(...)` - adds particular [probe functions](#probe-functions) to the list of liveness probes; - `kubeprobes.WithLivenessProbes(...)` - adds particular [probes](#probes) to the list of liveness probes;
- `kubeprobes.WithLivenessPath("/some/liveness/path")` - sets liveness probe path to given path (default is `/live`); - `kubeprobes.WithLivenessPath("/some/liveness/path")` - sets liveness probe path to given path (default is `/live`);
- `kubeprobes.WithReadinessProbes(...)` - adds particular [probe functions](#probe-functions) to the list of readiness probes; - `kubeprobes.WithReadinessProbes(...)` - adds particular [probes](#probes) to the list of readiness probes;
- `kubeprobes.WithReadinessPath("/some/readiness/path")` - sets readiness probe path to given path (default is `/ready`); - `kubeprobes.WithReadinessPath("/some/readiness/path")` - sets readiness probe path to given path (default is `/ready`);
- `kubeprobes.WithVerboseOutput()` - enables verbose output by default (returns both failed and passed probes). - `kubeprobes.WithVerboseOutput()` - enables verbose output by default (returns both failed and passed probes).
## Probes ## Probes
In order to determine the state of particular element of application, probes need to be implemented either by creating [status determining function](#probe-functions) or by using simple and thread-safe [manual probes](#manual-probes). In order to determine the state of particular element of application, probes need to be implemented either by creating [probes from functions](#standard-probes) or by using simple and thread-safe [manual probes](#manual-probes).
### Probe functions ### Standard probes
Probe functions (instances of `ProbeFunction` interface) are wrappers for functions that performs user defined logic with given interval of updates in order to determine whether the probe should be marked as healthy or not. Those functions should take no arguments and return error (if no error is returned, the probe is considered to be healthy; if error is returned, the probe is considered to be unhealthy). If given interval is less or equal zero, then function is only checked on probe creation and remains in determined state forever. Probes (instances of `Probe` interface) are wrappers for functions that performs user defined logic with given interval of updates in order to determine whether the probe should be marked as healthy or not. Those functions should take no arguments and return error (if no error is returned, the probe is considered to be healthy; if error is returned, the probe is considered to be unhealthy). If given interval is less or equal zero, then function is only checked on probe creation and remains in determined state forever.
```go ```go
someProbe := kubeprobes.NewProbeFunction("live", func() error { someProbe := kubeprobes.NewProbe("live", func() error {
// Some logic here // Some logic here
if time.Now().Weekday() == time.Wednesday { if time.Now().Weekday() == time.Wednesday {
// Fail only on wednesday! // Fail only on wednesday!
@ -45,7 +47,7 @@ someProbe := kubeprobes.NewProbeFunction("live", func() error {
return nil return nil
}, 1 * time.Hour) }, 1 * time.Hour)
someOtherProbe := kubeprobes.NewProbeFunction("ready", func() error { someOtherProbe := kubeprobes.NewProbe("ready", func() error {
// Always healthy // Always healthy
return nil return nil
}, 0) // This probe is checked once }, 0) // This probe is checked once
@ -59,7 +61,7 @@ kp, _ := kubeprobes.New(
### Manual probes ### Manual probes
Manual probes (instances of `ManualProbe` interface) are objects that can be marked either as healthy or unhealthy and implement `ProbeFunction` for easy integration. Those objects utilize `sync.RMutex` mechanism to ensure thread-safety. Manual probes (instances of `ManualProbe` interface) are objects that can be marked either as healthy or unhealthy and implement `Probe` for easy integration. Those objects utilize `sync.RMutex` mechanism to ensure thread-safety.
Those probes can be changed by user with provided methods: Those probes can be changed by user with provided methods:
@ -78,7 +80,9 @@ kp, _ := kubeprobes.New(
kubeprobes.WithReadinessProbes(someOtherProbe), kubeprobes.WithReadinessProbes(someOtherProbe),
) )
// Can be later marked according // Can be later marked according to needs
someProbe.Pass()
someOtherProbe.FailWithCause(errors.New("I'm not doing anything!"))
``` ```
## Direct handler access ## Direct handler access
@ -105,9 +109,9 @@ appProbe := func() error {
return nil return nil
} }
// Create stateful probes // Create manual probes
live := kubeprobes.NewStatefulProbe() live := kubeprobes.NewManualProbe("liveness")
ready := kubeprobes.NewStatefulProbe() ready := kubeprobes.NewManualProbe("readiness")
// Prepare handler // Prepare handler
kp, err := kubeprobes.New( kp, err := kubeprobes.New(

View File

@ -1,147 +1,147 @@
package kubeprobes package kubeprobes
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"net/http" "net/http"
"strings" "strings"
) )
// Kubeprobes represents liveness & readiness probes handler. // Kubeprobes represents liveness & readiness probes handler.
type Kubeprobes interface { type Kubeprobes interface {
http.Handler http.Handler
// LivenessHandler returns [http.Handler] for liveness probes. // LivenessHandler returns [http.Handler] for liveness probes.
LivenessHandler() http.Handler LivenessHandler() http.Handler
// ReadinessHandler returns [http.Handler] for readiness probes. // ReadinessHandler returns [http.Handler] for readiness probes.
ReadinessHandler() http.Handler ReadinessHandler() http.Handler
} }
type kubeprobes struct { type kubeprobes struct {
livenessProbes []ProbeFunction livenessProbes []Probe
readinessProbes []ProbeFunction readinessProbes []Probe
verbose bool verbose bool
pathLive string pathLive string
pathReady string pathReady string
} }
// New returns a new instance of a Kubernetes probes with given options. // New returns a new instance of a Kubernetes probes with given options.
func New(options ...Option) (Kubeprobes, error) { func New(options ...Option) (Kubeprobes, error) {
kp := &kubeprobes{ kp := &kubeprobes{
livenessProbes: []ProbeFunction{}, livenessProbes: []Probe{},
readinessProbes: []ProbeFunction{}, readinessProbes: []Probe{},
pathLive: defaultLivenessPath, pathLive: defaultLivenessPath,
pathReady: defaultReadinessPath, pathReady: defaultReadinessPath,
} }
for _, option := range options { for _, option := range options {
option.apply(kp) option.apply(kp)
} }
if err := kp.validate(); err != nil { if err := kp.validate(); err != nil {
return nil, err return nil, err
} }
return kp, nil return kp, nil
} }
func (kp *kubeprobes) validate() error { func (kp *kubeprobes) validate() error {
var err error var err error
if kp.pathLive == "" { if kp.pathLive == "" {
err = errors.Join(err, fmt.Errorf("liveness probe path must not be empty")) err = errors.Join(err, fmt.Errorf("liveness probe path must not be empty"))
} }
if kp.pathReady == "" { if kp.pathReady == "" {
err = errors.Join(err, fmt.Errorf("readiness probe path must not be empty")) err = errors.Join(err, fmt.Errorf("readiness probe path must not be empty"))
} }
if !strings.HasPrefix(kp.pathLive, "/") { if !strings.HasPrefix(kp.pathLive, "/") {
err = errors.Join(err, fmt.Errorf("liveness probe path must start with slash (current: %q)", kp.pathLive)) err = errors.Join(err, fmt.Errorf("liveness probe path must start with slash (current: %q)", kp.pathLive))
} }
if !strings.HasPrefix(kp.pathReady, "/") { if !strings.HasPrefix(kp.pathReady, "/") {
err = errors.Join(err, fmt.Errorf("readiness probe path must start with slash (current: %q)", kp.pathReady)) err = errors.Join(err, fmt.Errorf("readiness probe path must start with slash (current: %q)", kp.pathReady))
} }
if kp.pathLive == kp.pathReady { if kp.pathLive == kp.pathReady {
err = errors.Join(err, fmt.Errorf("liveness and readiness probes have the same values (both %q)", kp.pathLive)) err = errors.Join(err, fmt.Errorf("liveness and readiness probes have the same values (both %q)", kp.pathLive))
} }
if len(kp.livenessProbes) == 0 { if len(kp.livenessProbes) == 0 {
err = errors.Join(err, fmt.Errorf("no liveness probes defined")) err = errors.Join(err, fmt.Errorf("no liveness probes defined"))
} }
if len(kp.readinessProbes) == 0 { if len(kp.readinessProbes) == 0 {
err = errors.Join(err, fmt.Errorf("no readiness probes defined")) err = errors.Join(err, fmt.Errorf("no readiness probes defined"))
} }
return err return err
} }
type probesResponse struct { type probesResponse struct {
Passed []statusEntry `json:"passed,omitempty"` Passed []statusEntry `json:"passed,omitempty"`
Failed []statusEntry `json:"failed,omitempty"` Failed []statusEntry `json:"failed,omitempty"`
} }
func (kp *kubeprobes) handleLiveness(w http.ResponseWriter, r *http.Request) { func (kp *kubeprobes) handleLiveness(w http.ResponseWriter, r *http.Request) {
sq := newStatusQuery(kp.livenessProbes) sq := newStatusQuery(kp.livenessProbes)
output := probesResponse{} output := probesResponse{}
sq.wait() sq.wait()
output.Failed = sq.failed output.Failed = sq.failed
if r.URL.Query().Has(verboseOutputFlag) || kp.verbose { if r.URL.Query().Has(verboseOutputFlag) || kp.verbose {
output.Passed = sq.passed output.Passed = sq.passed
} }
w.Header().Add(headerContentType, contentTypeJSON) w.Header().Add(headerContentType, contentTypeJSON)
if sq.ok { if sq.ok {
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
} else { } else {
w.WriteHeader(http.StatusServiceUnavailable) w.WriteHeader(http.StatusServiceUnavailable)
} }
_ = json.NewEncoder(w).Encode(output) _ = json.NewEncoder(w).Encode(output)
} }
func (kp *kubeprobes) handleReadiness(w http.ResponseWriter, r *http.Request) { func (kp *kubeprobes) handleReadiness(w http.ResponseWriter, r *http.Request) {
sq := newStatusQuery(append(kp.livenessProbes, kp.readinessProbes...)) sq := newStatusQuery(append(kp.livenessProbes, kp.readinessProbes...))
output := probesResponse{} output := probesResponse{}
sq.wait() sq.wait()
output.Failed = sq.failed output.Failed = sq.failed
if r.URL.Query().Has(verboseOutputFlag) || kp.verbose { if r.URL.Query().Has(verboseOutputFlag) || kp.verbose {
output.Passed = sq.passed output.Passed = sq.passed
} }
w.Header().Add(headerContentType, contentTypeJSON) w.Header().Add(headerContentType, contentTypeJSON)
if sq.ok { if sq.ok {
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
} else { } else {
w.WriteHeader(http.StatusServiceUnavailable) w.WriteHeader(http.StatusServiceUnavailable)
} }
_ = json.NewEncoder(w).Encode(output) _ = json.NewEncoder(w).Encode(output)
} }
// LivenessHandler implements Kubeprobes. // LivenessHandler implements Kubeprobes.
func (kp *kubeprobes) LivenessHandler() http.Handler { func (kp *kubeprobes) LivenessHandler() http.Handler {
return http.HandlerFunc(kp.handleLiveness) return http.HandlerFunc(kp.handleLiveness)
} }
// ReadinessHandler implements Kubeprobes. // ReadinessHandler implements Kubeprobes.
func (kp *kubeprobes) ReadinessHandler() http.Handler { func (kp *kubeprobes) ReadinessHandler() http.Handler {
return http.HandlerFunc(kp.handleReadiness) return http.HandlerFunc(kp.handleReadiness)
} }
// ServeHTTP implements Kubeprobes. // ServeHTTP implements Kubeprobes.
func (kp *kubeprobes) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (kp *kubeprobes) ServeHTTP(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path { switch r.URL.Path {
case kp.pathLive: case kp.pathLive:
kp.handleLiveness(w, r) kp.handleLiveness(w, r)
case kp.pathReady: case kp.pathReady:
kp.handleReadiness(w, r) kp.handleReadiness(w, r)
default: default:
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
} }
} }

View File

@ -12,7 +12,7 @@ func (o option) apply(kp *kubeprobes) {
} }
// WithLivenessProbes adds given probe functions to the set of liveness probes. // WithLivenessProbes adds given probe functions to the set of liveness probes.
func WithLivenessProbes(probes ...ProbeFunction) Option { func WithLivenessProbes(probes ...Probe) Option {
return option(func(kp *kubeprobes) { return option(func(kp *kubeprobes) {
kp.livenessProbes = append(kp.livenessProbes, probes...) kp.livenessProbes = append(kp.livenessProbes, probes...)
}) })
@ -26,7 +26,7 @@ func WithLivenessPath(path string) Option {
} }
// WithReadinessProbes adds given probe functions to the set of readiness probes. // WithReadinessProbes adds given probe functions to the set of readiness probes.
func WithReadinessProbes(probes ...ProbeFunction) Option { func WithReadinessProbes(probes ...Probe) Option {
return option(func(kp *kubeprobes) { return option(func(kp *kubeprobes) {
kp.readinessProbes = append(kp.readinessProbes, probes...) kp.readinessProbes = append(kp.readinessProbes, probes...)
}) })

View File

@ -1,182 +1,182 @@
package kubeprobes package kubeprobes
import ( import (
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"testing" "testing"
) )
func getStatusFromEndpoint(t *testing.T, client *http.Client, endpoint string) int { func getStatusFromEndpoint(t *testing.T, client *http.Client, endpoint string) int {
t.Helper() t.Helper()
resp, err := client.Get(endpoint) resp, err := client.Get(endpoint)
if err != nil { if err != nil {
t.Errorf("error getting status from endpoint: %s", err) t.Errorf("error getting status from endpoint: %s", err)
} }
return resp.StatusCode return resp.StatusCode
} }
func TestValidation(t *testing.T) { func TestValidation(t *testing.T) {
var ( var (
live, _ = NewManualProbe("live") live, _ = NewManualProbe("live")
ready, _ = NewManualProbe("ready") ready, _ = NewManualProbe("ready")
) )
tests := map[string]struct { tests := map[string]struct {
opts []Option opts []Option
expectedError bool expectedError bool
}{ }{
"no modifications and no error": { "no modifications and no error": {
opts: []Option{ opts: []Option{
WithLivenessProbes(live), WithLivenessProbes(live),
WithReadinessProbes(ready), WithReadinessProbes(ready),
}, },
}, },
"modifications and no error": { "modifications and no error": {
opts: []Option{ opts: []Option{
WithLivenessProbes(live), WithLivenessProbes(live),
WithReadinessProbes(ready), WithReadinessProbes(ready),
WithLivenessPath("/livez"), WithLivenessPath("/livez"),
WithReadinessPath("/readyz"), WithReadinessPath("/readyz"),
}, },
}, },
"missing liveness probes": { "missing liveness probes": {
opts: []Option{ opts: []Option{
WithReadinessProbes(ready), WithReadinessProbes(ready),
}, },
expectedError: true, expectedError: true,
}, },
"missing readiness probes": { "missing readiness probes": {
opts: []Option{ opts: []Option{
WithLivenessProbes(live), WithLivenessProbes(live),
}, },
expectedError: true, expectedError: true,
}, },
"liveness probe path empty": { "liveness probe path empty": {
opts: []Option{ opts: []Option{
WithLivenessProbes(live), WithLivenessProbes(live),
WithReadinessProbes(ready), WithReadinessProbes(ready),
WithLivenessPath(""), WithLivenessPath(""),
}, },
expectedError: true, expectedError: true,
}, },
"readiness probe path empty": { "readiness probe path empty": {
opts: []Option{ opts: []Option{
WithLivenessProbes(live), WithLivenessProbes(live),
WithReadinessProbes(ready), WithReadinessProbes(ready),
WithReadinessPath(""), WithReadinessPath(""),
}, },
expectedError: true, expectedError: true,
}, },
"liveness probe path does not start with slash": { "liveness probe path does not start with slash": {
opts: []Option{ opts: []Option{
WithLivenessProbes(live), WithLivenessProbes(live),
WithReadinessProbes(ready), WithReadinessProbes(ready),
WithLivenessPath("livez"), WithLivenessPath("livez"),
}, },
expectedError: true, expectedError: true,
}, },
"readiness probe path does not start with slash": { "readiness probe path does not start with slash": {
opts: []Option{ opts: []Option{
WithLivenessProbes(live), WithLivenessProbes(live),
WithReadinessProbes(ready), WithReadinessProbes(ready),
WithReadinessPath("readyz"), WithReadinessPath("readyz"),
}, },
expectedError: true, expectedError: true,
}, },
"liveness and readiness probe paths are equal": { "liveness and readiness probe paths are equal": {
opts: []Option{ opts: []Option{
WithLivenessProbes(live), WithLivenessProbes(live),
WithReadinessProbes(ready), WithReadinessProbes(ready),
WithLivenessPath("/check"), WithLivenessPath("/check"),
WithReadinessPath("/check"), WithReadinessPath("/check"),
}, },
expectedError: true, expectedError: true,
}, },
} }
for name, tc := range tests { for name, tc := range tests {
name, tc := name, tc name, tc := name, tc
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
_, err := New(tc.opts...) _, err := New(tc.opts...)
switch { switch {
case err == nil && tc.expectedError: case err == nil && tc.expectedError:
t.Error("expected error, but no error was returned") t.Error("expected error, but no error was returned")
case err != nil && !tc.expectedError: case err != nil && !tc.expectedError:
t.Errorf("expected no error but got %v", err) t.Errorf("expected no error but got %v", err)
} }
}) })
} }
} }
func TestHandler(t *testing.T) { func TestHandler(t *testing.T) {
var ( var (
live, _ = NewManualProbe("live") live, _ = NewManualProbe("live")
ready, _ = NewManualProbe("ready") ready, _ = NewManualProbe("ready")
) )
tests := map[string]struct { tests := map[string]struct {
livenessProbeTransformation func(*testing.T, ManualProbe) livenessProbeTransformation func(*testing.T, ManualProbe)
readinessProbeTransformation func(*testing.T, ManualProbe) readinessProbeTransformation func(*testing.T, ManualProbe)
expectedLiveStatus int expectedLiveStatus int
expectedReadyStatus int expectedReadyStatus int
}{ }{
"not live": { "not live": {
livenessProbeTransformation: markAsDown, livenessProbeTransformation: markAsDown,
readinessProbeTransformation: markAsDown, readinessProbeTransformation: markAsDown,
expectedLiveStatus: http.StatusServiceUnavailable, expectedLiveStatus: http.StatusServiceUnavailable,
expectedReadyStatus: http.StatusServiceUnavailable, expectedReadyStatus: http.StatusServiceUnavailable,
}, },
"live but not ready": { "live but not ready": {
livenessProbeTransformation: markAsUp, livenessProbeTransformation: markAsUp,
readinessProbeTransformation: markAsDown, readinessProbeTransformation: markAsDown,
expectedLiveStatus: http.StatusOK, expectedLiveStatus: http.StatusOK,
expectedReadyStatus: http.StatusServiceUnavailable, expectedReadyStatus: http.StatusServiceUnavailable,
}, },
"live and ready": { "live and ready": {
livenessProbeTransformation: markAsUp, livenessProbeTransformation: markAsUp,
readinessProbeTransformation: markAsUp, readinessProbeTransformation: markAsUp,
expectedLiveStatus: http.StatusOK, expectedLiveStatus: http.StatusOK,
expectedReadyStatus: http.StatusOK, expectedReadyStatus: http.StatusOK,
}, },
"ready but not live - should never happen": { "ready but not live - should never happen": {
livenessProbeTransformation: markAsDown, livenessProbeTransformation: markAsDown,
readinessProbeTransformation: markAsUp, readinessProbeTransformation: markAsUp,
expectedLiveStatus: http.StatusServiceUnavailable, expectedLiveStatus: http.StatusServiceUnavailable,
expectedReadyStatus: http.StatusServiceUnavailable, expectedReadyStatus: http.StatusServiceUnavailable,
}, },
} }
kp, err := New( kp, err := New(
WithLivenessProbes(live), WithLivenessProbes(live),
WithReadinessProbes(ready), WithReadinessProbes(ready),
) )
if err != nil { if err != nil {
t.Errorf("expected no error, got %v", err) t.Errorf("expected no error, got %v", err)
} }
srv := httptest.NewServer(kp) srv := httptest.NewServer(kp)
defer srv.Close() defer srv.Close()
client := srv.Client() client := srv.Client()
for name, test := range tests { for name, test := range tests {
name, test := name, test name, test := name, test
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
test.livenessProbeTransformation(t, live) test.livenessProbeTransformation(t, live)
test.readinessProbeTransformation(t, ready) test.readinessProbeTransformation(t, ready)
liveStatus := getStatusFromEndpoint(t, client, srv.URL+defaultLivenessPath) liveStatus := getStatusFromEndpoint(t, client, srv.URL+defaultLivenessPath)
readyStatus := getStatusFromEndpoint(t, client, srv.URL+defaultReadinessPath) readyStatus := getStatusFromEndpoint(t, client, srv.URL+defaultReadinessPath)
otherStatus := getStatusFromEndpoint(t, client, srv.URL+"/something") otherStatus := getStatusFromEndpoint(t, client, srv.URL+"/something")
if liveStatus != test.expectedLiveStatus { if liveStatus != test.expectedLiveStatus {
t.Errorf("expected live status %d, got %d", test.expectedLiveStatus, liveStatus) t.Errorf("expected live status %d, got %d", test.expectedLiveStatus, liveStatus)
} }
if readyStatus != test.expectedReadyStatus { if readyStatus != test.expectedReadyStatus {
t.Errorf("expected ready status %d, got %d", test.expectedReadyStatus, readyStatus) t.Errorf("expected ready status %d, got %d", test.expectedReadyStatus, readyStatus)
} }
if otherStatus != http.StatusNotFound { if otherStatus != http.StatusNotFound {
t.Errorf("expected 404 status, got %d", otherStatus) t.Errorf("expected 404 status, got %d", otherStatus)
} }
}) })
} }
} }

2990
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,18 +1,18 @@
{ {
"private": true, "private": true,
"name": "kubeprobes", "name": "kubeprobes",
"version": "1.3.0", "version": "1.3.2-rc.3",
"scripts": { "scripts": {
"release": "./node_modules/.bin/semantic-release" "release": "./node_modules/.bin/semantic-release"
}, },
"devDependencies": { "devDependencies": {
"@saithodev/semantic-release-gitea": "^2.1.0", "@saithodev/semantic-release-gitea": "^2.1.0",
"@semantic-release/changelog": "^6.0.3", "@semantic-release/changelog": "^6.0.3",
"@semantic-release/commit-analyzer": "^11.0.0", "@semantic-release/commit-analyzer": "^13.0.0",
"@semantic-release/git": "^10.0.1", "@semantic-release/git": "^10.0.1",
"@semantic-release/npm": "^11.0.1", "@semantic-release/npm": "^12.0.0",
"@semantic-release/release-notes-generator": "^12.0.1", "@semantic-release/release-notes-generator": "^14.0.0",
"conventional-changelog-conventionalcommits": "^7.0.2", "conventional-changelog-conventionalcommits": "^8.0.0",
"semantic-release": "^23.0.0" "semantic-release": "^24.0.0"
} }
} }

View File

@ -5,15 +5,15 @@ import (
"time" "time"
) )
// ProbeFunction is a wrapper for a function that determines whether // Probe is a wrapper for a function that determines whether
// the given metric may be marked as correctly functioning. // the given metric may be marked as correctly functioning.
// It not, the error should be returned. // It not, the error should be returned.
type ProbeFunction interface { type Probe interface {
name() string name() string
status() error status() error
} }
type probeFunction struct { type probe struct {
probeName string probeName string
probeFunc func() error probeFunc func() error
refreshInterval time.Duration refreshInterval time.Duration
@ -22,20 +22,20 @@ type probeFunction struct {
err error err error
} }
// NewProbeFunction returns new instance of [ProbeFunction]. // NewProbe returns new instance of [Probe].
// //
// If update interval is less or equal zero then probe is updated only // If update interval is less or equal zero then probe is updated only
// on its creation and remains in the same state forever. // on its creation and remains in the same state forever.
func NewProbeFunction( func NewProbe(
name string, name string,
fn func() error, fn func() error,
updateInterval time.Duration, updateInterval time.Duration,
) (ProbeFunction, error) { ) (Probe, error) {
if name == "" { if name == "" {
return nil, errProbeNameEmpty return nil, errProbeNameEmpty
} }
pf := &probeFunction{ pf := &probe{
probeName: name, probeName: name,
probeFunc: fn, probeFunc: fn,
refreshInterval: updateInterval, refreshInterval: updateInterval,
@ -47,25 +47,25 @@ func NewProbeFunction(
} }
// name implements ProbeFunction. // name implements ProbeFunction.
func (pf *probeFunction) name() string { func (pf *probe) name() string {
return pf.probeName return pf.probeName
} }
// status implements ProbeFunction. // status implements ProbeFunction.
func (pf *probeFunction) status() error { func (pf *probe) status() error {
pf.mux.RLock() pf.mux.RLock()
defer pf.mux.RUnlock() defer pf.mux.RUnlock()
return pf.err return pf.err
} }
func (pf *probeFunction) update() { func (pf *probe) update() {
err := pf.probeFunc() err := pf.probeFunc()
pf.mux.Lock() pf.mux.Lock()
pf.err = err pf.err = err
pf.mux.Unlock() pf.mux.Unlock()
} }
func (pf *probeFunction) autoUpdate() { func (pf *probe) autoUpdate() {
pf.update() pf.update()
if pf.refreshInterval <= 0 { if pf.refreshInterval <= 0 {
return return

View File

@ -7,7 +7,7 @@ import (
// ManualProbe represents the simple probe that can be either // ManualProbe represents the simple probe that can be either
// marked as "up" (healthy) or "down" (unhealthy). // marked as "up" (healthy) or "down" (unhealthy).
type ManualProbe interface { type ManualProbe interface {
ProbeFunction Probe
// Pass marks the probe as healthy. // Pass marks the probe as healthy.
Pass() Pass()

View File

@ -20,7 +20,7 @@ func (sq *statusQuery) wait() {
sq.wg.Wait() sq.wg.Wait()
} }
func newStatusQuery(probes []ProbeFunction) *statusQuery { func newStatusQuery(probes []Probe) *statusQuery {
sq := &statusQuery{ sq := &statusQuery{
ok: true, ok: true,
passed: make([]statusEntry, 0, len(probes)), passed: make([]statusEntry, 0, len(probes)),

View File

@ -6,28 +6,28 @@ import (
func TestStatusQueryIsAllGreen(t *testing.T) { func TestStatusQueryIsAllGreen(t *testing.T) {
var ( var (
probePassing, _ = NewProbeFunction("pass", func() error { probePassing, _ = NewProbe("pass", func() error {
return nil return nil
}, 0) }, 0)
probeFailing, _ = NewProbeFunction("fail", func() error { probeFailing, _ = NewProbe("fail", func() error {
return errProbeFailed return errProbeFailed
}, 0) }, 0)
) )
tests := map[string]struct { tests := map[string]struct {
probes []ProbeFunction probes []Probe
expectedStatus bool expectedStatus bool
}{ }{
"all green": { "all green": {
probes: []ProbeFunction{probePassing}, probes: []Probe{probePassing},
expectedStatus: true, expectedStatus: true,
}, },
"some failed": { "some failed": {
probes: []ProbeFunction{probePassing, probeFailing}, probes: []Probe{probePassing, probeFailing},
expectedStatus: false, expectedStatus: false,
}, },
"all failed": { "all failed": {
probes: []ProbeFunction{probeFailing}, probes: []Probe{probeFailing},
expectedStatus: false, expectedStatus: false,
}, },
} }