First try to configure CI (#16)
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
This commit is contained in:
parent
15c4a315c6
commit
1c77ea94ca
|
@ -0,0 +1,54 @@
|
|||
name: Master
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Run tests on ${{ matrix.target }} ${{ matrix.toolchain }}
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
toolchain:
|
||||
- stable
|
||||
- nightly
|
||||
target:
|
||||
- x86_64-unknown-linux-gnu
|
||||
- x86_64-unknown-linux-musl
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- run: apt-get update
|
||||
if: ${{ matrix.toolchain == "x86_64-unknown-linux-musl" }}
|
||||
- run: apt-get install -y musl
|
||||
if: ${{ matrix.toolchain == "x86_64-unknown-linux-musl" }}
|
||||
- name: Cache cargo registry
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ~/.cargo/registry
|
||||
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
|
||||
- name: Cache cargo index
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ~/.cargo/git
|
||||
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
|
||||
- name: Cache cargo build
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: target
|
||||
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ matrix.toolchain }}
|
||||
target: ${{ matrix.target }}
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: build
|
||||
toolchain: ${{ matrix.toolchain }}
|
||||
target: ${{ matrix.target }}
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: test
|
||||
toolchain: ${{ matrix.toolchain }}
|
||||
target: ${{ matrix.target }}
|
|
@ -0,0 +1,58 @@
|
|||
name: Pull Request
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Run tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Cache cargo registry
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ~/.cargo/registry
|
||||
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
|
||||
- name: Cache cargo index
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ~/.cargo/git
|
||||
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
|
||||
- name: Cache cargo build
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: target
|
||||
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: stable
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: build
|
||||
toolchain: stable
|
||||
target: x86_64-unknown-linux-gnu
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: test
|
||||
toolchain: stable
|
||||
target: x86_64-unknown-linux-gnu
|
||||
|
||||
fmt:
|
||||
name: Format check
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: stable
|
||||
override: true
|
||||
components: rustfmt
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: fmt
|
||||
args: --all -- --check
|
|
@ -1,25 +0,0 @@
|
|||
name: Rust
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: build
|
||||
toolchain: stable
|
||||
target: x86_64-unknown-linux-gnu
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: test
|
||||
toolchain: stable
|
||||
target: x86_64-unknown-linux-gnu
|
|
@ -44,10 +44,7 @@ pub trait AttributesWriter {
|
|||
}
|
||||
|
||||
pub(crate) trait DataAttributesWriter {
|
||||
fn set_datacontenttype(
|
||||
&mut self,
|
||||
datacontenttype: Option<impl Into<String>>,
|
||||
);
|
||||
fn set_datacontenttype(&mut self, datacontenttype: Option<impl Into<String>>);
|
||||
fn set_dataschema(&mut self, dataschema: Option<impl Into<String>>);
|
||||
}
|
||||
|
||||
|
@ -169,10 +166,7 @@ impl AttributesWriter for Attributes {
|
|||
}
|
||||
|
||||
impl DataAttributesWriter for Attributes {
|
||||
fn set_datacontenttype(
|
||||
&mut self,
|
||||
datacontenttype: Option<impl Into<String>>,
|
||||
) {
|
||||
fn set_datacontenttype(&mut self, datacontenttype: Option<impl Into<String>>) {
|
||||
match self {
|
||||
Attributes::V10(a) => a.set_datacontenttype(datacontenttype),
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@ impl Data {
|
|||
/// [`AsRef<[u8]>`]: https://doc.rust-lang.org/std/convert/trait.AsRef.html
|
||||
/// [`Data`]: enum.Data.html
|
||||
pub fn from_base64<I>(i: I) -> Result<Self, base64::DecodeError>
|
||||
where
|
||||
I: AsRef<[u8]>,
|
||||
where
|
||||
I: AsRef<[u8]>,
|
||||
{
|
||||
Ok(base64::decode(&i)?.into())
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ impl TryFrom<Data> for String {
|
|||
match value {
|
||||
Data::String(s) => Ok(s),
|
||||
Data::Binary(v) => Ok(String::from_utf8(v)?),
|
||||
Data::Json(s) => Ok(s.to_string())
|
||||
Data::Json(s) => Ok(s.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
use super::{Attributes, AttributesReader, AttributesWriter, Data, ExtensionValue, SpecVersion, AttributesV10};
|
||||
use super::{
|
||||
Attributes, AttributesReader, AttributesV10, AttributesWriter, Data, ExtensionValue,
|
||||
SpecVersion,
|
||||
};
|
||||
use crate::event::attributes::DataAttributesWriter;
|
||||
use chrono::{DateTime, FixedOffset};
|
||||
use delegate::delegate;
|
||||
use std::convert::{TryFrom};
|
||||
use crate::event::attributes::DataAttributesWriter;
|
||||
use std::convert::TryFrom;
|
||||
|
||||
/// Data structure that represents a [CloudEvent](https://github.com/cloudevents/spec/blob/master/spec.md).
|
||||
/// It provides methods to get the attributes through [`AttributesReader`]
|
||||
|
@ -74,7 +77,7 @@ impl Default for Event {
|
|||
fn default() -> Self {
|
||||
Event {
|
||||
attributes: Attributes::V10(AttributesV10::default()),
|
||||
data: None
|
||||
data: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -94,15 +97,18 @@ impl Event {
|
|||
/// let mut e = Event::default();
|
||||
/// e.write_data("application/json", None, json!({}))
|
||||
/// ```
|
||||
pub fn write_data<S: Into<String>, D: Into<Data>>(&mut self, content_type: S, schema: Option<S>, value: D) {
|
||||
pub fn write_data<S: Into<String>, D: Into<Data>>(
|
||||
&mut self,
|
||||
content_type: S,
|
||||
schema: Option<S>,
|
||||
value: D,
|
||||
) {
|
||||
self.attributes.set_datacontenttype(Some(content_type));
|
||||
self.attributes.set_dataschema(schema);
|
||||
self.data = Some(value.into());
|
||||
}
|
||||
|
||||
pub fn get_data<T: Sized + From<Data>>(
|
||||
&self,
|
||||
) -> Option<T> {
|
||||
pub fn get_data<T: Sized + From<Data>>(&self) -> Option<T> {
|
||||
match self.data.as_ref() {
|
||||
Some(d) => Some(T::from(d.clone())),
|
||||
None => None,
|
||||
|
@ -128,8 +134,6 @@ impl Event {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
@ -140,17 +144,11 @@ mod tests {
|
|||
"hello": "world"
|
||||
});
|
||||
|
||||
let mut e = Event::default();
|
||||
e.write_data(
|
||||
"application/json",
|
||||
None,
|
||||
expected_data.clone()
|
||||
);
|
||||
|
||||
let mut e = Event::default();
|
||||
e.write_data("application/json", None, expected_data.clone());
|
||||
|
||||
let data: serde_json::Value = e.try_get_data().unwrap().unwrap();
|
||||
assert_eq!(expected_data, data);
|
||||
assert_eq!("application/json", e.get_datacontenttype().unwrap())
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use crate::event::attributes::DataAttributesWriter;
|
||||
use crate::event::{AttributesReader, AttributesWriter, ExtensionValue, SpecVersion};
|
||||
use chrono::{DateTime, FixedOffset};
|
||||
use std::collections::HashMap;
|
||||
use crate::event::attributes::DataAttributesWriter;
|
||||
use uuid::Uuid;
|
||||
use hostname::get_hostname;
|
||||
use std::collections::HashMap;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub struct Attributes {
|
||||
id: String,
|
||||
|
@ -109,10 +109,7 @@ impl AttributesWriter for Attributes {
|
|||
}
|
||||
|
||||
impl DataAttributesWriter for Attributes {
|
||||
fn set_datacontenttype(
|
||||
&mut self,
|
||||
datacontenttype: Option<impl Into<String>>,
|
||||
) {
|
||||
fn set_datacontenttype(&mut self, datacontenttype: Option<impl Into<String>>) {
|
||||
self.datacontenttype = datacontenttype.map(Into::into)
|
||||
}
|
||||
|
||||
|
@ -131,7 +128,7 @@ impl Default for Attributes {
|
|||
dataschema: None,
|
||||
subject: None,
|
||||
time: None,
|
||||
extensions: HashMap::new()
|
||||
extensions: HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue