Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ jobs:
- name: Check out code
uses: actions/checkout@v3

- name: Download Go modules
run: go mod tidy

- name: Build packages
run: go build ./...

- name: golangci-lint
uses: golangci/golangci-lint-action@v8
with:
Expand Down
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
module github.com/MowlCoder/heimdall

go 1.24.2

require github.com/stretchr/testify v1.11.1

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
83 changes: 83 additions & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package config

import (
"testing"

"github.com/MowlCoder/heimdall/internal/domain"
"github.com/stretchr/testify/assert"
)

func Test_Enablement_Notifiers(t *testing.T) {

cfg := &Config{

Services: []domain.Service{

{Name: "My Personal Website", URL: "https://example.com"},
},
Notifiers: struct {
Telegram *struct {
ChatID string "json:\"chatId\""
BotToken string "json:\"botToken\""
Enabled bool "json:\"enabled\""
}
Discord *struct {
Webhook string "json:\"webhook\""
Enabled bool "json:\"enabled\""
}
Slack *struct {
ChatID string "json:\"chatId\""
BotToken string "json:\"botToken\""
Enabled bool "json:\"enabled\""
}
Webhook *struct {
Webhook string "json:\"webhook\""
Enabled bool "json:\"enabled\""
}
}{

Telegram: &struct {
ChatID string "json:\"chatId\""
BotToken string "json:\"botToken\""
Enabled bool "json:\"enabled\""
}{

ChatID: "-123456789",
BotToken: "secret-telegram-bot-token",
Enabled: true,
},
Slack: &struct {
ChatID string "json:\"chatId\""
BotToken string "json:\"botToken\""
Enabled bool "json:\"enabled\""
}{
ChatID: "RandomTest",
BotToken: "xoxosecret-slack-bot-token",
Enabled: true,
},
Discord: &struct {
Webhook string "json:\"webhook\""
Enabled bool "json:\"enabled\""
}{
Webhook: "random",
Enabled: true,
},
Webhook: &struct {
Webhook string "json:\"webhook\""
Enabled bool "json:\"enabled\""
}{
Webhook: "randomWebhook",
Enabled: true,
},
},
}

checkTelegram := cfg.IsTelegramEnabled()
assert.True(t, checkTelegram)
checkSlack := cfg.IsSlackEnabled()
assert.True(t, checkSlack)
checkDiscord := cfg.IsDiscordEnabled()
assert.True(t, checkDiscord)
checkWebhook := cfg.IsWebhookEnabled()
assert.True(t, checkWebhook)
}
74 changes: 74 additions & 0 deletions internal/domain/service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package domain

import (
"testing"
)

func Test_ParseInterval(t *testing.T) {

TestCases := []Service{
{

Name: "TestIntervalString",
Interval: "5m",
},
{

Name: "TestNumber",
Interval: "1",
},
{

Name: "TestRandom",
Interval: "1m",
},
}

for _, tc := range TestCases {

t.Run(tc.Name, func(t *testing.T) {

_, err := tc.ParseInterval()

if err != nil {

t.Errorf("Test case failed: Failed to parse the Interval %v", err)
}

})

}

}

func Test_ParseIntervalOnlyString(t *testing.T) {

TestCases := []Service{
{

Name: "TestIntervalString",
Interval: "m",
},
{

Name: "TestNumber",
Interval: "s",
},
}

for _, tc := range TestCases {

t.Run(tc.Name, func(t *testing.T) {

_, err := tc.ParseInterval()

if err == nil {

t.Error("Only String Interval pasrse, Test Case Failed")
}

})

}

}
35 changes: 35 additions & 0 deletions internal/notifier/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package notifier

import (
"fmt"
"testing"
)

func Test_StatusCheck(t *testing.T) {

TestCases := []int{200, 400, 300, 500}
statusCodeTextMap := map[int]string{
200: "Success",
300: "Redirect",
400: "Client Error",
500: "Server Error",
}

for _, tc := range TestCases {

t.Run("Status Code Text test", func(t *testing.T) {

text := getStatusText(tc)

if text != statusCodeTextMap[tc] {

fmt.Println(statusCodeTextMap[tc])

t.Errorf("Text to status code mapping is incorrect for %v", tc)
}

})

}

}
Loading