Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Commit

Permalink
feat(local-ins): Use empty str for default-less options
Browse files Browse the repository at this point in the history
  • Loading branch information
AntiD2ta committed Sep 27, 2023
1 parent b120cd0 commit 1d557c1
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 2 deletions.
30 changes: 30 additions & 0 deletions e2e/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import (
"testing"
"time"

"github.com/NethermindEth/eigenlayer/internal/env"
"github.com/NethermindEth/eigenlayer/pkg/monitoring"
"github.com/cenkalti/backoff"
"github.com/docker/docker/client"
gapi "github.com/grafana/grafana-api-golang-client"
"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -331,3 +333,31 @@ func checkAVSHealth(t *testing.T, ip string, port string, wantCode int) {
assert.NoError(t, err, "AVS health should be ok, but it is not")
assert.Equal(t, wantCode, responseCode, "AVS health should be %d, but it is %d", wantCode, responseCode)
}

func checkEnvTargets(t *testing.T, instanceId string, targets ...string) {
// Check nodes folder exists
dataDir, err := dataDirPath()
if err != nil {
t.Fatal(err)
}
nodesDir := filepath.Join(dataDir, "nodes")

// Check instance directory does exist and is not empty
instancePath := filepath.Join(nodesDir, instanceId)
assert.DirExists(t, instancePath)
assert.FileExists(t, filepath.Join(instancePath, ".env"))

// Load .env file
fs := afero.NewOsFs()
envData, err := env.LoadEnv(fs, filepath.Join(instancePath, ".env"))
envTargets := make([]string, 0, len(envData))
for key := range envData {
envTargets = append(envTargets, key)
}

t.Logf("Checking .env targets")
for _, target := range targets {
assert.Contains(t, envTargets, target)
assert.Equal(t, envData[target], "\"\"", "target %s should be empty string", target)
}
}
76 changes: 76 additions & 0 deletions e2e/local_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,79 @@ func TestLocalInstall_ProfileWithHiddenOptionsNotSet(t *testing.T) {
// Run test case
e2eTest.run()
}

const newOptions = `
- name: "hidden-option-test"
target: HIDDEN_WITH_DEFAULT_TEST
type: str
default: test
hidden: true
help: "Hidden option test"
- name: "option-without-default-test"
target: OPTION_WITHOUT_DEFAULT_TEST
type: str
validate:
re2_regex: "^eigen.*" # Words that start with eigen
help: "Option without default"
`

func TestLocalInstall_OptionsWithoutDefault(t *testing.T) {
// Test context
var (
testDir = t.TempDir()
pkgDir = filepath.Join(testDir, "mock-avs")
runErr error
)
// Build test case
e2eTest := newE2ETestCase(
t,
// Arrange
func(t *testing.T, egnPath string) error {
if err := buildMockAvsImages(t); err != nil {
return err
}
err := os.MkdirAll(pkgDir, 0o755)
if err != nil {
return err
}
err = runCommand(t, "git", "clone", "--single-branch", "-b", common.MockAvsPkg.Version(), common.MockAvsPkg.Repo(), pkgDir)
if err != nil {
return err
}
// Modify health-checker to add a hidden option will default and a non-hidden option without default.
// Both TARGETS should be the empty string in the .env.
f, err := os.OpenFile(filepath.Join(pkgDir, "pkg", "health-checker", "profile.yml"), os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
t.Fatalf("failed to open profile.yml: %v", err)
}
defer f.Close()

if _, err = f.WriteString(newOptions); err != nil {
t.Fatalf("failed to write to profile.yml: %v", err)
}

// data, _ := os.ReadFile(filepath.Join(pkgDir, "pkg", "health-checker", "profile.yml"))
// t.Logf("profile.yml: \n %s \n", data)
// t.Fatal("stop")

// remove .git folder
return os.RemoveAll(filepath.Join(pkgDir, ".git"))
},
// Act
func(t *testing.T, egnPath string) {
runErr = runCommand(t, egnPath, "local-install", pkgDir, "--profile", "health-checker", "--run", "--log-debug")
},
// Assert
func(t *testing.T) {
assert.NoError(t, runErr, "local-install command should succeed")
checkInstanceInstalled(t, "mock-avs-default")
checkContainerRunning(t, "health-checker")
healthCheckerIP, err := getContainerIPByName("health-checker", "eigenlayer")
require.NoError(t, err, "failed to get health-checker container IP")
checkAVSHealth(t, healthCheckerIP, "8090", 200)
checkEnvTargets(t, "mock-avs-default", "HIDDEN_WITH_DEFAULT_TEST", "OPTION_WITHOUT_DEFAULT_TEST")
},
)
// Run test case
e2eTest.run()
}
5 changes: 3 additions & 2 deletions pkg/daemon/egn_daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,10 +641,11 @@ func (d *EgnDaemon) localInstall(pkgTar io.Reader, options LocalInstallOptions)
return instanceID, tID, err
}
optionsEnv[o.Target()] = v
} else if o.Default() != "" {
} else if o.Default() != "" && !o.Hidden() {
optionsEnv[o.Target()] = o.Default()
} else {
return instanceID, tID, fmt.Errorf("%w: %s", ErrOptionWithoutValue, o.Name())
log.Warn("Option ", o.Name(), " does not have a default value. Using empty string as value.")
optionsEnv[o.Target()] = "\"\""
}
}
maps.Copy(env, optionsEnv)
Expand Down

0 comments on commit 1d557c1

Please sign in to comment.