initial
This commit is contained in:
28
internal/globals/globals.go
Normal file
28
internal/globals/globals.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package globals
|
||||
|
||||
import (
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
// these get populated from main() and copied into the Globals object.
|
||||
var (
|
||||
Appname string
|
||||
Version string
|
||||
Buildarch string
|
||||
)
|
||||
|
||||
type Globals struct {
|
||||
Appname string
|
||||
Version string
|
||||
Buildarch string
|
||||
}
|
||||
|
||||
// nolint:revive // lc parameter is required by fx even if unused
|
||||
func New(lc fx.Lifecycle) (*Globals, error) {
|
||||
n := &Globals{
|
||||
Appname: Appname,
|
||||
Buildarch: Buildarch,
|
||||
Version: Version,
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
30
internal/globals/globals_test.go
Normal file
30
internal/globals/globals_test.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package globals
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"go.uber.org/fx/fxtest"
|
||||
)
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
// Set test values
|
||||
Appname = "test-app"
|
||||
Version = "1.0.0"
|
||||
Buildarch = "test-arch"
|
||||
|
||||
lc := fxtest.NewLifecycle(t)
|
||||
globals, err := New(lc)
|
||||
if err != nil {
|
||||
t.Fatalf("New() error = %v", err)
|
||||
}
|
||||
|
||||
if globals.Appname != "test-app" {
|
||||
t.Errorf("Appname = %v, want %v", globals.Appname, "test-app")
|
||||
}
|
||||
if globals.Version != "1.0.0" {
|
||||
t.Errorf("Version = %v, want %v", globals.Version, "1.0.0")
|
||||
}
|
||||
if globals.Buildarch != "test-arch" {
|
||||
t.Errorf("Buildarch = %v, want %v", globals.Buildarch, "test-arch")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user