Skip to content

Commit

Permalink
Bugfix/Issue with package namespace (#23)
Browse files Browse the repository at this point in the history
* Fixed issue with package namespace
* Updated changelog
  • Loading branch information
bestwebua authored Oct 26, 2024
1 parent 9dbe2c7 commit dbc10ed
Show file tree
Hide file tree
Showing 29 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .circleci/.goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: 2

builds:
- id: heartbeat-build
dir: cmd
dir: cmd/heartbeat
binary: heartbeat
env:
- CGO_ENABLED=0
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cmd/main.go → cmd/heartbeat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package main
import (
"flag"
"fmt"
"heartbeat"
"heartbeat/cmd/version"
"io"
"log"
"os"
"os/signal"
"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
Expand Down
6 changes: 3 additions & 3 deletions cmd/main_test.go → cmd/heartbeat/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import (
"bytes"
"errors"
"flag"
"heartbeat/cmd/version"
"io/fs"
"log"
"net"
"os"
"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)
Expand Down Expand Up @@ -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))
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module heartbeat
module github.com/obstools/go-prometheus-heartbeat-exporter

go 1.23.0

Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions configuration_test.go → pkg/heartbeat/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -62,38 +62,38 @@ 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")
assert.Nil(t, actualConfiguration)
})

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")
assert.Nil(t, actualConfiguration)
})

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")
assert.Nil(t, actualConfiguration)
})

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")
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions heartbeat_test.go → pkg/heartbeat/heartbeat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit dbc10ed

Please sign in to comment.