Skip to content

Commit

Permalink
fix: tests for gen/build
Browse files Browse the repository at this point in the history
  • Loading branch information
EstebanBorai committed May 24, 2024
1 parent 3997a87 commit d93c0b2
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 18 deletions.
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ dialoguer = "0.11.0"
directories = "5.0.0"
dirs = "5.0.0"
duct = { version = "0.13", default-features = false }
enum-display = "0.1.3"
event-listener = "3.1.0"
eyre = { version = "0.6", default-features = false }
flate2 = { version = "1.0.25" }
Expand Down
1 change: 1 addition & 0 deletions crates/cdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ cargo-generate = { workspace = true }
clap = { workspace = true, features = ["std", "derive", "help", "usage", "error-context", "env", "wrap_help", "suggestions"], default-features = false }
comfy-table = { workspace = true }
current_platform = { workspace = true }
enum-display = { workspace = true }
include_dir = { workspace = true }
serde = { workspace = true, features = ["derive"] }
sysinfo = { workspace = true, default-features = false }
Expand Down
40 changes: 27 additions & 13 deletions crates/cdk/src/generate.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use std::{fmt::Debug, path::PathBuf};
use std::fmt::Debug;
use std::fmt::Display;
use std::path::PathBuf;

use anyhow::{Result, Error};

use clap::Parser;
use clap::{Parser, ValueEnum};
use cargo_generate::{GenerateArgs, TemplatePath, generate};
use include_dir::{Dir, include_dir};
use tempfile::TempDir;
use enum_display::EnumDisplay;

// Note: Cargo.toml.liquid files are changed by cargo-generate to Cargo.toml
// this avoids the problem of cargo trying to parse Cargo.toml template files
Expand All @@ -20,10 +23,12 @@ pub struct GenerateCmd {
/// Connector Name
name: Option<String>,

#[arg(long, value_name = "GROUP")]
/// Connector developer group
group: Option<String>,

/// Connector description used as part of the project metadata
#[arg(long, value_name = "DESCRIPTION")]
conn_description: Option<String>,

/// Local path to generate the SmartConnector project.
Expand Down Expand Up @@ -65,7 +70,7 @@ impl GenerateCmd {
let mut maybe_user_input = CdkTemplateUserValues::new();

maybe_user_input
.with_name(self.name)
.with_name(self.name.clone())
.with_group(self.group)
.with_description(self.conn_description)
.with_conn_type(self.conn_type)
Expand Down Expand Up @@ -95,6 +100,7 @@ enum ConnectorType {
Source,
}

#[derive(Clone, Debug)]
enum CdkTemplateValue {
Name(String),
Group(String),
Expand All @@ -109,7 +115,9 @@ impl Display for CdkTemplateValue {
match self {
CdkTemplateValue::Name(name) => write!(f, "project-name={}", name),
CdkTemplateValue::Group(group) => write!(f, "project-group={}", group),
CdkTemplateValue::Description(description) => write!(f, "project-description={}", description),
CdkTemplateValue::Description(description) => {
write!(f, "project-description={}", description)
}
CdkTemplateValue::ConnFluvioDependencyHash(hash) => {
write!(f, "fluvio-cargo-dependency-hash={}", hash)
}
Expand All @@ -130,43 +138,49 @@ impl CdkTemplateUserValues {
fn new() -> Self {
// By default the fluvio dependency hash is the current git hash
// and its always passed as option to cargo generate
let values = vec![CdkTemplateValue::FluvioDependencyHash(
env!("GIT_HASH")
let values = vec![CdkTemplateValue::ConnFluvioDependencyHash(
env!("GIT_HASH").to_string(),
)];

Self::default()
Self { values }
}

fn to_vec(&self) -> Vec<SmdkTemplateValue> {
fn to_vec(&self) -> Vec<CdkTemplateValue> {
self.values.clone()
}

fn to_cargo_generate(&self) -> Vec<String> {
self.to_vec().iter().map(|v| v.to_string()).collect()
}

fn with_name(&mut self, value: Option<String>) {
fn with_name(&mut self, value: Option<String>) -> &mut Self {
if let Some(v) = value {
tracing::debug!("CDK Argument - project-name={}", v);
self.values.push(CdkTemplateValue::Name(v));
}

self
}

fn with_group(&mut self, value: Option<String>) {
fn with_group(&mut self, value: Option<String>) -> &mut Self {
if let Some(v) = value {
tracing::debug!("CDK Argument - project-group={}", v);
self.values.push(CdkTemplateValue::Group(v));
}

self
}

fn with_description(&mut self, value: Option<String>) {
fn with_description(&mut self, value: Option<String>) -> &mut Self {
if let Some(v) = value {
tracing::debug!("CDK Argument - project-description={}", v);
self.values.push(CdkTemplateValue::Description(v));
}

self
}

fn with_conn_type(&mut self, value: Option<ConnectorType>) {
fn with_conn_type(&mut self, value: Option<ConnectorType>) -> &mut Self {
if let Some(v) = value {
tracing::debug!("CDK Argument - connector-type={}", v);
self.values.push(CdkTemplateValue::ConnType(v));
Expand All @@ -175,7 +189,7 @@ impl CdkTemplateUserValues {
self
}

fn with_conn_public(&mut self, value: Option<bool>) {
fn with_conn_public(&mut self, value: Option<bool>) -> &mut Self {
if let Some(v) = value {
tracing::debug!("CDK Argument - connector-public={}", v);
self.values.push(CdkTemplateValue::ConnPublic(v));
Expand Down
2 changes: 1 addition & 1 deletion crates/smartmodule-development-kit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ anyhow = { workspace = true }
clap = { workspace = true, features = ["std", "derive", "help", "usage", "error-context", "env", "wrap_help", "suggestions"], default-features = false }
current_platform = { workspace = true }
dirs = { workspace = true }
enum-display = { workspace = true }
toml = { workspace = true }
tokio = { workspace = true }
cargo-generate = { workspace = true }
include_dir = { workspace = true }
tempfile = { workspace = true }
enum-display = "0.1.3"
lib-cargo-crate = "0.2.1"


Expand Down
38 changes: 38 additions & 0 deletions tests/cli/cdk_smoke_tests/cdk-basic.bats
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,44 @@ setup_file() {
assert_success
}

@test "Generate and Builds a Sink Connector Package" {
export SINK_CONN_NAME="$PROJECT_NAME_PREFIX-my-sink-conn"

# generate a sink connector
run $CDK_BIN generate $SINK_CONN_NAME \
--group "$PROJECT_NAME_PREFIX" \
--conn-description "My Sink Connector" \
--conn-type sink \
--conn-public true
assert_success

# cd into the sink connector directory
cd $SINK_CONN_NAME

# build connector
run $CDK_BIN build --target x86_64-unknown-linux-gnu
assert_success
}

@test "Generate and Builds a Source Connector Package" {
export SOURCE_CONN_NAME="$PROJECT_NAME_PREFIX-my-sink-conn"

# generate a sink connector
run $CDK_BIN generate $SOURCE_CONN_NAME \
--group "$PROJECT_NAME_PREFIX" \
--conn-description "My Source Connector" \
--conn-type source \
--conn-public true
assert_success

# cd into the sink connector directory
cd $SOURCE_CONN_NAME

# build connector
run $CDK_BIN build --target x86_64-unknown-linux-gnu
assert_success
}

# fix CI authentication to hub service first:
# https://github.com/infinyon/fluvio/issues/3634
# @test "List connectors from hub" {
Expand Down

0 comments on commit d93c0b2

Please sign in to comment.