Skip to content

Commit 3efaf4a

Browse files
committed
fixup: Respond to review feedback
1 parent 1e3ed01 commit 3efaf4a

File tree

5 files changed

+11
-7
lines changed

5 files changed

+11
-7
lines changed

config/viper.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import (
1515
"github.com/spf13/viper"
1616
)
1717

18+
const EnvPrefix = "avago"
19+
20+
var DashesToUnderscores = strings.NewReplacer("-", "_")
21+
1822
// BuildViper returns the viper environment from parsing config file from
1923
// default search paths and any parsed command line flags
2024
func BuildViper(fs *pflag.FlagSet, args []string) (*viper.Viper, error) {
@@ -27,8 +31,8 @@ func BuildViper(fs *pflag.FlagSet, args []string) (*viper.Viper, error) {
2731

2832
v := viper.New()
2933
v.AutomaticEnv()
30-
v.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
31-
v.SetEnvPrefix("avago")
34+
v.SetEnvKeyReplacer(DashesToUnderscores)
35+
v.SetEnvPrefix(EnvPrefix)
3236
if err := v.BindPFlags(fs); err != nil {
3337
return nil, err
3438
}

tests/antithesis/avalanchego/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ package main
66
import (
77
"errors"
88
"fmt"
9-
"strings"
109

1110
"github.com/spf13/pflag"
1211
"github.com/spf13/viper"
1312

13+
"github.com/ava-labs/avalanchego/config"
1414
"github.com/ava-labs/avalanchego/wallet/subnet/primary"
1515
)
1616

@@ -62,7 +62,7 @@ func parseFlags(arguments []string) (*viper.Viper, error) {
6262

6363
v := viper.New()
6464
v.AutomaticEnv()
65-
v.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
65+
v.SetEnvKeyReplacer(config.DashesToUnderscores)
6666
v.SetEnvPrefix(EnvPrefix)
6767
if err := v.BindPFlags(fs); err != nil {
6868
return nil, fmt.Errorf("failed binding pflags: %w", err)

tests/antithesis/avalanchego/gencomposeconfig/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func main() {
2929
nodeImageName := fmt.Sprintf("%s-node:%s", baseImageName, imageTag)
3030
workloadImageName := fmt.Sprintf("%s-workload:%s", baseImageName, imageTag)
3131

32-
network := tmpnet.LocalNetworkOrDie()
32+
network := tmpnet.LocalNetworkOrPanic()
3333
err := antithesis.GenerateComposeConfig(network, nodeImageName, workloadImageName, targetPath)
3434
if err != nil {
3535
log.Fatalf("failed to generate config for docker-compose: %s", err)

tests/antithesis/compose.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func keyMapToEnvVarMap(keyMap types.Mapping) types.Mapping {
183183
envVarMap := make(types.Mapping, len(keyMap))
184184
for key, val := range keyMap {
185185
// e.g. network-id -> AVAGO_NETWORK_ID
186-
envVar := "AVAGO_" + strings.ToUpper(strings.ReplaceAll(key, "-", "_"))
186+
envVar := strings.ToUpper(config.EnvPrefix + "_" + config.DashesToUnderscores.Replace(key))
187187
envVarMap[envVar] = val
188188
}
189189
return envVarMap

tests/fixture/tmpnet/local_network.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
1212
)
1313

14-
func LocalNetworkOrDie() *Network {
14+
func LocalNetworkOrPanic() *Network {
1515
// Temporary network configured with local network keys
1616
// See: /staking/local/README.md
1717
network := &Network{

0 commit comments

Comments
 (0)