refactor: dedicated constants package, no explicit bridge version

This commit is contained in:
James Houlahan
2020-04-23 10:07:41 +02:00
committed by Jakub Cuth
parent 32ca7b3903
commit 522cadb8b1
11 changed files with 88 additions and 42 deletions

View File

@ -1,9 +1,9 @@
.PHONY: check-has-go install-godog test test-live test-debug test-live-debug
export GO111MODULE=on
export VERSION:=1.2.5-integrationtest
export VERBOSITY?=fatal
export TEST_DATA=testdata
export VERSION:=dev-integrationtests
check-has-go:
@which go || (echo "Install Go-lang!" && exit 1)

View File

@ -18,11 +18,11 @@
package context
import (
"os"
"runtime"
"github.com/ProtonMail/proton-bridge/internal/bridge"
"github.com/ProtonMail/proton-bridge/internal/preferences"
"github.com/ProtonMail/proton-bridge/pkg/constants"
"github.com/ProtonMail/proton-bridge/pkg/listener"
)
@ -64,13 +64,12 @@ func newBridgeInstance(
eventListener listener.Listener,
clientManager bridge.ClientManager,
) *bridge.Bridge {
version := os.Getenv("VERSION")
bridge.UpdateCurrentUserAgent(version, runtime.GOOS, "", "")
bridge.UpdateCurrentUserAgent(constants.Version, runtime.GOOS, "", "")
panicHandler := &panicHandler{t: t}
pref := preferences.New(cfg)
return bridge.New(cfg, pref, panicHandler, eventListener, version, clientManager, credStore)
return bridge.New(cfg, pref, panicHandler, eventListener, clientManager, credStore)
}
// SetLastBridgeError sets the last error that occurred while executing a bridge action.

View File

@ -23,6 +23,7 @@ import (
"os"
"path/filepath"
"github.com/ProtonMail/gopenpgp/constants"
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
)
@ -48,13 +49,16 @@ func (c *fakeConfig) ClearData() error {
}
func (c *fakeConfig) GetAPIConfig() *pmapi.ClientConfig {
return &pmapi.ClientConfig{
AppVersion: "Bridge_" + os.Getenv("VERSION"),
AppVersion: "Bridge_" + constants.Version,
ClientID: "bridge",
}
}
func (c *fakeConfig) GetDBDir() string {
return c.dir
}
func (c *fakeConfig) GetVersion() string {
return constants.Version
}
func (c *fakeConfig) GetLogDir() string {
return c.dir
}

View File

@ -22,6 +22,7 @@ import (
"os"
"testing"
"github.com/ProtonMail/proton-bridge/pkg/constants"
"github.com/cucumber/godog"
"github.com/cucumber/godog/colors"
)
@ -33,6 +34,9 @@ var opt = godog.Options{ //nolint[gochecknoglobals]
func init() { //nolint[gochecknoinits]
godog.BindFlags("godog.", flag.CommandLine, &opt)
// This would normally be done using ldflags but `godog` command doesn't support that.
constants.Version = os.Getenv("VERSION")
}
func TestMain(m *testing.M) {
@ -46,5 +50,6 @@ func TestMain(m *testing.M) {
if st := m.Run(); st > status {
status = st
}
os.Exit(status)
}