Skip to content

Commit

Permalink
oasis-net-runner: Use per-file init() functions
Browse files Browse the repository at this point in the history
  • Loading branch information
matevz committed Apr 23, 2020
1 parent a07ff2a commit 21e08c2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
2 changes: 1 addition & 1 deletion go/oasis-net-runner/fixtures/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 6 additions & 2 deletions go/oasis-net-runner/fixtures/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
11 changes: 1 addition & 10 deletions go/oasis-net-runner/fixtures/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
Expand All @@ -45,8 +41,3 @@ func DumpFixture(f *oasis.NetworkFixture) ([]byte, error) {

return data, nil
}

func init() {
initDefaultFixtureFlags()
initFileFixtureFlags()
}

0 comments on commit 21e08c2

Please sign in to comment.