Skip to content

Commit

Permalink
(#46) fix: change BuildInformation to an interface
Browse files Browse the repository at this point in the history
  • Loading branch information
majohn-r committed Oct 28, 2024
1 parent 9f6db97 commit 26871ed
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@ Key to symbols
- 😒 change is invisible to the user
- 🆕 new feature

## v0.24.1

_release `2024.10.28`_

- 🐛⚠️ change `BuildInformation` from a `struct` to an `interface` for easier mocking by consumers. Consequently,
`GetBuildInfo` returns an _implementation_ of `BuildInformation` instead of a pointer to an instance of
`BuildInformation`.

## v0.24.0

_release `2024.10.27`_
_release `2024.10.28`_

- 🆕add `GetBuildData(reader func() (*debug.BuildInfo, bool)) *BuildInformation`; this also adds the `BuildInformation`
struct and four methods on `*BuildInformation`:
Expand Down
27 changes: 17 additions & 10 deletions about.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,44 @@ import (
"github.com/majohn-r/output"
)

// BuildInformation holds data about the build
type BuildInformation struct {
// BuildInformation provides data about the build
type BuildInformation interface {
GoVersion() string
Dependencies() []string
MainVersion() string
Settings() []string
}

type buildInformation struct {
goVersion string
dependencies []string
mainVersion string
settings []string
}

// GoVersion returns the version of Go used to build the code
func (bi *BuildInformation) GoVersion() string {
func (bi *buildInformation) GoVersion() string {
return bi.goVersion
}

// Dependencies returns an alphabetically sorted slice of dependency data (path and version for each dependency)
func (bi *BuildInformation) Dependencies() []string {
func (bi *buildInformation) Dependencies() []string {
return bi.dependencies
}

// MainVersion returns the git version of the main module
func (bi *BuildInformation) MainVersion() string {
func (bi *buildInformation) MainVersion() string {
return bi.mainVersion
}

// Settings returns an alphabetically sorted slice of build settings used to build the code
func (bi *BuildInformation) Settings() []string {
func (bi *buildInformation) Settings() []string {
return bi.settings
}

// GetBuildData returns the build data, if any, obtained from the provided reader function
func GetBuildData(reader func() (*debug.BuildInfo, bool)) *BuildInformation {
bi := &BuildInformation{
func GetBuildData(reader func() (*debug.BuildInfo, bool)) BuildInformation {
bi := &buildInformation{
goVersion: "unknown",
dependencies: []string{},
mainVersion: "unknown",
Expand Down Expand Up @@ -76,8 +83,8 @@ func GetBuildData(reader func() (*debug.BuildInfo, bool)) *BuildInformation {
// callers, pass in debug.ReadBuildInfo
func InterpretBuildData(buildInfoReader func() (*debug.BuildInfo, bool)) (goVersion string, dependencies []string) {
bi := GetBuildData(buildInfoReader)
goVersion = bi.goVersion
dependencies = bi.dependencies
goVersion = bi.GoVersion()
dependencies = bi.Dependencies()
return
}

Expand Down

0 comments on commit 26871ed

Please sign in to comment.