aboutsummaryrefslogtreecommitdiff
path: root/worker_test.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2025-07-25 02:30:37 +0700
committerShulhan <ms@kilabit.info>2025-07-29 00:31:23 +0700
commit0537c5e094c7b6e5ff376ccdf0dba80adf5c4342 (patch)
treeb8c2c3621c1e76c5182acdc2f09291b796792a9e /worker_test.go
parent3d4c7b48674cd553ce8f670933af9b609992ae77 (diff)
downloadlilin-0537c5e094c7b6e5ff376ccdf0dba80adf5c4342.tar.xz
all: refactoring Service to create with ServiceOptions
Instead of defining the options in the Service, create it in the ServiceOptions and pass it to NewService function. In this way, we can check it, initialize it, and set default value. The Address option now use URL with scheme, so we can derive the service type based on the scheme, for example "http://" for HTTP based service, "tcp://xxx" for TCP based service, and so on.
Diffstat (limited to 'worker_test.go')
-rw-r--r--worker_test.go47
1 files changed, 34 insertions, 13 deletions
diff --git a/worker_test.go b/worker_test.go
index b8c7494..83fcc69 100644
--- a/worker_test.go
+++ b/worker_test.go
@@ -4,7 +4,9 @@
package lilin
import (
+ "net/url"
"testing"
+ "time"
"git.sr.ht/~shulhan/pakakeh.go/lib/test"
)
@@ -26,23 +28,42 @@ func TestNewWorker(t *testing.T) {
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`,
+ opts: ServiceOptions{
+ scanURL: &url.URL{
+ Scheme: `http`,
+ Host: `127.0.0.1:6121`,
+ Path: `/health`,
+ },
+ Name: `example http`,
+ HTTPMethod: `GET`,
+ Address: `http://127.0.0.1:6121/health`,
+ Timeout: `5s`,
+ timeout: 5 * time.Second,
+ },
},
`example tcp`: &Service{
- Name: `example tcp`,
- Type: `tcp`,
- Address: `127.0.0.1:6122`,
- Timeout: `5s`,
+ opts: ServiceOptions{
+ scanURL: &url.URL{
+ Scheme: `tcp`,
+ Host: `127.0.0.1:6122`,
+ },
+ Name: `example tcp`,
+ Address: `tcp://127.0.0.1:6122`,
+ Timeout: `5s`,
+ timeout: 5 * time.Second,
+ },
},
`example udp`: &Service{
- Name: `example udp`,
- Type: `udp`,
- Address: `127.0.0.1:6123`,
- Timeout: `5s`,
+ opts: ServiceOptions{
+ scanURL: &url.URL{
+ Scheme: `udp`,
+ Host: `127.0.0.1:6123`,
+ },
+ Name: `example udp`,
+ Address: `udp://127.0.0.1:6123`,
+ Timeout: `5s`,
+ timeout: 5 * time.Second,
+ },
},
},
}}