aboutsummaryrefslogtreecommitdiff
path: root/worker_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'worker_test.go')
-rw-r--r--worker_test.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/worker_test.go b/worker_test.go
new file mode 100644
index 0000000..b8c7494
--- /dev/null
+++ b/worker_test.go
@@ -0,0 +1,58 @@
+// SPDX-FileCopyrightText: 2025 M. Shulhan <ms@kilabit.info>
+// SPDX-License-Identifier: GPL-3.0-only
+
+package lilin
+
+import (
+ "testing"
+
+ "git.sr.ht/~shulhan/pakakeh.go/lib/test"
+)
+
+func TestNewWorker(t *testing.T) {
+ type testCase struct {
+ expServices map[string]*Service
+ configDir string
+ expError string
+ }
+
+ var listCase = []testCase{{
+ configDir: `testdata/worker/withoutServiceDir/etc/lilin/`,
+ expError: `open testdata/worker/withoutServiceDir/etc/lilin/service.d: no such file or directory`,
+ }, {
+ configDir: `testdata/worker/readError/etc/lilin/`,
+ expError: `open testdata/worker/readError/etc/lilin/service.d/broken.cfg: no such file or directory`,
+ }, {
+ configDir: `testdata/etc/lilin/`,
+ expServices: map[string]*Service{
+ `example http`: &Service{
+ Name: `example http`,
+ Type: `http`,
+ Method: `GET`,
+ Address: `http://127.0.0.1:6121/health`,
+ Timeout: `5s`,
+ },
+ `example tcp`: &Service{
+ Name: `example tcp`,
+ Type: `tcp`,
+ Address: `127.0.0.1:6122`,
+ Timeout: `5s`,
+ },
+ `example udp`: &Service{
+ Name: `example udp`,
+ Type: `udp`,
+ Address: `127.0.0.1:6123`,
+ Timeout: `5s`,
+ },
+ },
+ }}
+
+ for _, tcase := range listCase {
+ wrk, err := newWorker(tcase.configDir)
+ if err != nil {
+ test.Assert(t, ``, tcase.expError, err.Error())
+ continue
+ }
+ test.Assert(t, `worker.Services`, tcase.expServices, wrk.Services)
+ }
+}