Browse Source

cli: Test command deploys programs on localnet when skipping validator launch (#324)

Armani Ferrante 4 years ago
parent
commit
52628bcfeb
1 changed files with 25 additions and 22 deletions
  1. 25 22
      cli/src/main.rs

+ 25 - 22
cli/src/main.rs

@@ -957,29 +957,32 @@ fn test(
     file: Option<String>,
 ) -> Result<()> {
     with_workspace(cfg_override, |cfg, _path, _cargo| {
-        // Bootup validator, if needed.
-        let validator_handle = match cfg.provider.cluster.url() {
-            "http://127.0.0.1:8899" => {
-                if !skip_build {
-                    build(cfg_override, None, false)?;
-                }
-                let flags = match skip_deploy {
-                    true => None,
-                    false => Some(genesis_flags(cfg)?),
-                };
-                match skip_local_validator {
-                    true => None,
-                    false => Some(start_test_validator(cfg, flags)?),
-                }
-            }
-            _ => {
-                if !skip_deploy {
-                    build(cfg_override, None, false)?;
-                    deploy(cfg_override, None)?;
-                }
-                None
+        // Build if needed.
+        if !skip_build {
+            build(cfg_override, None, false)?;
+        }
+
+        // Run the deploy against the cluster in two cases:
+        //
+        // 1. The cluster is not localnet.
+        // 2. The cluster is localnet, but we're not booting a local validator.
+        //
+        // In either case, skip the deploy if the user specifies.
+        let is_localnet = cfg.provider.cluster == Cluster::Localnet;
+        if !is_localnet || (is_localnet && skip_local_validator) {
+            if !skip_deploy {
+                deploy(cfg_override, None)?;
             }
-        };
+        }
+        // Start local test validator, if needed.
+        let mut validator_handle = None;
+        if is_localnet && (!skip_local_validator) {
+            let flags = match skip_deploy {
+                true => None,
+                false => Some(genesis_flags(cfg)?),
+            };
+            validator_handle = Some(start_test_validator(cfg, flags)?);
+        }
 
         // Setup log reader.
         let log_streams = stream_logs(&cfg.provider.cluster.url());