Skip to content
Open
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
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ on:
permissions:
contents: write

env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true

jobs:
lint:
name: Lint
Expand Down
87 changes: 50 additions & 37 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ import (
"github.com/Owloops/updo/net"
)

const (
testURL = "https://example.com"
googleURL = "https://google.com"
githubURL = "https://github.com"
unnamedURL = "https://unnamed.com"
overrideURL = "https://override.example.com"
inheritURL = "https://inherit.example.com"
unlimitedURL = "https://unlimited.example.com"
exampleStr = "Example"
googleStr = "Google"
githubStr = "GitHub"
)

func TestLoadConfig(t *testing.T) {
configContent := `
[global]
Expand All @@ -17,8 +30,8 @@ follow_redirects = false
receive_alert = false

[[targets]]
url = "https://example.com"
name = "Example"
url = "` + testURL + `"
name = "` + exampleStr + `"
refresh_interval = 60
timeout = 20
method = "POST"
Expand Down Expand Up @@ -58,11 +71,11 @@ method = "POST"
}

target := config.Targets[0]
if target.URL != "https://example.com" {
t.Errorf("Expected URL=https://example.com, got %s", target.URL)
if target.URL != testURL {
t.Errorf("Expected URL=%s, got %s", testURL, target.URL)
}
if target.Name != "Example" {
t.Errorf("Expected Name=Example, got %s", target.Name)
if target.Name != exampleStr {
t.Errorf("Expected Name=%s, got %s", exampleStr, target.Name)
}
if target.RefreshInterval != 60 {
t.Errorf("Expected RefreshInterval=60, got %d", target.RefreshInterval)
Expand All @@ -84,15 +97,15 @@ receive_alert = true
skip_ssl = true

[[targets]]
url = "https://override.example.com"
url = "` + overrideURL + `"
name = "Override"
follow_redirects = false
accept_redirects = false
receive_alert = false
skip_ssl = false

[[targets]]
url = "https://inherit.example.com"
url = "` + inheritURL + `"
name = "Inherit"
`

Expand Down Expand Up @@ -162,16 +175,16 @@ func TestBodySizeLimitInheritance(t *testing.T) {
body_size_limit = 2097152

[[targets]]
url = "https://inherit.example.com"
url = "` + inheritURL + `"
name = "Inherit"

[[targets]]
url = "https://override.example.com"
url = "` + overrideURL + `"
name = "Override"
body_size_limit = 524288

[[targets]]
url = "https://unlimited.example.com"
url = "` + unlimitedURL + `"
name = "Unlimited"
body_size_limit = 0
`
Expand Down Expand Up @@ -218,7 +231,7 @@ body_size_limit = 0
func TestBodySizeLimitDefault(t *testing.T) {
configContent := `
[[targets]]
url = "https://example.com"
url = "` + testURL + `"
`

tmpFile, err := os.CreateTemp("", "test-config-bodysize-default-*.toml")
Expand Down Expand Up @@ -254,7 +267,7 @@ url = "https://example.com"
func TestLoadConfigDefaults(t *testing.T) {
configContent := `
[[targets]]
url = "https://example.com"
url = "` + testURL + `"
`

tmpFile, err := os.CreateTemp("", "test-config-defaults-*.toml")
Expand Down Expand Up @@ -328,10 +341,10 @@ func TestGlobalGetMethods(t *testing.T) {
func TestFilterTargets(t *testing.T) {
config := &Config{
Targets: []Target{
{URL: "https://example.com", Name: "Example"},
{URL: "https://google.com", Name: "Google"},
{URL: "https://github.com", Name: "GitHub"},
{URL: "https://unnamed.com"},
{URL: testURL, Name: exampleStr},
{URL: googleURL, Name: googleStr},
{URL: githubURL, Name: githubStr},
{URL: unnamedURL},
},
}

Expand All @@ -348,29 +361,29 @@ func TestFilterTargets(t *testing.T) {
},
{
name: "only by name",
only: []string{"Example"},
only: []string{exampleStr},
expected: 1,
expectURL: "https://example.com",
expectURL: testURL,
},
{
name: "only by URL",
only: []string{"https://google.com"},
only: []string{googleURL},
expected: 1,
expectURL: "https://google.com",
expectURL: googleURL,
},
{
name: "skip by name",
skip: []string{"Google"},
skip: []string{googleStr},
expected: 3,
},
{
name: "skip by URL for unnamed target",
skip: []string{"https://unnamed.com"},
skip: []string{unnamedURL},
expected: 3,
},
{
name: "only multiple",
only: []string{"Example", "GitHub"},
only: []string{exampleStr, githubStr},
expected: 2,
},
}
Expand Down Expand Up @@ -398,13 +411,13 @@ func TestGetTargetName(t *testing.T) {
}{
{
name: "with name",
target: Target{Name: "Example", URL: "https://example.com"},
expected: "Example",
target: Target{Name: exampleStr, URL: testURL},
expected: exampleStr,
},
{
name: "without name",
target: Target{URL: "https://example.com"},
expected: "https://example.com",
target: Target{URL: testURL},
expected: testURL,
},
}

Expand All @@ -428,23 +441,23 @@ func TestContainsTarget(t *testing.T) {
}{
{
name: "found by target name",
list: []string{"Example", "Google"},
target: "Example",
url: "https://example.com",
list: []string{exampleStr, googleStr},
target: exampleStr,
url: testURL,
expected: true,
},
{
name: "found by URL",
list: []string{"Example", "https://google.com"},
target: "Google",
url: "https://google.com",
list: []string{exampleStr, googleURL},
target: googleStr,
url: googleURL,
expected: true,
},
{
name: "not found",
list: []string{"Example", "Google"},
target: "GitHub",
url: "https://github.com",
list: []string{exampleStr, googleStr},
target: githubStr,
url: githubURL,
expected: false,
},
}
Expand Down
21 changes: 8 additions & 13 deletions metrics/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ import (
"github.com/Owloops/updo/net"
)

const (
testUser = "user"
testPass = "pass"
)

func TestWriteClient(t *testing.T) {
cfg := NewConfig()
client := NewWriteClient(cfg)
Expand All @@ -27,7 +22,7 @@ func TestWriteClient(t *testing.T) {
t.Fatal("WriteClient not properly initialized")
}

target := config.Target{Name: "test", URL: "https://example.com"}
target := config.Target{Name: "test", URL: testURL}
result := net.WebsiteCheckResult{URL: target.URL, IsUp: true, StatusCode: 200}

initialCount := len(client.samples)
Expand All @@ -49,7 +44,7 @@ func TestWriteClient(t *testing.T) {

func TestSSLExpiry(t *testing.T) {
client := NewWriteClient(NewConfig())
target := config.Target{Name: "ssl-test", URL: "https://example.com"}
target := config.Target{Name: "ssl-test", URL: testURL}

tests := []struct {
days int
Expand All @@ -72,17 +67,17 @@ func TestNormalizeTimestamps(t *testing.T) {
client := NewWriteClient(NewConfig())
samples := []*prompb.TimeSeries{
{
Labels: []*prompb.Label{{Name: "__name__", Value: "test1"}},
Labels: []*prompb.Label{{Name: _nameLbl, Value: "test1"}},
Samples: []*prompb.Sample{{Timestamp: 0, Value: 1.0}, {Timestamp: 0, Value: 2.0}},
},
{
Labels: []*prompb.Label{{Name: "__name__", Value: "test2"}},
Labels: []*prompb.Label{{Name: _nameLbl, Value: "test2"}},
Samples: []*prompb.Sample{{Timestamp: 0, Value: 3.0}},
},
nil,
{Labels: []*prompb.Label{{Name: "__name__", Value: "empty"}}, Samples: []*prompb.Sample{}},
{Labels: []*prompb.Label{{Name: _nameLbl, Value: emptyStr}}, Samples: []*prompb.Sample{}},
{
Labels: []*prompb.Label{{Name: "__name__", Value: "mixed"}},
Labels: []*prompb.Label{{Name: _nameLbl, Value: "mixed"}},
Samples: []*prompb.Sample{nil, {Timestamp: 0, Value: 4.0}},
},
}
Expand Down Expand Up @@ -112,7 +107,7 @@ func TestNormalizeTimestamps(t *testing.T) {

func TestConcurrentAccess(t *testing.T) {
client := NewWriteClient(NewConfig())
target := config.Target{Name: "concurrent", URL: "https://example.com"}
target := config.Target{Name: "concurrent", URL: testURL}
result := net.WebsiteCheckResult{URL: target.URL, IsUp: true}

var wg sync.WaitGroup
Expand Down Expand Up @@ -143,7 +138,7 @@ func TestHTTPRequests(t *testing.T) {
header bool
expect bool
}{
{"success", 200, "", false, false, true},
{successStr, 200, "", false, false, true},
{"error", 400, "out of order", false, false, false},
{"auth", 200, "", true, false, true},
{"headers", 200, "", false, true, true},
Expand Down
12 changes: 12 additions & 0 deletions metrics/common_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package metrics

const (
testURL = "https://example.com"
apiURL = "https://api.com"
brokenURL = "https://broken.com"
secureURL = "https://secure.com"
emptyStr = "empty"
successStr = "success"
testUser = "user"
testPass = "pass"
)
Loading