-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is the second PR of a two-part feature related to #3578. The first part can be found in #3611. Reuse the code from #3611 at `cdk hub`. CI is expected to fail, see the comment below. Closes #3578
- Loading branch information
1 parent
472e361
commit d0dd859
Showing
7 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use std::sync::Arc; | ||
|
||
use anyhow::Result; | ||
use clap::Parser; | ||
use fluvio_future::task; | ||
use fluvio_hub_util::cmd::{ConnectorHubListOpts, ConnectorHubDownloadOpts}; | ||
use fluvio_extension_common::PrintTerminal; | ||
|
||
/// Work with Connectors hub | ||
#[derive(Debug, Parser)] | ||
pub enum HubCmd { | ||
#[command(name = "list")] | ||
List(ConnectorHubListOpts), | ||
#[command(name = "download")] | ||
Download(ConnectorHubDownloadOpts), | ||
} | ||
|
||
impl HubCmd { | ||
pub fn process(self) -> Result<()> { | ||
let terminal = Arc::new(PrintTerminal::new()); | ||
match self { | ||
HubCmd::List(opt) => task::run_block_on(opt.process(terminal)), | ||
HubCmd::Download(opt) => task::run_block_on(opt.process(terminal)), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,12 @@ use anyhow::Result; | |
|
||
use fluvio_extension_common::Terminal; | ||
|
||
const CONNECTOR_HUB_DOWNLOAD_REDIRECT_MESSAGE: &str = r#"Connectors running on `InfinyOn Cloud` are automatically downloaded during `fluvio cloud connector create ...`. | ||
Connectors running locally require `cdk` to download and deploy: | ||
1. Install cdk: `fluvio install cdk` | ||
2. Download connector: `cdk hub download ...` | ||
3. Deploy connector: `cdk deploy start ...`"#; | ||
|
||
/// List available Connectors in the hub | ||
#[derive(Debug, Parser)] | ||
pub enum ConnectorHubSubCmd { | ||
|
@@ -21,7 +27,56 @@ impl ConnectorHubSubCmd { | |
pub async fn process<O: Terminal + Debug + Send + Sync>(self, out: Arc<O>) -> Result<()> { | ||
match self { | ||
ConnectorHubSubCmd::List(opts) => opts.process(out).await, | ||
ConnectorHubSubCmd::Download(opts) => opts.process(out).await, | ||
ConnectorHubSubCmd::Download(_) => { | ||
out.println(CONNECTOR_HUB_DOWNLOAD_REDIRECT_MESSAGE); | ||
Ok(()) | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use std::sync::{RwLock, Arc}; | ||
|
||
use clap::Parser; | ||
use fluvio_extension_common::Terminal; | ||
use fluvio_future::task::run_block_on; | ||
|
||
use crate::client::hub::connector::CONNECTOR_HUB_DOWNLOAD_REDIRECT_MESSAGE; | ||
|
||
use super::ConnectorHubSubCmd; | ||
|
||
#[derive(Default, Debug)] | ||
struct MockTerminal(Arc<RwLock<String>>); | ||
impl Terminal for MockTerminal { | ||
fn print(&self, msg: &str) { | ||
self.0 | ||
.write() | ||
.expect("could not print to MockTerminal") | ||
.push_str(msg); | ||
} | ||
|
||
fn println(&self, msg: &str) { | ||
self.0 | ||
.write() | ||
.expect("could not println to MockTerminal") | ||
.push_str(&format!("{msg}\n")); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_calling_fluvio_hub_download_displays_a_help_message() { | ||
let terminal = Arc::new(MockTerminal::default()); | ||
let cmd = | ||
ConnectorHubSubCmd::parse_from(["conn", "download", "infinyon/[email protected]"]); | ||
|
||
assert!(matches!(cmd, ConnectorHubSubCmd::Download(_))); | ||
|
||
run_block_on(cmd.process(terminal.clone())).expect("command failed to process"); | ||
|
||
let x = terminal.0.read().unwrap(); | ||
let x = x.as_str().trim_end(); | ||
assert_eq!(x, CONNECTOR_HUB_DOWNLOAD_REDIRECT_MESSAGE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters