Unverified Commit c7611367 authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Dynamo IT & IO Layer v0 (#84)

* Dynamo IT & IO Layer v0

This diff adds 2 _extremely_ WIP components:
1. A basic IO layer that uses Hyper and a pure Rust signer. This will change significantly over the coming days.
2. A rudimentary Dynamo DB integration test that creates a table and verifies that it exists.

Neither of these is anywhere near final, but, rather, these are intended as a starting point for discussion.

* Fixup tests
parent eca86039
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
target/
+1110 −0

File added.

Preview size limit exceeded, changes collapsed.

+13 −0
Original line number Diff line number Diff line
[package]
name = "dynamo-it"
version = "0.1.0"
authors = ["Russell Cohen <rcoh@amazon.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
smithy-types = { path = "../../rust-runtime/smithy-types" }
dynamo = { version = "0.0.1", path = "../build/smithyprojections/codegen-test/dynamo/rust-codegen/"}
io-v0 = { path = "../../rust-runtime/io-v0" }
tokio = { version = "0.2", features = ["full"] }
+7 −0
Original line number Diff line number Diff line
version: '3.7'
services:
  dynamodb-local:
    image: amazon/dynamodb-local:latest
    container_name: dynamodb-local
    ports:
    - 8000:8000
+51 −0
Original line number Diff line number Diff line
use dynamo::model::{AttributeDefinition, KeySchemaElement, KeyType, ScalarAttributeType, ProvisionedThroughput};
use dynamo::operation::CreateTable;
use dynamo::output::{ListTablesOutput };
use std::error::Error;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let table_name = "new_table";
    let client = io_v0::Client::local("dynamodb");
    let clear_table = dynamo::operation::DeleteTable::builder()
        .table_name(table_name)
        .build();
    match io_v0::dispatch!(client, clear_table).parsed() {
        Ok(table_deleted) => println!("{:?} table was deleted", table_deleted),
        Err(e) => println!("dispatch error: {:?}", e),
    }

    let tables = io_v0::dispatch!(client, dynamo::operation::ListTables::builder().build()).parsed.unwrap();
    assert_eq!(
        tables.unwrap(),
        ListTablesOutput::builder().table_names(vec![]).build()
    );

    let create_table = CreateTable::builder()
        .table_name(table_name)
        .attribute_definitions(vec![AttributeDefinition::builder()
            .attribute_name("ForumName")
            .attribute_type(ScalarAttributeType::from("S"))
            .build()])
        .key_schema(vec![KeySchemaElement::builder()
            .attribute_name("ForumName")
            .key_type(KeyType::from("HASH"))
            .build()])
        .provisioned_throughput(ProvisionedThroughput::builder().read_capacity_units(100).write_capacity_units(100).build())
        .build();

    let response = io_v0::dispatch!(client, create_table);
    match response.parsed {
        Some(Ok(output)) => assert_eq!(output.table_description.unwrap().table_name.unwrap(), table_name),
        _ => println!("{:?}", response.raw)
    }

    let tables = io_v0::dispatch!(client, dynamo::operation::ListTables::builder().build()).parsed.unwrap();
    assert_eq!(
        tables.unwrap(),
        ListTablesOutput::builder().table_names(vec![table_name.to_string()]).build()
    );

    //assert_eq!(table_created.table_description.unwrap().table_name.unwrap(), "new table");
    Ok(())
}
Loading