test: Modularize the checks for invalid and valid filetypes.