diff --git a/go.sum b/go.sum index 81cc42b6a89ad52ef71d09dc95a9574368ca99e7..c70612451b8fe7b29bbb14d8afd5ae937e309aee 100644 --- a/go.sum +++ b/go.sum @@ -82,10 +82,6 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/iotaledger/hive.go v0.0.0-20191229233341-c3732738ee20 h1:ZIJAeQSEdmVbmZNIW2198IwD23+wBteb4WE4pyjxk+c= -github.com/iotaledger/hive.go v0.0.0-20191229233341-c3732738ee20/go.mod h1:7iqun29a1x0lymTrn0UJ3Z/yy0sUzUpoOZ1OYMrYN20= -github.com/iotaledger/hive.go v0.0.0-20200107010340-3674684388b3 h1:Ognd+3Z0qhQz9LAAwKA6ma8nDiDfClEIsxrUfZnvmmU= -github.com/iotaledger/hive.go v0.0.0-20200107010340-3674684388b3/go.mod h1:vrZrvGaWT1o5kz3Jj2B/PcUtqsFzZnLWrO3zEsGSuwk= github.com/iotaledger/hive.go v0.0.0-20200107124343-d0fddfc88dea h1:kLGh9F6KOOygmJPynFSgy7DSlFOg4/x5jmOMOF8vFaA= github.com/iotaledger/hive.go v0.0.0-20200107124343-d0fddfc88dea/go.mod h1:vrZrvGaWT1o5kz3Jj2B/PcUtqsFzZnLWrO3zEsGSuwk= github.com/iotaledger/iota.go v1.0.0-beta.9/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8= @@ -303,6 +299,7 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= diff --git a/packages/parameter/parameter.go b/packages/parameter/parameter.go index 86cfd4503c44189455f2c44b613a5cad0ae34d70..fa1adfee757902a5e66d847b47800381db05bab0 100644 --- a/packages/parameter/parameter.go +++ b/packages/parameter/parameter.go @@ -1,19 +1,18 @@ package parameter import ( + "github.com/iotaledger/hive.go/parameter" flag "github.com/spf13/pflag" "github.com/spf13/viper" - - "github.com/iotaledger/hive.go/parameter" ) var ( // flags - configName = flag.StringP("config", "c", "config", "Filename of the config file without the file extension") - configDirPath = flag.StringP("config-dir", "d", ".", "Path to the directory containing the config file") + configName = flag.StringP("config", "c", "config", "Filename of the config file without the file extension") + configDirPath = flag.StringP("config-dir", "d", ".", "Path to the directory containing the config file") // Viper - NodeConfig = viper.New() + NodeConfig = viper.New() ) // FetchConfig fetches config values from a dir defined via CLI flag --config-dir (or the current working dir if not set). @@ -21,7 +20,6 @@ var ( // It automatically reads in a single config file starting with "config" (can be changed via the --config CLI flag) // and ending with: .json, .toml, .yaml or .yml (in this sequence). func FetchConfig(printConfig bool, ignoreSettingsAtPrint ...[]string) error { - err := parameter.LoadConfigFile(NodeConfig, *configDirPath, *configName, true, false) if err != nil { return err @@ -32,3 +30,18 @@ func FetchConfig(printConfig bool, ignoreSettingsAtPrint ...[]string) error { } return nil } + +// LoadDefaultConfig only binds the flags, but does not load any config file. +func LoadDefaultConfig(printConfig bool) error { + // only bind the flags + flag.Parse() + err := NodeConfig.BindPFlags(flag.CommandLine) + if err != nil { + return err + } + + if printConfig { + parameter.PrintConfig(NodeConfig) + } + return nil +} diff --git a/plugins/bundleprocessor/bundleprocessor_test.go b/plugins/bundleprocessor/bundleprocessor_test.go index f1b52a48f07f89415e18ced6e3e1ef658aa338ef..484d6a29b3df434e2f97e49c7985d5c9e6b6480a 100644 --- a/plugins/bundleprocessor/bundleprocessor_test.go +++ b/plugins/bundleprocessor/bundleprocessor_test.go @@ -1,24 +1,30 @@ package bundleprocessor import ( - "os" "sync" "testing" "github.com/iotaledger/goshimmer/packages/client" "github.com/iotaledger/goshimmer/packages/model/bundle" "github.com/iotaledger/goshimmer/packages/model/value_transaction" + "github.com/iotaledger/goshimmer/packages/parameter" "github.com/iotaledger/goshimmer/plugins/tangle" "github.com/iotaledger/goshimmer/plugins/tipselection" "github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/node" - "github.com/iotaledger/hive.go/parameter" "github.com/iotaledger/iota.go/consts" "github.com/magiconair/properties/assert" ) var seed = client.NewSeed("YFHQWAUPCXC9S9DSHP9NDF9RLNPMZVCMSJKUKQP9SWUSUCPRQXCMDVDVZ9SHHESHIQNCXWBJF9UJSWE9Z", consts.SecurityLevelMedium) +func init() { + err := parameter.LoadDefaultConfig(false) + if err != nil { + log.Fatalf("Failed to initialize config: %s", err) + } +} + func BenchmarkValidateSignatures(b *testing.B) { bundleFactory := client.NewBundleFactory() bundleFactory.AddInput(seed.GetAddress(0), -400) @@ -44,11 +50,6 @@ func BenchmarkValidateSignatures(b *testing.B) { wg.Wait() } -func TestMain(m *testing.M) { - parameter.FetchConfig(false) - os.Exit(m.Run()) -} - func TestValidateSignatures(t *testing.T) { bundleFactory := client.NewBundleFactory() bundleFactory.AddInput(seed.GetAddress(0), -400) @@ -65,11 +66,9 @@ func TestValidateSignatures(t *testing.T) { } func TestProcessSolidBundleHead_Data(t *testing.T) { - // show all error messages for tests - // TODO: adjust logger package - // start a test node - node.Start(tangle.PLUGIN, PLUGIN) + node.Start(node.Plugins(tangle.PLUGIN, PLUGIN)) + defer node.Shutdown() bundleFactory := client.NewBundleFactory() bundleFactory.AddOutput(seed.GetAddress(1), 400, "Testmessage") @@ -90,6 +89,7 @@ func TestProcessSolidBundleHead_Data(t *testing.T) { wg.Done() }) Events.BundleSolid.Attach(testResults) + defer Events.BundleSolid.Detach(testResults) wg.Add(1) @@ -98,19 +98,12 @@ func TestProcessSolidBundleHead_Data(t *testing.T) { } wg.Wait() - - Events.BundleSolid.Detach(testResults) - - // shutdown test node - node.Shutdown() } func TestProcessSolidBundleHead_Value(t *testing.T) { - // show all error messages for tests - // TODO: adjust logger package - // start a test node - node.Start(tangle.PLUGIN, PLUGIN) + node.Start(node.Plugins(tangle.PLUGIN, PLUGIN)) + defer node.Shutdown() bundleFactory := client.NewBundleFactory() bundleFactory.AddInput(seed.GetAddress(0), -400) @@ -133,6 +126,7 @@ func TestProcessSolidBundleHead_Value(t *testing.T) { }) Events.BundleSolid.Attach(testResults) + defer Events.BundleSolid.Detach(testResults) wg.Add(1) @@ -141,9 +135,4 @@ func TestProcessSolidBundleHead_Value(t *testing.T) { } wg.Wait() - - Events.BundleSolid.Detach(testResults) - - // shutdown test node - node.Shutdown() } diff --git a/plugins/tangle/solidifier_test.go b/plugins/tangle/solidifier_test.go index 7b8aaf1dea231fdf453dd76936501f19f122759a..139febe3a4f2e240d9fc82f6629ce2868a6ec113 100644 --- a/plugins/tangle/solidifier_test.go +++ b/plugins/tangle/solidifier_test.go @@ -1,22 +1,23 @@ package tangle import ( - "os" "sync" "testing" "github.com/iotaledger/goshimmer/packages/gossip" "github.com/iotaledger/goshimmer/packages/model/meta_transaction" "github.com/iotaledger/goshimmer/packages/model/value_transaction" + "github.com/iotaledger/goshimmer/packages/parameter" "github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/node" - "github.com/iotaledger/hive.go/parameter" "github.com/stretchr/testify/require" ) -func TestMain(m *testing.M) { - parameter.FetchConfig(false) - os.Exit(m.Run()) +func init() { + err := parameter.LoadDefaultConfig(false) + if err != nil { + log.Fatalf("Failed to initialize config: %s", err) + } } func TestSolidifier(t *testing.T) { @@ -24,7 +25,7 @@ func TestSolidifier(t *testing.T) { // TODO: adjust logger package // start a test node - node.Start(PLUGIN) + node.Start(node.Plugins(PLUGIN)) // create transactions and chain them together transaction1 := value_transaction.New()