Skip to content

Commit af7030b

Browse files
fix: Integraction tests
1 parent e500bd0 commit af7030b

File tree

2 files changed

+51
-42
lines changed

2 files changed

+51
-42
lines changed

src/provider/create.rs

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -91,45 +91,9 @@ pub async fn run(args: Args, ctx: &mut crate::Context) -> miette::Result<()> {
9191
Some(url) => url,
9292
None => inquire::Text::new("URL:").prompt().into_diagnostic()?,
9393
};
94-
let headers: HashMap<String, String> = inquire::Text::new(
95-
"Add request headers? Example: 'dmtr-api-key:dmtr_jdndajs,other:other-value'",
96-
)
97-
.prompt()
98-
.into_diagnostic()?
99-
.split(",")
100-
.flat_map(|keyval| {
101-
if keyval.is_empty() {
102-
return None;
103-
}
104-
let mut parts = keyval.split(":");
105-
let key = match parts.next() {
106-
Some(s) => s,
107-
None => return Some(Err(miette::Error::msg("Invalid header"))),
108-
};
109-
let val = match parts.next() {
110-
Some(s) => s,
111-
None => return Some(Err(miette::Error::msg("Invalid header"))),
112-
};
113-
Some(Ok((key.to_string(), val.to_string())))
114-
})
115-
.collect::<Result<_, miette::Error>>()?;
116-
117-
let trp_url = match args.trp_url {
118-
Some(url) => Some(url),
119-
None => {
120-
let response = inquire::Text::new("TRP URL (leave empty for undefined):")
121-
.prompt()
122-
.into_diagnostic()?;
123-
if response.is_empty() {
124-
None
125-
} else {
126-
Some(response)
127-
}
128-
}
129-
};
130-
let mut trp_headers = None;
131-
if trp_url.is_some() {
132-
let aux: HashMap<String, String> = inquire::Text::new(
94+
let headers: HashMap<String, String> = match args.utxorpc_headers {
95+
Some(aux) => serde_json::from_str(&aux).into_diagnostic()?,
96+
None => inquire::Text::new(
13397
"Add request headers? Example: 'dmtr-api-key:dmtr_jdndajs,other:other-value'",
13498
)
13599
.prompt()
@@ -150,7 +114,50 @@ pub async fn run(args: Args, ctx: &mut crate::Context) -> miette::Result<()> {
150114
};
151115
Some(Ok((key.to_string(), val.to_string())))
152116
})
153-
.collect::<Result<_, miette::Error>>()?;
117+
.collect::<Result<_, miette::Error>>()?,
118+
};
119+
120+
let trp_url = match args.trp_url {
121+
Some(url) => Some(url),
122+
None => {
123+
let response = inquire::Text::new("TRP URL (leave empty for undefined):")
124+
.prompt()
125+
.into_diagnostic()?;
126+
if response.is_empty() {
127+
None
128+
} else {
129+
Some(response)
130+
}
131+
}
132+
};
133+
let mut trp_headers = None;
134+
if trp_url.is_some() {
135+
let aux: HashMap<String, String> = match args.trp_headers {
136+
Some(inner) => serde_json::from_str(&inner).into_diagnostic()?,
137+
138+
None => inquire::Text::new(
139+
"Add request headers? Example: 'dmtr-api-key:dmtr_jdndajs,other:other-value'",
140+
)
141+
.prompt()
142+
.into_diagnostic()?
143+
.split(",")
144+
.flat_map(|keyval| {
145+
if keyval.is_empty() {
146+
return None;
147+
}
148+
let mut parts = keyval.split(":");
149+
let key = match parts.next() {
150+
Some(s) => s,
151+
None => return Some(Err(miette::Error::msg("Invalid header"))),
152+
};
153+
let val = match parts.next() {
154+
Some(s) => s,
155+
None => return Some(Err(miette::Error::msg("Invalid header"))),
156+
};
157+
Some(Ok((key.to_string(), val.to_string())))
158+
})
159+
.collect::<Result<_, miette::Error>>()?,
160+
};
154161

155162
if !aux.is_empty() {
156163
trp_headers = Some(aux);

test/integration.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ fi
4949
# Create provider
5050
OUTPUT=$(run provider create \
5151
--name test \
52-
--kind utxorpc \
5352
--is-default true \
5453
--network-kind testnet \
55-
--parameters '{"url":"https://preprod.utxorpc-v0.demeter.run","headers":{"dmtr-api-key":"utxorpc1yzpcjdkeuqgy5pfg69z"}}'
54+
--utxorpc-url "https://preprod.utxorpc-v0.demeter.run" \
55+
--utxorpc-headers '{"dmtr-api-key":"utxorpc1yzpcjdkeuqgy5pfg69z"}' \
56+
--trp-url "https://preprod.trp-m1.demeter.run" \
57+
--trp-headers '{"dmtr-api-key":"trpyzpcjdkeuqgy5pfg69z"}'
5658
)
5759
NAME=$(echo "$OUTPUT" | jq -r '.name' )
5860
if [[ "$NAME" == "test" ]]; then

0 commit comments

Comments
 (0)