Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add antithesis PoC workload #2796

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading