Skip to content

Commit

Permalink
Add antithesis PoC workload (#2796)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Mar 12, 2024
1 parent ddf66ea commit 6649530
Show file tree
Hide file tree
Showing 2 changed files with 707 additions and 0 deletions.
71 changes: 71 additions & 0 deletions tests/antithesis/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package main

import (
"errors"
"fmt"
"strings"

"github.com/spf13/pflag"
"github.com/spf13/viper"

"github.com/ava-labs/avalanchego/wallet/subnet/primary"
)

const (
URIsKey = "uris"

FlagsName = "workload"
EnvPrefix = "avawl"
)

var (
errNoURIs = errors.New("at least one URI must be provided")
errNoArguments = errors.New("no arguments")
)

type Config struct {
URIs []string
}

func NewConfig(arguments []string) (*Config, error) {
v, err := parseFlags(arguments)
if err != nil {
return nil, err
}

c := &Config{
URIs: v.GetStringSlice(URIsKey),
}
return c, c.Verify()
}

func (c *Config) Verify() error {
if len(c.URIs) == 0 {
return errNoURIs
}
return nil
}

func parseFlags(arguments []string) (*viper.Viper, error) {
if len(arguments) == 0 {
return nil, errNoArguments
}

fs := pflag.NewFlagSet(FlagsName, pflag.ContinueOnError)
fs.StringSlice(URIsKey, []string{primary.LocalAPIURI}, "URIs of nodes that the workload can communicate with")
if err := fs.Parse(arguments[1:]); err != nil {
return nil, fmt.Errorf("failed parsing CLI flags: %w", err)
}

v := viper.New()
v.AutomaticEnv()
v.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
v.SetEnvPrefix(EnvPrefix)
if err := v.BindPFlags(fs); err != nil {
return nil, fmt.Errorf("failed binding pflags: %w", err)
}
return v, nil
}
Loading

0 comments on commit 6649530

Please sign in to comment.