diff --git a/cmd/edenConfig.go b/cmd/edenConfig.go index b1c05b3c9..ccbf83fb9 100644 --- a/cmd/edenConfig.go +++ b/cmd/edenConfig.go @@ -15,7 +15,10 @@ func newConfigCmd(configName, verbosity *string) *cobra.Command { if err != nil { log.Fatal(err) } - cfg := openevec.GetDefaultConfig(currentPath) + cfg, err := openevec.GetDefaultConfig(currentPath) + if err != nil { + log.Fatalf("Failed to generate default config %v\n", err) + } var configCmd = &cobra.Command{ Use: "config", Short: "work with config", diff --git a/cmd/edenSetup.go b/cmd/edenSetup.go index 88e89f3e3..7406d2b5d 100644 --- a/cmd/edenSetup.go +++ b/cmd/edenSetup.go @@ -23,9 +23,6 @@ func newSetupCmd(configName, verbosity *string) *cobra.Command { Long: `Setup harness.`, PersistentPreRunE: preRunViperLoadFunction(cfg, configName, verbosity), Run: func(cmd *cobra.Command, args []string) { - // if err := openevec.ConfigCheck(*configName); err != nil { - // log.Fatalf("Config check failed %s", err) - // } if err := openEVEC.SetupEden(*configName, configDir, softSerial, zedControlURL, ipxeOverride, grubOptions, netboot, installer); err != nil { log.Fatalf("Setup eden failed: %s", err) diff --git a/docs/design-decisions.md b/docs/design-decisions.md new file mode 100644 index 000000000..c5668ecd9 --- /dev/null +++ b/docs/design-decisions.md @@ -0,0 +1,73 @@ +# Design decisions + +This document is a collection of high-level decisions, that have been made in the project. Why do we have a section about how things use to be? In case if we want to revisit certain concept it will be useful to know why we chose one approach over another. + +## Using Doman Specific Language (DSL) vs writing native golang tests + +When talking about Eden tests till version 0.9.12, we are talking about `escript`, a Domain Specific Language (DSL) which describes test case and uses Eden to setup, environment. Escript looks like this + +```bash +# 1 Setup environment variables +{{$port := "2223"}} +{{$network_name := "n1"}} +{{$app_name := "eclient"}} + +# ... + +# 2 run eden commands +eden -t 1m network create 10.11.12.0/24 -n {{$network_name}} + +# 3 run escript commands +test eden.network.test -test.v -timewait 10m ACTIVATED {{$network_name}} + +eden pod deploy -n {{$app_name}} --memory=512MB {{template "eclient_image"}} -p {{$port}}:22 --networks={{$network_name}} + +# 4 execute shell script which are defined inside escript file +exec -t 5m bash ssh.sh +stdout 'Ubuntu' + +# 5 overwrite configuration +-- eden-config.yml -- +{{/* Test's config. file */}} +test: + controller: adam://{{EdenConfig "adam.ip"}}:{{EdenConfig "adam.port"}} + eve: + {{EdenConfig "eve.name"}}: + onboard-cert: {{EdenConfigPath "eve.cert"}} + serial: "{{EdenConfig "eve.serial"}}" + model: {{EdenConfig "eve.devmodel"}} + +-- ssh.sh -- +EDEN={{EdenConfig "eden.root"}}/{{EdenConfig "eden.bin-dist"}}/{{EdenConfig "eden.eden-bin"}} +for i in `seq 20` +do + sleep 20 + # Test SSH-access to container + echo $i\) $EDEN sdn fwd eth0 {{$port}} -- {{template "ssh"}} grep Ubuntu /etc/issue + $EDEN sdn fwd eth0 {{$port}} -- {{template "ssh"}} grep Ubuntu /etc/issue && break +done +``` + +So you can + +1) setup some environment variables +2) run eden commands +3) run escript commands with test +4) execute user-defined shell scripts +5) overwrite eden configuration + +Escript file is fed as input to eden test command, which parses the variables using golang templates to substitute some variables using templates in golang, then it's going to read line by line and execute it via os.exec call in golang. test is actually a compiled golang binary, we compile it inside eden repo and then execute it, under the hood it is a manually forked version of standard golang test package with some added commands. + +For more information on specific topics refer to following documents: + +- Escript test structure [doc](./escript/test-anatomy-sample.md) +- Writing eden tasks for escript [doc](./escript/task-writing.md) +- Running tests [doc](./escript/test-running.md) + +So there are several problems with that approach: + +**You have to be an escript expert**: when new person comes to a project, they will have some industry skills, like C++ expertise, Rust, Golang, Computer Networking, etc. but if you never worked on this project, you never heard about escript, its' sole purpose was to be part of Eden and be useful language to describe tests for Eden. One might argue, but that's just bash on steroids. Well, true, but do you know what `!` means? It's not equal parameter in escript. So it is like bash, but not exactly it, and it might take time to figure out other hidden features, that could be solved by proper documentation. But before spiraling down that conversation lets think about tools? Imagine, that you wrote new fancy eden test and it doesn't work. Usual thing, you would say. Test Driven Development is all about writing failing tests first and then making them work. + +**But how do you debug that test?** Because you're running an interpreter, which runs bash commands via os.exec plus you execute golang program, which is written and compiled inside the repository. Debug printing would work, but I find debuggers much more useful and efficient most of the times. It is a matter of taste, but better to debugger at your disposal, than not to have it in this case. Even worse, how do you debug escript problem? You need to know it's internals, there's no Stackoverflow or Google by your side, nor there are books about it. + +**Bumping golang is actually manual action**: last but not least, we have to maintain custom test files which a basically copy-paste with one added function, bumping golang turns into some weird dances in that case. diff --git a/docs/task-writing.md b/docs/escript/task-writing.md similarity index 100% rename from docs/task-writing.md rename to docs/escript/task-writing.md diff --git a/docs/test-anatomy-sample.md b/docs/escript/test-anatomy-sample.md similarity index 100% rename from docs/test-anatomy-sample.md rename to docs/escript/test-anatomy-sample.md diff --git a/docs/test-running.md b/docs/escript/test-running.md similarity index 100% rename from docs/test-running.md rename to docs/escript/test-running.md diff --git a/docs/writing-tests.md b/docs/writing-tests.md new file mode 100644 index 000000000..c984efe61 --- /dev/null +++ b/docs/writing-tests.md @@ -0,0 +1,98 @@ +# How to write tests with Eden + +The eden golang test SDK for eve consists of two categories of functions: + +1. `openevec`: infrastructure manager. `openevec` enables you to deploy a controller, a backend for that controller, deploy an edge node, etc. It does not change anything on an individual edge node. +2. `evetestkit`: provides useful collection of functions to describe expected state of the system (controller, EVE, AppInstances) + +And those functions are used in context of standard golang test library. We do a setup in TestMain (for more info check [this](https://pkg.go.dev/testing#hdr-Main)) and then write test functions which interact with the environment we created. Setting up environment takes couple of minutes, so it makes sense to do it once and run tests within that environment. + +Source for the example below can be found [here](../tests/sec/sec_test.go) + +In order to test a feature in Eden you need to + +## 1. Create a configuration file and describe your environment + +The glue between `openevec` and `evetestkit` is a configuration structure called `EdenSetupArgs`. It contains all the necessary information to setup all the components of the test: controller, EVE, etc. You can fill in the structure manually, however `openevec` provides you with a convenient function to create default configuration structure providing project root path: + +```go +// ... +func TestMain(m *testing.M) { + currentPath, err := os.Getwd() + if err != nil { + log.Fatal(err) + } + twoLevelsUp := filepath.Dir(filepath.Dir(currentPath)) + + cfg := openevec.GetDefaultConfig(twoLevelsUp) + + if err = openevec.ConfigAdd(cfg, cfg.ConfigName, "", false); err != nil { + log.Fatal(err) + } + // ... +} +``` + +Due to backward compatibility with escript as of time of writing, the project root path should be Eden repository folder. So if you add tests in the `eden/tests/my-awesome-test` you need to go two levels up, will be removed with escript +Also we need to write configuration file to file system, because there are components (like changer) which read configuration from file system, will be removed with escript + +## 2. Initialize `openevec` Setup, Start and Onboard EVE node + +When configuration you need `openevec` to create all needed certificates, start backend. For that we create `openevec` object based on a configuration provided, it is just a convinient wrapper. + +```go +// ... +func TestMain(m *testing.M) { + // ... + evec := openvec.CreateOpenEVEC(cfg) + + evec.SetupEden(/* ... */) + evec.StartEden(/* ... */) + evec.OnboardEve(/* ... */) + + // ... +} +``` + +## 3. Initialize `evetestkit` and run test suite + +`evetestkit` provides an abstraction over EveNode, which is used to describe expected state of the system. Each EveNode is running within a project You can create a global object within one test file to use it across multiple tests. Note that EveNode is not threadsafe, since controller is stateful, so tests should be run consequently (no t.Parallel()) + +```go +const projectName = "security-test" +var eveNode *evetestkit.EveNode + +func TestMain(m *testing.M) { + // ... + node, err := evetestkit.InitializeTestFromConfig(projectName, cfg, evetestkit.WithControllerVerbosity("debug")) + if err != nil { + log.Fatalf("Failed to initialize test: %v", err) + } + + eveNode = node + res := m.Run() + os.Exit(res) +} +``` + +## 4. Write your test + +Below is an example of test, which check if AppArmor is enabled (specific file on EVE exists). It uses `EveReadFile` function from `evetestkit` + +```go +const appArmorStatus = "/sys/module/apparmor/parameters/enabled" +// ... +func TestAppArmorEnabled(t *testing.T) { + log.Println("TestAppArmorEnabled started") + defer log.Println("TestAppArmorEnabled finished") + + out, err := eveNode.EveReadFile(appArmorStatus) + if err != nil { + t.Fatal(err) + } + + exits := strings.TrimSpace(string(out)) + if exits != "Y" { + t.Fatal("AppArmor is not enabled") + } +``` diff --git a/pkg/evetestkit/utils.go b/pkg/evetestkit/utils.go index fe378e78c..0b1ac8559 100644 --- a/pkg/evetestkit/utils.go +++ b/pkg/evetestkit/utils.go @@ -791,8 +791,8 @@ func InitilizeTestFromConfig(projectName string, cfg *openevec.EdenSetupArgs, op // or UUIDs that were passed in) in the context. This is the first place // where we're using zcli-like API: for _, node := range tc.GetNodeDescriptions() { - edgeNode := node.GetEdgeNode(tc) - if edgeNode == nil { + edgenode = node.GetEdgeNode(tc) + if edgenode == nil { // Couldn't find existing edgeNode record in the controller. // Need to create it from scratch now: // this is modeled after: zcli edge-node create @@ -803,27 +803,26 @@ func InitilizeTestFromConfig(projectName string, cfg *openevec.EdenSetupArgs, op // [--network=...] // // XXX: not sure if struct (giving us optional fields) would be better - edgeNode = tc.NewEdgeNode(tc.WithNodeDescription(node), tc.WithCurrentProject()) + edgenode = tc.NewEdgeNode(tc.WithNodeDescription(node), tc.WithCurrentProject()) } else { // make sure to move EdgeNode to the project we created, again // this is modeled after zcli edge-node update [--title=] // [--lisp-mode=experimental|default] [--project=<project>] // [--clear-onboarding-certs] [--config=<key:value>...] [--network=<network>...] - edgeNode.SetProject(projectName) + edgenode.SetProject(projectName) } - edgenode = edgeNode - tc.ConfigSync(edgeNode) + tc.ConfigSync(edgenode) // finally we need to make sure that the edgeNode is in a state that we need // it to be, before the test can run -- this could be multiple checks on its // status, but for example: - if edgeNode.GetState() == device.NotOnboarded { + if edgenode.GetState() == device.NotOnboarded { return nil, fmt.Errorf("node is not onboarded now") } // this is a good node -- lets add it to the test context - tc.AddNode(edgeNode) + tc.AddNode(edgenode) } tc.StartTrackingState(false) diff --git a/pkg/openevec/changers.go b/pkg/openevec/changers.go index bc4b85728..3a0926d1f 100644 --- a/pkg/openevec/changers.go +++ b/pkg/openevec/changers.go @@ -7,7 +7,6 @@ import ( "os" "github.com/lf-edge/eden/pkg/controller" - "github.com/lf-edge/eden/pkg/defaults" "github.com/lf-edge/eden/pkg/device" "github.com/lf-edge/eden/pkg/utils" "github.com/lf-edge/eve-api/go/config" @@ -29,7 +28,7 @@ func changerByControllerMode(controllerMode string) (configChanger, error) { if controllerMode == "" { return &adamChanger{}, nil } - modeType, modeURL, err := utils.GetControllerMode(controllerMode, defaults.DefaultControllerModePattern) + modeType, modeURL, err := utils.GetControllerMode(controllerMode) if err != nil { return nil, err } diff --git a/pkg/openevec/config.go b/pkg/openevec/config.go index 8ad319eb9..f6e393b31 100644 --- a/pkg/openevec/config.go +++ b/pkg/openevec/config.go @@ -5,7 +5,6 @@ import ( "io" "os" "path" - "path/filepath" "reflect" "strings" @@ -325,49 +324,6 @@ func resolvePath(path string, v reflect.Value) { } } -func ConfigCheck(configName string) error { - configFile := utils.GetConfig(configName) - configSaved := utils.ResolveAbsPath(fmt.Sprintf("%s-%s", configName, defaults.DefaultConfigSaved)) - - abs, err := filepath.Abs(configSaved) - if err != nil { - return fmt.Errorf("fail in reading filepath: %s\n", err.Error()) - } - - if _, err = os.Lstat(abs); os.IsNotExist(err) { - if err = utils.CopyFile(configFile, abs); err != nil { - return fmt.Errorf("copying fail %s\n", err.Error()) - } - } else { - - viperLoaded, err := utils.LoadConfigFile(abs) - if err != nil { - return fmt.Errorf("error reading config %s: %s\n", abs, err.Error()) - } - if viperLoaded { - confOld := viper.AllSettings() - - if _, err = utils.LoadConfigFile(configFile); err != nil { - return fmt.Errorf("error reading config %s: %s", configFile, err.Error()) - } - - confCur := viper.AllSettings() - - if reflect.DeepEqual(confOld, confCur) { - log.Infof("Config file %s is the same as %s\n", configFile, configSaved) - } else { - return fmt.Errorf("the current configuration file %s is different from the saved %s. You can fix this with the commands 'eden config clean' and 'eden config add/set/edit'.\n", configFile, abs) - } - } else { - /* Incorrect saved config -- just rewrite by current */ - if err = utils.CopyFile(configFile, abs); err != nil { - return fmt.Errorf("copying fail %s\n", err.Error()) - } - } - } - return nil -} - func getValStrRepr(v reflect.Value) string { if v.Kind() == reflect.String { return fmt.Sprintf("'%v'", v.Interface()) diff --git a/pkg/openevec/defaults.go b/pkg/openevec/defaults.go index 70d6aea2b..c1f8a7c84 100644 --- a/pkg/openevec/defaults.go +++ b/pkg/openevec/defaults.go @@ -13,24 +13,24 @@ import ( uuid "github.com/satori/go.uuid" ) -func GetDefaultConfig(currentPath string) *EdenSetupArgs { +func GetDefaultConfig(projectRootPath string) (*EdenSetupArgs, error) { ip, err := utils.GetIPForDockerAccess() if err != nil { - return nil + return nil, err } edenDir, err := utils.DefaultEdenDir() if err != nil { - return nil + return nil, err } id, err := uuid.NewV4() if err != nil { - return nil + return nil, err } - imageDist := filepath.Join(currentPath, defaults.DefaultDist, fmt.Sprintf("%s-%s", defaults.DefaultContext, defaults.DefaultImageDist)) - certsDist := filepath.Join(currentPath, defaults.DefaultDist, fmt.Sprintf("%s-%s", defaults.DefaultContext, defaults.DefaultCertsDist)) + imageDist := filepath.Join(projectRootPath, defaults.DefaultDist, fmt.Sprintf("%s-%s", defaults.DefaultContext, defaults.DefaultImageDist)) + certsDist := filepath.Join(projectRootPath, defaults.DefaultDist, fmt.Sprintf("%s-%s", defaults.DefaultContext, defaults.DefaultCertsDist)) firmware := []string{filepath.Join(imageDist, "eve", "OVMF.fd")} if runtime.GOARCH == "amd64" { @@ -41,11 +41,11 @@ func GetDefaultConfig(currentPath string) *EdenSetupArgs { defaultEdenConfig := &EdenSetupArgs{ Eden: EdenConfig{ - Root: filepath.Join(currentPath, defaults.DefaultDist), - Tests: filepath.Join(currentPath, defaults.DefaultDist, "tests"), + Root: filepath.Join(projectRootPath, defaults.DefaultDist), + Tests: filepath.Join(projectRootPath, defaults.DefaultDist, "tests"), Download: true, BinDir: defaults.DefaultBinDist, - SSHKey: filepath.Join(currentPath, defaults.DefaultDist, fmt.Sprintf("%s-%s", defaults.DefaultContext, defaults.DefaultSSHKey)), + SSHKey: filepath.Join(projectRootPath, defaults.DefaultDist, fmt.Sprintf("%s-%s", defaults.DefaultContext, defaults.DefaultSSHKey)), CertsDir: certsDist, TestBin: defaults.DefaultTestProg, EdenBin: "eden", @@ -134,8 +134,8 @@ func GetDefaultConfig(currentPath string) *EdenSetupArgs { QemuMemory: defaults.DefaultMemory, ImageSizeMB: defaults.DefaultEVEImageSize, Serial: defaults.DefaultEVESerial, - Pid: filepath.Join(currentPath, defaults.DefaultDist, fmt.Sprintf("%s-eve.pid", strings.ToLower(defaults.DefaultContext))), - Log: filepath.Join(currentPath, defaults.DefaultDist, fmt.Sprintf("%s-eve.log", strings.ToLower(defaults.DefaultContext))), + Pid: filepath.Join(projectRootPath, defaults.DefaultDist, fmt.Sprintf("%s-eve.pid", strings.ToLower(defaults.DefaultContext))), + Log: filepath.Join(projectRootPath, defaults.DefaultDist, fmt.Sprintf("%s-eve.log", strings.ToLower(defaults.DefaultContext))), TelnetPort: defaults.DefaultTelnetPort, TPM: defaults.DefaultTPMEnabled, ImageFile: filepath.Join(imageDist, "eve", "live.img"), @@ -178,16 +178,16 @@ func GetDefaultConfig(currentPath string) *EdenSetupArgs { Sdn: SdnConfig{ RAM: defaults.DefaultSdnMemory, CPU: defaults.DefaultSdnCpus, - ConsoleLogFile: filepath.Join(currentPath, defaults.DefaultDist, "sdn-console.log"), + ConsoleLogFile: filepath.Join(projectRootPath, defaults.DefaultDist, "sdn-console.log"), Disable: true, TelnetPort: defaults.DefaultSdnTelnetPort, MgmtPort: defaults.DefaultSdnMgmtPort, - PidFile: filepath.Join(currentPath, defaults.DefaultDist, "sdn.pid"), + PidFile: filepath.Join(projectRootPath, defaults.DefaultDist, "sdn.pid"), SSHPort: defaults.DefaultSdnSSHPort, - SourceDir: filepath.Join(currentPath, "sdn"), + SourceDir: filepath.Join(projectRootPath, "sdn"), ConfigDir: filepath.Join(edenDir, fmt.Sprintf("%s-sdn", "default")), ImageFile: filepath.Join(imageDist, "eden", "sdn-efi.qcow2"), - LinuxkitBin: filepath.Join(currentPath, defaults.DefaultBuildtoolsDir, "linuxkit"), + LinuxkitBin: filepath.Join(projectRootPath, defaults.DefaultBuildtoolsDir, "linuxkit"), NetModelFile: "", }, @@ -204,7 +204,7 @@ func GetDefaultConfig(currentPath string) *EdenSetupArgs { EdenDir: edenDir, } - return defaultEdenConfig + return defaultEdenConfig, nil } func GetDefaultPodConfig() *PodConfig { diff --git a/pkg/openevec/eden.go b/pkg/openevec/eden.go index c9a18a436..ea0f7b649 100644 --- a/pkg/openevec/eden.go +++ b/pkg/openevec/eden.go @@ -371,24 +371,29 @@ func setupEdenScripts(cfg EdenSetupArgs) error { } func setupConfigDir(cfg EdenSetupArgs, eveConfigDir, softSerial, zedControlURL string, grubOptions []string) error { - wifiPSK := "" - if cfg.Eve.Ssid != "" { - fmt.Printf("Enter password for wifi %s: ", cfg.Eve.Ssid) - pass, _ := term.ReadPassword(0) - wifiPSK = strings.ToLower(hex.EncodeToString(pbkdf2.Key(pass, []byte(cfg.Eve.Ssid), 4096, 32, sha1.New))) - fmt.Println() - } - if zedControlURL == "" { - if err := eden.GenerateEveCerts(cfg.Eden.CertsDir, cfg.Adam.CertsDomain, cfg.Adam.CertsIP, cfg.Adam.CertsEVEIP, cfg.Eve.CertsUUID, - cfg.Eve.DevModel, cfg.Eve.Ssid, cfg.Eve.Arch, wifiPSK, grubOptions, cfg.Adam.APIv1); err != nil { - return fmt.Errorf("cannot GenerateEveCerts: %w", err) + if _, err := os.Stat(filepath.Join(cfg.Eden.CertsDir, "root-certificate.pem")); os.IsNotExist(err) { + wifiPSK := "" + if cfg.Eve.Ssid != "" { + fmt.Printf("Enter password for wifi %s: ", cfg.Eve.Ssid) + pass, _ := term.ReadPassword(0) + wifiPSK = strings.ToLower(hex.EncodeToString(pbkdf2.Key(pass, []byte(cfg.Eve.Ssid), 4096, 32, sha1.New))) + fmt.Println() + } + if zedControlURL == "" { + if err := eden.GenerateEveCerts(cfg.Eden.CertsDir, cfg.Adam.CertsDomain, cfg.Adam.CertsIP, cfg.Adam.CertsEVEIP, cfg.Eve.CertsUUID, + cfg.Eve.DevModel, cfg.Eve.Ssid, cfg.Eve.Arch, wifiPSK, grubOptions, cfg.Adam.APIv1); err != nil { + return fmt.Errorf("cannot GenerateEveCerts: %w", err) + } + log.Info("GenerateEveCerts done") + } else { + if err := eden.PutEveCerts(cfg.Eden.CertsDir, cfg.Eve.DevModel, cfg.Eve.Ssid, cfg.Eve.Arch, wifiPSK); err != nil { + return fmt.Errorf("cannot GenerateEveCerts: %w", err) + } + log.Info("GenerateEveCerts done") } - log.Info("GenerateEveCerts done") } else { - if err := eden.PutEveCerts(cfg.Eden.CertsDir, cfg.Eve.DevModel, cfg.Eve.Ssid, cfg.Eve.Arch, wifiPSK); err != nil { - return fmt.Errorf("cannot GenerateEveCerts: %w", err) - } log.Info("GenerateEveCerts done") + log.Infof("Certs already exists in certs dir: %s", cfg.Eden.CertsDir) } if zedControlURL == "" { err := eden.GenerateEVEConfig(cfg.Eve.DevModel, cfg.Eden.CertsDir, cfg.Adam.CertsDomain, cfg.Adam.CertsEVEIP, diff --git a/pkg/openevec/test.go b/pkg/openevec/test.go index 5ab979c21..00a5dcb55 100644 --- a/pkg/openevec/test.go +++ b/pkg/openevec/test.go @@ -95,7 +95,6 @@ func InitVarsFromConfig(cfg *EdenSetupArgs) (*utils.ConfigVars, error) { } func Test(tstCfg *TestArgs) error { - fmt.Println("SOME TEST") switch { case tstCfg.TestList != "": tests.RunTest(tstCfg.TestProg, []string{"-test.list", tstCfg.TestList}, "", tstCfg.TestTimeout, tstCfg.FailScenario, tstCfg.ConfigFile, tstCfg.Verbosity) diff --git a/pkg/testcontext/testContext.go b/pkg/testcontext/testContext.go index 85510568e..2a91db426 100644 --- a/pkg/testcontext/testContext.go +++ b/pkg/testcontext/testContext.go @@ -57,7 +57,7 @@ func NewTestContext() *TestContext { log.Fatalf("LoadConfigFile %s", err) } if viperLoaded { - modeType, modeURL, err := utils.GetControllerMode(viper.GetString("test.controller"), defaults.DefaultControllerModePattern) + modeType, modeURL, err := utils.GetControllerMode(viper.GetString("test.controller")) if err != nil { log.Debug(err) } diff --git a/pkg/utils/params.go b/pkg/utils/params.go index ede5ef505..7da92f4f0 100644 --- a/pkg/utils/params.go +++ b/pkg/utils/params.go @@ -6,11 +6,14 @@ import ( "regexp" "strings" "time" + + "github.com/lf-edge/eden/pkg/defaults" ) // GetControllerMode parse url with controller -func GetControllerMode(controllerMode, modePattern string) (modeType, modeURL string, err error) { - params := GetParams(controllerMode, modePattern) +func GetControllerMode(controllerMode string) (modeType, modeURL string, err error) { + + params := GetParams(controllerMode, defaults.DefaultControllerModePattern) if len(params) == 0 { return "", "", fmt.Errorf("cannot parse mode (not [file|proto|adam|zedcloud]://<URL>): %s", controllerMode) } diff --git a/shell-scripts/activate.csh.tmpl b/shell-scripts/activate.csh.tmpl deleted file mode 100644 index 84a2a899a..000000000 --- a/shell-scripts/activate.csh.tmpl +++ /dev/null @@ -1,48 +0,0 @@ -# This file must be used with "source bin/activate.csh" *from csh*. -# You cannot run it directly. - -set newline='\ -' - -alias eden_deactivate 'test $?_OLD_EDEN_PATH != 0 && setenv PATH "$_OLD_EDEN_PATH:q" && unset _OLD_EDEN_PATH; rehash; test $?_OLD_EDEN_PROMPT != 0 && set prompt="$_OLD_EDEN_PROMPT:q" && unset _OLD_EDEN_PROMPT; unsetenv EDEN_HOME; test "\!:*" != "nondestructive" && unalias eden_deactivate && unalias eden_config && unalias eden+config && unalias eden-config' - -alias eden_config 'eden config set \!:1 && set prompt="EDEN-`eden config get`_$_OLD_EDEN_PROMPT:q"' - -alias eden+config 'cd `eden config get --key eden.root`/..; eden config add \!:1; cd -' -alias eden-config 'eden config delete \!:1; eden_config default' - -# Unset irrelevant variables. -eden_deactivate nondestructive - -setenv EDEN_HOME "{{.Eden.Root}}" - -set _OLD_EDEN_PATH="$PATH:q" -setenv PATH "{{.Eden.BinDir}}:$PATH:q" - -if ( $?EDEN_DISABLE_PROMPT ) then - if ( $EDEN_DISABLE_PROMPT == "" ) then - set do_prompt = "1" - else - set do_prompt = "0" - endif -else - set do_prompt = "1" -endif - -if ( $do_prompt == "1" ) then - # Could be in a non-interactive environment, - # in which case, $prompt is undefined and we wouldn't - # care about the prompt anyway. - if ( $?prompt ) then - set _OLD_EDEN_PROMPT="$prompt:q" - if ( "$prompt:q" =~ *"$newline:q"* ) then - : - else - set prompt = "eden-`eden config get`_$prompt:q" - endif - endif -endif - -unset do_prompt - -rehash diff --git a/shell-scripts/activate.sh.tmpl b/shell-scripts/activate.sh.tmpl deleted file mode 100644 index c2446c915..000000000 --- a/shell-scripts/activate.sh.tmpl +++ /dev/null @@ -1,97 +0,0 @@ -# This file must be used with "source bin/activate" *from bash* -# you cannot run it directly - -if [ "${BASH_SOURCE-}" = "$0" ]; then - echo "You must source this script: \$ source $0" >&2 - exit 33 -fi - -eden_deactivate () { - # reset old environment variables - # ! [ -z ${VAR+_} ] returns true if VAR is declared at all - if ! [ -z "${_OLD_EDEN_PATH:+_}" ] ; then - PATH="$_OLD_EDEN_PATH" - export PATH - unset _OLD_EDEN_PATH - fi - - # This should detect bash and zsh, which have a hash command that must - # be called to get it to forget past commands. Without forgetting - # past commands the $PATH changes we made may not be respected - if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then - hash -r 2>/dev/null - fi - - if ! [ -z "${_OLD_EDEN_PS1+_}" ] ; then - PS1="$_OLD_EDEN_PS1" - export PS1 - unset _OLD_EDEN_PS1 - fi - - unset EDEN_HOME - if [ ! "${1-}" = "nondestructive" ] ; then - # Self destruct! - unset -f eden_deactivate - unset -f eden_config - unset -f eden-config - unset -f eden+config - fi -} - -eden_config () { - if [ $# -eq 0 ] - then - echo Usage: eden_config config - return - fi - - eden config set $1 - PS1="EDEN-`eden config get`_${_OLD_EDEN_PS1-}" -} - -eden+config () { - if [ $# -eq 0 ] - then - echo Usage: eden+config config - return - fi - - cd `eden config get --key eden.root`/.. - eden config add $1 - cd - -} - -eden-config () { - if [ $# -eq 0 ] - then - echo Usage: eden-config config - return - fi - - eden config delete $1 - eden_config default -} - -# unset irrelevant variables -eden_deactivate nondestructive - -EDEN_HOME={{.Eden.Root}} -EDEN_BIN={{.Eden.BinDir}} -export EDEN_HOME - -_OLD_EDEN_PATH="$PATH" -PATH="$EDEN_BIN:$PATH" -export PATH - -if [ -z "${EDEN_HOME_DISABLE_PROMPT-}" ] ; then - _OLD_EDEN_PS1="${PS1-}" - PS1="EDEN-`eden config get`_${PS1-}" - export PS1 -fi - -# This should detect bash and zsh, which have a hash command that must -# be called to get it to forget past commands. Without forgetting -# past commands the $PATH changes we made may not be respected -if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then - hash -r 2>/dev/null -fi diff --git a/tests/README.md b/tests/README.md index 7d959e304..eb3eae835 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,7 +1,7 @@ # Eden Integration Tests This directory contains a series of integration tests that meet the -[eden task API](../docs/task-writing.md), and thus can be launched using +[eden task API](../docs/escript/task-writing.md), and thus can be launched using `eden test`. Each subdirectory contains an individual test suite with one or more tests. @@ -25,7 +25,7 @@ To run the entire suite of integration tests, run either: ### Running Individual Tests To run any single suite of integration tests, launch them like any other -[eden test/task](../docs/test-running.md): +[eden test/task](../docs/escript/test-running.md): ```console eden test tests/testdir/ diff --git a/tests/sec/sec_test.go b/tests/sec/sec_test.go index 945e8a354..77cc15813 100644 --- a/tests/sec/sec_test.go +++ b/tests/sec/sec_test.go @@ -27,7 +27,10 @@ func TestMain(m *testing.M) { } twoLevelsUp := filepath.Dir(filepath.Dir(currentPath)) - cfg := openevec.GetDefaultConfig(twoLevelsUp) + cfg, err := openevec.GetDefaultConfig(twoLevelsUp) + if err != nil { + log.Fatalf("Failed to generate default config %v\n", err) + } if err = openevec.ConfigAdd(cfg, cfg.ConfigName, "", false); err != nil { log.Fatal(err)