Attempt 1: just use a real tweet in a JSON file and deserialize it:
let json = {
let mut file = File::open("src/twitter_status.json").unwrap();
let mut ret = String::new();
file.read_to_string(&mut ret).unwrap();
ret
};
Tweet::from_str(json)
Does not work because egg_mode::common::from_json::FromJson is private and I cannot access that as egg-mode library consumer. I should probably file an issue against egg-mode to make that accessible?
The problem is that Tweet has so many fields that it is very tedious to construct by hand. A more general approach to testing with structs in Rust would be a library that fills any struct with dummy data. I'm thinking of an API like this:
let tweet = fill_struct_with_crap<Tweet>();
Does such a library exist? What else could I do to get test data into a Tweet without handcrafting 200 lines of struct filling code?
Once you have this "template" struct defined, you can use struct update syntax to create new instances with just a few fields set to some values you want to base the tests on.
I am usually trying to provide a default implementation, which tends to be useful anyways and can be re-used for test vector initialization + random modification of selected values.
In general: Pure randomly filled structures tend to be invalid / no use case either. Handling that would require some additional logic, making the test itself pointless because the filter will essentially have all the test logic which kills the atomic / module test concept.