func TestRenameChain(t *testing.T) { aChain := "hichain" rename1 := "niahctset" rename2 := chainName testNewChain(aChain) defer testKillChain(t, rename2) do := def.NowDo() do.Name = aChain do.NewName = rename1 logger.Infof("Renaming chain (from tests) =>\t%s:%s\n", do.Name, do.NewName) if e := RenameChain(do); e != nil { tests.IfExit(e) } testExistAndRun(t, rename1, true, true) do = def.NowDo() do.Name = rename1 do.NewName = rename2 logger.Infof("Renaming chain (from tests) =>\t%s:%s\n", do.Name, do.NewName) if e := RenameChain(do); e != nil { tests.IfExit(e) } testExistAndRun(t, chainName, true, true) }
func TestLoadServiceDefinition(t *testing.T) { var e error srv, e = loaders.LoadServiceDefinition(servName, true, 1) if e != nil { log.Error(e) tests.IfExit(e) } if srv.Name != servName { log.WithFields(log.Fields{ "expected": servName, "got": srv.Name, }).Error("Improper name on load") } if srv.Service.Name != servName { log.WithFields(log.Fields{ "expected": servName, "got": srv.Service.Name, }).Error("Improper service name on load") tests.IfExit(e) } if !srv.Service.AutoData { log.Error("data_container not properly read on load") tests.IfExit(e) } if srv.Operations.DataContainerName == "" { log.Error("data_container_name not set") tests.IfExit(e) } }
func TestMain(m *testing.M) { var logLevel log.LogLevel logLevel = 0 // logLevel = 1 // logLevel = 3 log.SetLoggers(logLevel, os.Stdout, os.Stderr) if os.Getenv("TEST_IN_CIRCLE") == "true" { erisDir = os.Getenv("HOME") } file = path.Join(erisDir, "temp") tests.IfExit(testsInit()) exitCode := m.Run() if os.Getenv("TEST_IN_CIRCLE") != "true" { testKillIPFS(nil) tests.IfExit(tests.TestsTearDown()) } os.Exit(exitCode) }
func TestRmChain(t *testing.T) { testStartChain(t, chainName) do := def.NowDo() do.Operations.Args, do.Rm, do.RmD = []string{"keys"}, true, true log.WithField("=>", do.Name).Info("Removing keys (from tests)") if e := services.KillService(do); e != nil { tests.IfExit(e) } do = def.NowDo() do.Name, do.Rm, do.RmD = chainName, false, false log.WithField("=>", do.Name).Info("Stopping chain (from tests)") if e := KillChain(do); e != nil { tests.IfExit(e) } testExistAndRun(t, chainName, true, false) do = def.NowDo() do.Name = chainName do.RmD = true log.WithField("=>", do.Name).Info("Removing chain (from tests)") if e := RmChain(do); e != nil { tests.IfExit(e) } testExistAndRun(t, chainName, false, false) }
func TestListKnownActions(t *testing.T) { do := definitions.NowDo() do.Known = true do.Running = false do.Existing = false do.Operations.Args = []string{"testing"} tests.IfExit(util.ListAll(do, "actions")) k := strings.Split(do.Result, "\n") // tests output formatting. if len(k) != 4 { tests.IfExit(fmt.Errorf("Found %v action definition files, Expected 4. Something is wrong.\n", len(k))) } i := 0 for _, actFile := range k { switch actFile { case "do_not_use": i++ case "chain_info": i++ case "dns_register": i++ case "keys_list": i++ } } if i != 4 { tests.IfExit(fmt.Errorf("Could not find all the expected action definition files.\n")) } }
func TestMain(m *testing.M) { log.SetFormatter(logger.ErisFormatter{}) log.SetLevel(log.ErrorLevel) // log.SetLevel(log.InfoLevel) // log.SetLevel(log.DebugLevel) if os.Getenv("TEST_IN_CIRCLE") == "true" { erisDir = os.Getenv("HOME") } // Prevent CLI from starting IPFS. os.Setenv("ERIS_SKIP_ENSURE", "true") file = filepath.Join(erisDir, "temp") tests.IfExit(testsInit()) exitCode := m.Run() if os.Getenv("TEST_IN_CIRCLE") != "true" { tests.IfExit(tests.TestsTearDown()) } os.Exit(exitCode) }
func TestKillRmService(t *testing.T) { testStartService(t, servName, false) do := def.NowDo() do.Name = servName do.Rm = false do.RmD = false do.Operations.Args = []string{servName} logger.Debugf("Stopping serv (via tests) =>\t%s\n", servName) if e := KillService(do); e != nil { logger.Errorln(e) tests.IfExit(e) } testExistAndRun(t, servName, 1, true, false) testNumbersExistAndRun(t, servName, 1, 0) if os.Getenv("TEST_IN_CIRCLE") == "true" { logger.Println("Testing in Circle. Where we don't have rm privileges (due to their driver). Skipping test.") return } do = def.NowDo() do.Name = servName do.Operations.Args = []string{servName} do.File = false do.RmD = true logger.Debugf("Removing serv (via tests) =>\t%s\n", servName) if e := RmService(do); e != nil { logger.Errorln(e) tests.IfExit(e) } testExistAndRun(t, servName, 1, false, false) testNumbersExistAndRun(t, servName, 0, 0) }
func TestNewService(t *testing.T) { do := def.NowDo() servName := "keys" do.Name = servName do.Operations.Args = []string{"quay.io/eris/keys"} log.WithFields(log.Fields{ "=>": do.Name, "args": do.Operations.Args, }).Debug("Creating a new service (from tests)") e := NewService(do) if e != nil { log.Error(e) tests.IfExit(e) } do = def.NowDo() do.Operations.Args = []string{servName} log.WithFields(log.Fields{ "container number": do.Operations.ContainerNumber, "args": do.Operations.Args, }).Debug("Starting service (from tests)") e = StartService(do) if e != nil { log.Error(e) tests.IfExit(e) } testExistAndRun(t, servName, 1, true, true) testNumbersExistAndRun(t, servName, 1, 1) testKillService(t, servName, true) testExistAndRun(t, servName, 1, false, false) }
func TestRenameChain(t *testing.T) { aChain := "hichain" rename1 := "niahctset" rename2 := chainName testNewChain(aChain) defer testKillChain(t, rename2) do := def.NowDo() do.Name = aChain do.NewName = rename1 log.WithFields(log.Fields{ "from": do.Name, "to": do.NewName, }).Info("Renaming chain (from tests)") if e := RenameChain(do); e != nil { tests.IfExit(e) } testExistAndRun(t, rename1, true, true) do = def.NowDo() do.Name = rename1 do.NewName = rename2 log.WithFields(log.Fields{ "from": do.Name, "to": do.NewName, }).Info("Renaming chain (from tests)") if e := RenameChain(do); e != nil { tests.IfExit(e) } testExistAndRun(t, chainName, true, true) }
func TestLoadServiceDefinition(t *testing.T) { var e error srv, e = loaders.LoadServiceDefinition(servName, true, 1) if e != nil { logger.Errorln(e) tests.IfExit(e) } if srv.Name != servName { logger.Errorf("FAILURE: improper name on LOAD. expected: %s\tgot: %s\n", servName, srv.Name) } if srv.Service.Name != servName { logger.Errorf("FAILURE: improper service name on LOAD. expected: %s\tgot: %s\n", servName, srv.Service.Name) tests.IfExit(e) } if !srv.Service.AutoData { logger.Errorf("FAILURE: data_container not properly read on LOAD.\n") tests.IfExit(e) } if srv.Operations.DataContainerName == "" { logger.Errorf("FAILURE: data_container_name not set.\n") tests.IfExit(e) } }
func TestKillRmService(t *testing.T) { testStartService(t, servName, false) do := def.NowDo() do.Name = servName do.Rm = false do.RmD = false do.Operations.Args = []string{servName} log.WithField("=>", servName).Debug("Stopping service (from tests)") if e := KillService(do); e != nil { log.Error(e) tests.IfExit(e) } testExistAndRun(t, servName, 1, true, false) testNumbersExistAndRun(t, servName, 1, 0) if os.Getenv("TEST_IN_CIRCLE") == "true" { log.Warn("Testing in Circle where we don't have rm privileges. Skipping test") return } do = def.NowDo() do.Name = servName do.Operations.Args = []string{servName} do.File = false do.RmD = true log.WithField("=>", servName).Debug("Removing service (from tests)") if e := RmService(do); e != nil { log.Error(e) tests.IfExit(e) } testExistAndRun(t, servName, 1, false, false) testNumbersExistAndRun(t, servName, 0, 0) }
func TestInspectService(t *testing.T) { testStartService(t, servName, false) defer testKillService(t, servName, true) do := def.NowDo() do.Name = servName do.Operations.Args = []string{"name"} do.Operations.ContainerNumber = 1 log.WithFields(log.Fields{ "=>": fmt.Sprintf("%s:%d", servName, do.Operations.ContainerNumber), "args": do.Operations.Args, }).Debug("Inspect service (from tests)") e := InspectService(do) if e != nil { log.Infof("Error inspecting service: %v", e) tests.IfExit(e) } do = def.NowDo() do.Name = servName do.Operations.Args = []string{"config.user"} do.Operations.ContainerNumber = 1 log.WithFields(log.Fields{ "=>": servName, "args": do.Operations.Args, }).Debug("Inspect service (from tests)") e = InspectService(do) if e != nil { log.Infof("Error inspecting service: %v", e) tests.IfExit(e) } }
func TestInspectService(t *testing.T) { testStartService(t, servName, false) defer testKillService(t, servName, true) do := def.NowDo() do.Name = servName do.Operations.Args = []string{"name"} do.Operations.ContainerNumber = 1 logger.Debugf("Inspect service (via tests) =>\t%s:%v:%d\n", servName, do.Operations.Args, do.Operations.ContainerNumber) e := InspectService(do) if e != nil { logger.Infof("Error inspecting service =>\t%v\n", e) tests.IfExit(e) } do = def.NowDo() do.Name = servName do.Operations.Args = []string{"config.user"} do.Operations.ContainerNumber = 1 logger.Debugf("Inspect service (via tests) =>\t%s:%v\n", servName, do.Operations.Args) e = InspectService(do) if e != nil { logger.Infof("Error inspecting service =>\t%v\n", e) tests.IfExit(e) } }
func TestNewService(t *testing.T) { do := def.NowDo() servName := "keys" do.Name = servName do.Operations.Args = []string{"quay.io/eris/keys"} logger.Debugf("New-ing serv (via tests) =>\t%s:%v\n", do.Name, do.Operations.Args) e := NewService(do) if e != nil { logger.Errorln(e) tests.IfExit(e) } do = def.NowDo() do.Operations.Args = []string{servName} // do.Operations.ContainerNumber = util.AutoMagic(0, "service") //do.Operations.ContainerNumber = 1 logger.Debugf("Starting serv (via tests) =>\t%v:%d\n", do.Operations.Args, do.Operations.ContainerNumber) e = StartService(do) if e != nil { logger.Errorln(e) tests.IfExit(e) } testExistAndRun(t, servName, 1, true, true) testNumbersExistAndRun(t, servName, 1, 1) testKillService(t, servName, true) testExistAndRun(t, servName, 1, false, false) }
func TestCatService(t *testing.T) { do := def.NowDo() do.Name = "do_not_use" if err := CatService(do); err != nil { tests.IfExit(err) } if do.Result != ini.DefaultIpfs2() { tests.IfExit(fmt.Errorf("Cat Service on keys does not match DefaultKeys. Got %s \n Expected %s", do.Result, ini.DefaultIpfs2())) } }
// eris chains new -c _ -csv _ func TestChainsNewConfigAndCSV(t *testing.T) { chainID := "testChainsNewConfigAndCSV" do := def.NowDo() do.Name = chainID do.ConfigFile = filepath.Join(common.ChainsPath, "default", "config.toml") do.CSV = filepath.Join(common.ChainsPath, "default", "genesis.csv") do.Operations.ContainerNumber = 1 do.Operations.PublishAllPorts = true log.WithField("=>", do.Name).Info("Creating chain (from tests)") tests.IfExit(NewChain(do)) _, err := ioutil.ReadFile(do.ConfigFile) if err != nil { tests.IfExit(err) } // remove the data container defer removeChainContainer(t, chainID, do.Operations.ContainerNumber) // verify the contents of config.toml ops := loaders.LoadDataDefinition(do.Name, do.Operations.ContainerNumber) util.Merge(ops, do.Operations) ops.Args = []string{"cat", fmt.Sprintf("/home/eris/.eris/chains/%s/config.toml", chainID)} result := trimResult(string(runContainer(t, ops))) configDefault := filepath.Join(erisDir, "chains", "default", "config.toml") read, err := ioutil.ReadFile(configDefault) if err != nil { tests.IfExit(err) } contents := trimResult(string(read)) if result != contents { tests.IfExit(fmt.Errorf("config not properly copied. Got: %s \n Expected: %s", result, contents)) } // verify the contents of genesis.json (should have the validator from the csv) ops = loaders.LoadDataDefinition(do.Name, do.Operations.ContainerNumber) util.Merge(ops, do.Operations) ops.Args = []string{"cat", fmt.Sprintf("/home/eris/.eris/chains/%s/genesis.json", chainID)} result = string(runContainer(t, ops)) var found bool for _, s := range strings.Split(result, "\n") { if strings.Contains(s, ini.DefaultPubKeys[0]) { found = true break } } if !found { tests.IfExit(fmt.Errorf("Did not find pubkey %s in genesis.json: %s", ini.DefaultPubKeys[0], result)) } }
func TestCatService(t *testing.T) { do := def.NowDo() do.Name = "ipfs" if err := CatService(do); err != nil { tests.IfExit(err) } //if init worked properly...? read, err := ioutil.ReadFile(filepath.Join(config.GlobalConfig.ErisDir, "services", "ipfs.toml")) if err != nil { tests.IfExit(err) } if do.Result != string(read) { tests.IfExit(fmt.Errorf("Cat Service on ipfs does not match Default. Got %s \n Expected %s", do.Result, string(read))) } }
func TestImportService(t *testing.T) { do := def.NowDo() do.Name = "eth" if hash == "" { do.Hash = "QmQ1LZYPNG4wSb9dojRicWCmM4gFLTPKFUhFnMTR3GKuA2" } else { do.Hash = hash } logger.Debugf("Import-ing serv (via tests) =>\t%s:%v\n", do.Name, do.Hash) // because IPFS is testy, we retry the put up to // 10 times. passed := false for i := 0; i < 9; i++ { if err := ImportService(do); err != nil { time.Sleep(2 * time.Second) continue } else { passed = true break } } if !passed { // final time will throw if err := ImportService(do); err != nil { tests.IfExit(err) } } testKillService(t, "ipfs", true) testExistAndRun(t, "ipfs", 1, false, false) }
func TestMain(m *testing.M) { log.SetFormatter(logger.ErisFormatter{}) log.SetLevel(log.ErrorLevel) // log.SetLevel(log.InfoLevel) // log.SetLevel(log.DebugLevel) tests.IfExit(testsInit()) exitCode := m.Run() if os.Getenv("TEST_IN_CIRCLE") != "true" { tests.IfExit(tests.TestsTearDown()) } os.Exit(exitCode) }
func TestStartKillServiceWithDependencies(t *testing.T) { do := def.NowDo() do.Operations.Args = []string{"do_not_use"} log.WithFields(log.Fields{ "service": servName, "dependency": "keys", }).Debug("Starting service with dependency (from tests)") if e := StartService(do); e != nil { log.Infof("Error starting service: %v", e) tests.IfExit(e) } defer func() { testKillService(t, "do_not_use", true) testExistAndRun(t, servName, 1, false, false) testNumbersExistAndRun(t, servName, 0, 0) testKillService(t, "keys", true) }() testExistAndRun(t, servName, 1, true, true) testExistAndRun(t, "keys", 1, true, true) testNumbersExistAndRun(t, "keys", 1, 1) testNumbersExistAndRun(t, servName, 1, 1) }
func TestExportService(t *testing.T) { testStartService(t, "ipfs", false) time.Sleep(5 * time.Second) do := def.NowDo() do.Name = "ipfs" // because IPFS is testy, we retry the put up to // 10 times. passed := false for i := 0; i < 9; i++ { if err := ExportService(do); err != nil { time.Sleep(2 * time.Second) continue } else { passed = true break } } if !passed { // final time will throw if err := ExportService(do); err != nil { tests.IfExit(err) } } hash = do.Result testExistAndRun(t, "ipfs", 1, true, true) }
func TestStartKillServiceWithDependencies(t *testing.T) { do := def.NowDo() do.Operations.Args = []string{"do_not_use"} //do.Operations.ContainerNumber = 1 // do.Operations.ContainerNumber = util.AutoMagic(0, "service") logger.Debugf("Starting service with deps =>\t%s:%s\n", servName, "keys") if e := StartService(do); e != nil { logger.Infof("Error starting service =>\t%v\n", e) tests.IfExit(e) } defer func() { testKillService(t, "do_not_use", true) testExistAndRun(t, servName, 1, false, false) testNumbersExistAndRun(t, servName, 0, 0) // XXX: option for kill to kill dependencies too testKillService(t, "keys", true) //testExistAndRun(t, "keys", 1, false, false) //testNumbersExistAndRun(t, "keys", 1, 0) }() testExistAndRun(t, servName, 1, true, true) testExistAndRun(t, "keys", 1, true, true) testNumbersExistAndRun(t, "keys", 1, 1) testNumbersExistAndRun(t, servName, 1, 1) }
func TestKnownChain(t *testing.T) { do := def.NowDo() do.Known = true do.Existing = false do.Running = false do.Operations.Args = []string{"testing"} tests.IfExit(util.ListAll(do, "chains")) k := strings.Split(do.Result, "\n") // tests output formatting. // apparently these have extra space if strings.TrimSpace(k[0]) != chainName { log.WithField("=>", do.Result).Debug("Result") tests.IfExit(fmt.Errorf("Unexpected chain definition file. Got %s, expected %s.", k[0], chainName)) } }
func TestKnownServices(t *testing.T) { do := def.NowDo() do.Known = true do.Existing = false do.Running = false do.Operations.Args = []string{"testing"} tests.IfExit(util.ListAll(do, "services")) k := strings.Split(do.Result, "\n") // tests output formatting. if len(k) != 13 { tests.IfExit(fmt.Errorf("Did not find exactly 13 service definitions files, found %v. Something is wrong.\n", len(k))) } i := 0 for _, actFile := range k { switch actFile { case "btcd": i++ case "compilers": i++ case "eth": i++ case "ipfs": i++ case "keys": i++ case "logspout": i++ case "logsrotate": i++ case "mindy": i++ case "mint": i++ case "openbazaar": i++ case "tinydns": i++ case "watchtower": i++ case "do_not_use": i++ } } if i != 13 { tests.IfExit(fmt.Errorf("Could not find all the expected service definition files.\n")) } }
func testsInit() error { if err := tests.TestsInit("files"); err != nil { return err } f, err := os.Create(file) tests.IfExit(err) f.Write([]byte(content)) do1 := definitions.NowDo() do1.Operations.Args = []string{"ipfs"} err = services.StartService(do1) tests.IfExit(err) time.Sleep(5 * time.Second) // boot time return nil }
func TestListActions(t *testing.T) { do := definitions.NowDo() do.Known = true do.Running = false do.Existing = false do.Operations.Args = []string{"testing"} tests.IfExit(util.ListAll(do, "actions")) k := strings.Split(do.Result, "\n") // tests output formatting. if len(k) != 1 { tests.IfExit(fmt.Errorf("The wrong number of action definitions have been found. Something is wrong.\n")) } if k[0] != "do_not_use" { tests.IfExit(fmt.Errorf("Could not find \"do not use\" action definition.\n")) } }
func TestKnownService(t *testing.T) { do := def.NowDo() do.Known = true do.Existing = false do.Running = false do.Operations.Args = []string{"testing"} tests.IfExit(util.ListAll(do, "services")) k := strings.Split(do.Result, "\n") // tests output formatting. if len(k) != 3 { tests.IfExit(fmt.Errorf("Did not find exactly 3 service definitions files. Something is wrong.\n")) } if k[1] != "ipfs" { tests.IfExit(fmt.Errorf("Could not find ipfs service definition. Services found =>\t%v\n", k)) } }
func ensureTomlValue(t *testing.T, s, field, value string) bool { if strings.Contains(s, field) { if !strings.Contains(s, value) { tests.IfExit(fmt.Errorf("Expected %s to be %s. Got: %s", field, value, s)) } return true } return false }
func testNumbersExistAndRun(t *testing.T, servName string, containerExist, containerRun int) { logger.Infof("\nTesting number of (%s) containers. Existing? (%d) and Running? (%d)\n", servName, containerExist, containerRun) logger.Debugf("Checking Existing Containers =>\t%s\n", servName) exist := util.HowManyContainersExisting(servName, "service") logger.Debugf("Checking Running Containers =>\t%s\n", servName) run := util.HowManyContainersRunning(servName, "service") if exist != containerExist { tests.IfExit(fmt.Errorf("Wrong number of containers existing for service (%s). Expected (%d). Got (%d).\n", servName, containerExist, exist)) } if run != containerRun { tests.IfExit(fmt.Errorf("Wrong number of containers running for service (%s). Expected (%d). Got (%d).\n", servName, containerRun, run)) } logger.Infoln("All good.\n") }
func removeChainContainer(t *testing.T, chainID string, cNum int) { do := def.NowDo() do.Name = chainID do.Rm, do.Force, do.RmD = true, true, true do.Operations.ContainerNumber = cNum if err := KillChain(do); err != nil { tests.IfExit(err) } }