From 21e08c241d584d1de9302ecde95ccc2b5ded1d2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matev=C5=BE=20Jekovec?= Date: Thu, 23 Apr 2020 12:26:30 +0200 Subject: [PATCH] oasis-net-runner: Use per-file init() functions --- go/oasis-net-runner/fixtures/default.go | 2 +- go/oasis-net-runner/fixtures/file.go | 8 ++++++-- go/oasis-net-runner/fixtures/fixtures.go | 11 +---------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/go/oasis-net-runner/fixtures/default.go b/go/oasis-net-runner/fixtures/default.go index c82d29c837a..4ff0fc12b0d 100644 --- a/go/oasis-net-runner/fixtures/default.go +++ b/go/oasis-net-runner/fixtures/default.go @@ -128,7 +128,7 @@ func newDefaultFixture() (*oasis.NetworkFixture, error) { }, nil } -func initDefaultFixtureFlags() { +func init() { DefaultFixtureFlags.Bool(cfgEpochtimeMock, false, "use mock epochtime") DefaultFixtureFlags.Uint64(cfgHaltEpoch, math.MaxUint64, "halt epoch height") DefaultFixtureFlags.String(cfgKeymanagerBinary, "simple-keymanager", "path to the keymanager runtime") diff --git a/go/oasis-net-runner/fixtures/file.go b/go/oasis-net-runner/fixtures/file.go index ce604a284dc..b4afb03aeb1 100644 --- a/go/oasis-net-runner/fixtures/file.go +++ b/go/oasis-net-runner/fixtures/file.go @@ -10,7 +10,11 @@ import ( "github.com/oasislabs/oasis-core/go/oasis-test-runner/oasis" ) -// newFixtureFromFile parses given JSON file and creates a new fixture object from it. +const ( + cfgFile = "fixture.file" +) + +// newFixtureFromFile parses given JSON file and creates new fixture object from it. func newFixtureFromFile(path string) (*oasis.NetworkFixture, error) { f := oasis.NetworkFixture{} data, err := ioutil.ReadFile(path) @@ -24,7 +28,7 @@ func newFixtureFromFile(path string) (*oasis.NetworkFixture, error) { return &f, nil } -func initFileFixtureFlags() { +func init() { FileFixtureFlags.String(cfgFile, "", "path to JSON-encoded fixture input file") _ = viper.BindPFlags(FileFixtureFlags) } diff --git a/go/oasis-net-runner/fixtures/fixtures.go b/go/oasis-net-runner/fixtures/fixtures.go index 54760f98866..33076f1d253 100644 --- a/go/oasis-net-runner/fixtures/fixtures.go +++ b/go/oasis-net-runner/fixtures/fixtures.go @@ -10,10 +10,6 @@ import ( "github.com/oasislabs/oasis-core/go/oasis-test-runner/oasis" ) -const ( - cfgFile = "fixture.file" -) - var ( // FileFixtureFlags are command line flags for the fixtures. FileFixtureFlags = flag.NewFlagSet("", flag.ContinueOnError) @@ -22,7 +18,7 @@ var ( DefaultFixtureFlags = flag.NewFlagSet("", flag.ContinueOnError) ) -// GetFixture generates a fixture object from given file or default fixture, if no fixtures file provided. +// GetFixture generates fixture object from given file or default fixture, if no fixtures file provided. func GetFixture() (f *oasis.NetworkFixture, err error) { if viper.IsSet(cfgFile) { f, err = newFixtureFromFile(viper.GetString(cfgFile)) @@ -45,8 +41,3 @@ func DumpFixture(f *oasis.NetworkFixture) ([]byte, error) { return data, nil } - -func init() { - initDefaultFixtureFlags() - initFileFixtureFlags() -}