Files
hickory-dns/crates/server/tests/sqlite_tests.rs
Benjamin Fry 408d0baca0 Prepare 0.24 release with branding change to Hickory DNS (#2054)
* update all READMEs with notices about the name change

* update changelog for 0.24

* bump crate versions to 0.24

* update version notice information

* update readmes to back reference trust-dns

* rename all crates to hickory counterparts

* replace all Trust-DNS references in code and comments with Hickory DNS

* rename all Trust-DNS references to Hickory DNS in non-code

* rename all trust-dns-resolver references to hickory-resolver

* rename all trust-dns-client references to hickory-client

* rename all trust-dns-proto references to hickory-proto

* rename all trust-dns-server references to hickory-server

* rename all trust-dns-compatibility references to hickory-compatability

* rename all trust-dns-integration references to hickory-integration

* rename all trust-dns-util references to hickory-util

* Update MIT licenses to reference Hickory DNS

* update all trust-dns references to hickory-dns

* update all bluejekyll github references to hickorydns org

* Update name in Changelog

* make sure hickory-dns logs during tests

* add changelogs for recent main additions

* fix references to trust-dns and hickory in architecture

* update a few trust-dns references in READMEs

* fixup some dangling trust_dns references

* replace fka with formerly in change log

* replace all hickoydns org references to hickory-dns

* replace all http links with https

* update logos

* update hickorydns to hickory-dns for all other org references

* fix Notices of Trust-DNS to Hickory in each Readme
2023-10-13 18:39:28 -07:00

98 lines
2.7 KiB
Rust

#![cfg(feature = "sqlite")]
use std::str::FromStr;
use rusqlite::*;
use hickory_proto::rr::{rdata::A, *};
use hickory_server::store::sqlite::persistence::CURRENT_VERSION;
use hickory_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_data(Some(RData::A(A::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_data(Some(RData::A(A::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_data(Some(RData::A(A::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_data(Some(RData::A(A::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_data(Some(RData::A(A::from_str("127.0.0.1").unwrap()))),
&iter.next().unwrap()
);
assert_eq!(
record.set_data(Some(RData::A(A::from_str("127.0.1.1").unwrap()))),
&iter.next().unwrap()
);
assert_eq!(None, iter.next());
}