diff --git a/.circleci/.goreleaser.yml b/.circleci/.goreleaser.yml index dc46aaf..f6bc0cf 100644 --- a/.circleci/.goreleaser.yml +++ b/.circleci/.goreleaser.yml @@ -4,7 +4,7 @@ version: 2 builds: - id: heartbeat-build - dir: cmd + dir: cmd/heartbeat binary: heartbeat env: - CGO_ENABLED=0 diff --git a/CHANGELOG.md b/CHANGELOG.md index ef3beb6..679d179 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.1.2] - 2024-10-26 + +### Fixed + +- Fixed issue with package namespace + ## [0.1.1] - 2024-10-25 ### Added diff --git a/cmd/main.go b/cmd/heartbeat/main.go similarity index 92% rename from cmd/main.go rename to cmd/heartbeat/main.go index 75d0a74..4ff7bc2 100644 --- a/cmd/main.go +++ b/cmd/heartbeat/main.go @@ -3,8 +3,6 @@ package main import ( "flag" "fmt" - "heartbeat" - "heartbeat/cmd/version" "io" "log" "os" @@ -12,6 +10,8 @@ import ( "syscall" _ "github.com/lib/pq" + "github.com/obstools/go-prometheus-heartbeat-exporter/cmd/version" + "github.com/obstools/go-prometheus-heartbeat-exporter/pkg/heartbeat" ) var signals, logFatalf = make(chan os.Signal, 1), log.Fatalf diff --git a/cmd/main_test.go b/cmd/heartbeat/main_test.go similarity index 93% rename from cmd/main_test.go rename to cmd/heartbeat/main_test.go index 5e96246..7abbe5c 100644 --- a/cmd/main_test.go +++ b/cmd/heartbeat/main_test.go @@ -4,7 +4,6 @@ import ( "bytes" "errors" "flag" - "heartbeat/cmd/version" "io/fs" "log" "net" @@ -12,13 +11,14 @@ import ( "syscall" "testing" + "github.com/obstools/go-prometheus-heartbeat-exporter/cmd/version" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) func TestMain(t *testing.T) { t.Run("when error not happened", func(*testing.T) { - os.Args = []string{os.Args[0], "-config=../fixtures/config.yml"} + os.Args = []string{os.Args[0], "-config=../../fixtures/config.yml"} signals <- syscall.SIGINT assert.NotPanics(t, main) @@ -48,7 +48,7 @@ func TestMain(t *testing.T) { } func TestRun(t *testing.T) { - path, config := "some-path-to-the-program", "-config=../fixtures/config_without_instances.yml" + path, config := "some-path-to-the-program", "-config=../../fixtures/config_without_instances.yml" t.Run("when command line argument error", func(t *testing.T) { assert.Error(t, run([]string{path, "-not_existing_flag=42"}, flag.ContinueOnError)) diff --git a/cmd/test_mocks_test.go b/cmd/heartbeat/test_mocks_test.go similarity index 100% rename from cmd/test_mocks_test.go rename to cmd/heartbeat/test_mocks_test.go diff --git a/go.mod b/go.mod index 3e24209..cd5cea4 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module heartbeat +module github.com/obstools/go-prometheus-heartbeat-exporter go 1.23.0 diff --git a/configuration.go b/pkg/heartbeat/configuration.go similarity index 100% rename from configuration.go rename to pkg/heartbeat/configuration.go diff --git a/configuration_test.go b/pkg/heartbeat/configuration_test.go similarity index 87% rename from configuration_test.go rename to pkg/heartbeat/configuration_test.go index e3e174b..07a8327 100644 --- a/configuration_test.go +++ b/pkg/heartbeat/configuration_test.go @@ -37,7 +37,7 @@ func TestLoadConfiguration(t *testing.T) { }, }, } - actualConfiguration, err := loadConfiguration("./fixtures/config.yml") + actualConfiguration, err := loadConfiguration("../../fixtures/config.yml") assert.EqualValues(t, expectedConfiguration, actualConfiguration) assert.Nil(t, err) @@ -62,14 +62,14 @@ func TestLoadConfiguration(t *testing.T) { }, }, } - actualConfiguration, err := loadConfiguration("./fixtures/config_with_env.yml") + actualConfiguration, err := loadConfiguration("../../fixtures/config_with_env.yml") assert.EqualValues(t, expectedConfiguration, actualConfiguration) assert.Nil(t, err) }) t.Run("when configuration file not exists", func(t *testing.T) { - configurationPath := "./fixtures/config_not_existing.yml" + configurationPath := "../../fixtures/config_not_existing.yml" actualConfiguration, err := loadConfiguration(configurationPath) assert.EqualError(t, err, "open "+configurationPath+": no such file or directory") @@ -77,7 +77,7 @@ func TestLoadConfiguration(t *testing.T) { }) t.Run("when configuration file is a broken file", func(t *testing.T) { - configurationPath := "./fixtures/config" + configurationPath := "../../fixtures/config" actualConfiguration, err := loadConfiguration(configurationPath) assert.EqualError(t, err, "yaml: invalid trailing UTF-8 octet") @@ -85,7 +85,7 @@ func TestLoadConfiguration(t *testing.T) { }) t.Run("when configuration file is not a file", func(t *testing.T) { - configurationPath := "./fixtures" + configurationPath := "../../fixtures" actualConfiguration, err := loadConfiguration(configurationPath) assert.EqualError(t, err, "read "+configurationPath+": is a directory") @@ -93,7 +93,7 @@ func TestLoadConfiguration(t *testing.T) { }) t.Run("when configuration file is broken", func(t *testing.T) { - configurationPath := "./fixtures/config_broken.yml" + configurationPath := "../../fixtures/config_broken.yml" actualConfiguration, err := loadConfiguration(configurationPath) assert.EqualError(t, err, "yaml: line 7: did not find expected key") diff --git a/consts.go b/pkg/heartbeat/consts.go similarity index 100% rename from consts.go rename to pkg/heartbeat/consts.go diff --git a/exporter.go b/pkg/heartbeat/exporter.go similarity index 100% rename from exporter.go rename to pkg/heartbeat/exporter.go diff --git a/exporter_test.go b/pkg/heartbeat/exporter_test.go similarity index 100% rename from exporter_test.go rename to pkg/heartbeat/exporter_test.go diff --git a/heartbeat.go b/pkg/heartbeat/heartbeat.go similarity index 100% rename from heartbeat.go rename to pkg/heartbeat/heartbeat.go diff --git a/heartbeat_error.go b/pkg/heartbeat/heartbeat_error.go similarity index 100% rename from heartbeat_error.go rename to pkg/heartbeat/heartbeat_error.go diff --git a/heartbeat_error_test.go b/pkg/heartbeat/heartbeat_error_test.go similarity index 100% rename from heartbeat_error_test.go rename to pkg/heartbeat/heartbeat_error_test.go diff --git a/heartbeat_instance.go b/pkg/heartbeat/heartbeat_instance.go similarity index 100% rename from heartbeat_instance.go rename to pkg/heartbeat/heartbeat_instance.go diff --git a/heartbeat_instance_test.go b/pkg/heartbeat/heartbeat_instance_test.go similarity index 100% rename from heartbeat_instance_test.go rename to pkg/heartbeat/heartbeat_instance_test.go diff --git a/heartbeat_test.go b/pkg/heartbeat/heartbeat_test.go similarity index 73% rename from heartbeat_test.go rename to pkg/heartbeat/heartbeat_test.go index 3f34798..1a298c2 100644 --- a/heartbeat_test.go +++ b/pkg/heartbeat/heartbeat_test.go @@ -8,14 +8,14 @@ import ( func TestNew(t *testing.T) { t.Run("when configuration file is valid", func(t *testing.T) { - server, err := New("fixtures/config_without_instances.yml") + server, err := New("../../fixtures/config_without_instances.yml") assert.NotNil(t, server) assert.NoError(t, err) }) t.Run("when configuration file is invalid", func(t *testing.T) { - server, err := New("fixtures/config_broken.yml") + server, err := New("../../fixtures/config_broken.yml") assert.Nil(t, server) assert.Error(t, err) diff --git a/logger.go b/pkg/heartbeat/logger.go similarity index 100% rename from logger.go rename to pkg/heartbeat/logger.go diff --git a/logger_test.go b/pkg/heartbeat/logger_test.go similarity index 100% rename from logger_test.go rename to pkg/heartbeat/logger_test.go diff --git a/metric.go b/pkg/heartbeat/metric.go similarity index 100% rename from metric.go rename to pkg/heartbeat/metric.go diff --git a/metric_test.go b/pkg/heartbeat/metric_test.go similarity index 100% rename from metric_test.go rename to pkg/heartbeat/metric_test.go diff --git a/server.go b/pkg/heartbeat/server.go similarity index 100% rename from server.go rename to pkg/heartbeat/server.go diff --git a/server_test.go b/pkg/heartbeat/server_test.go similarity index 100% rename from server_test.go rename to pkg/heartbeat/server_test.go diff --git a/session.go b/pkg/heartbeat/session.go similarity index 100% rename from session.go rename to pkg/heartbeat/session.go diff --git a/session_postgres.go b/pkg/heartbeat/session_postgres.go similarity index 100% rename from session_postgres.go rename to pkg/heartbeat/session_postgres.go diff --git a/session_postgres_test.go b/pkg/heartbeat/session_postgres_test.go similarity index 100% rename from session_postgres_test.go rename to pkg/heartbeat/session_postgres_test.go diff --git a/session_test.go b/pkg/heartbeat/session_test.go similarity index 100% rename from session_test.go rename to pkg/heartbeat/session_test.go diff --git a/test_helpers_test.go b/pkg/heartbeat/test_helpers_test.go similarity index 100% rename from test_helpers_test.go rename to pkg/heartbeat/test_helpers_test.go diff --git a/test_mocks_test.go b/pkg/heartbeat/test_mocks_test.go similarity index 100% rename from test_mocks_test.go rename to pkg/heartbeat/test_mocks_test.go