trust-dns-server 0.19.7

Trust-DNS is a safe and secure DNS server with DNSec support. Eventually this could be a replacement for BIND9. The DNSSec support allows for live signing of all records, in it does not currently support records signed offline. The server supports dynamic DNS with SIG0 authenticated requests. Trust-DNS is based on the Tokio and Futures libraries, which means it should be easily integrated into other software that also use those libraries.
Documentation
#![cfg(feature = "sqlite")]

extern crate rusqlite;
extern crate trust_dns_client;
extern crate trust_dns_proto;
extern crate trust_dns_server;

use std::net::*;
use std::str::FromStr;

use rusqlite::*;

use trust_dns_client::rr::*;
use trust_dns_server::store::sqlite::persistence::CURRENT_VERSION;
use trust_dns_server::store::sqlite::Journal;

#[test]
fn test_new_journal() {
    let conn = Connection::open_in_memory().expect("could not create in memory DB");
    assert_eq!(
        Journal::new(conn).expect("new Journal").schema_version(),
        -1
    );
}

#[test]
fn test_init_journal() {
    let conn = Connection::open_in_memory().expect("could not create in memory DB");
    let mut journal = Journal::new(conn).unwrap();
    let version = journal.schema_up().unwrap();
    assert_eq!(version, CURRENT_VERSION);
    assert_eq!(
        Journal::select_schema_version(&*journal.conn()).unwrap(),
        CURRENT_VERSION
    );
}

fn create_test_journal() -> (Record, Journal) {
    let www = Name::from_str("www.example.com").unwrap();

    let mut record = Record::new();
    record.set_name(www);
    record.set_rr_type(RecordType::A);
    record.set_rdata(RData::A(Ipv4Addr::from_str("127.0.0.1").unwrap()));

    // test that this message can be inserted
    let conn = Connection::open_in_memory().expect("could not create in memory DB");
    let mut journal = Journal::new(conn).unwrap();
    journal.schema_up().unwrap();

    // insert the message
    journal.insert_record(0, &record).unwrap();

    // insert another...
    record.set_rdata(RData::A(Ipv4Addr::from_str("127.0.1.1").unwrap()));
    journal.insert_record(0, &record).unwrap();

    (record, journal)
}

#[test]
fn test_insert_and_select_record() {
    let (mut record, journal) = create_test_journal();

    // select the record
    let (row_id, journal_record) = journal
        .select_record(0)
        .expect("persistence error")
        .expect("none");
    record.set_rdata(RData::A(Ipv4Addr::from_str("127.0.0.1").unwrap()));
    assert_eq!(journal_record, record);

    // test another
    let (row_id, journal_record) = journal
        .select_record(row_id + 1)
        .expect("persistence error")
        .expect("none");
    record.set_rdata(RData::A(Ipv4Addr::from_str("127.0.1.1").unwrap()));
    assert_eq!(journal_record, record);

    // check that we get nothing for id over row_id
    let option_none = journal
        .select_record(row_id + 1)
        .expect("persistence error");
    assert!(option_none.is_none());
}

#[test]
fn test_iterator() {
    let (mut record, journal) = create_test_journal();

    let mut iter = journal.iter();

    assert_eq!(
        record.set_rdata(RData::A(Ipv4Addr::from_str("127.0.0.1").unwrap())),
        &iter.next().unwrap()
    );
    assert_eq!(
        record.set_rdata(RData::A(Ipv4Addr::from_str("127.0.1.1").unwrap())),
        &iter.next().unwrap()
    );
    assert_eq!(None, iter.next());
}