Skip to content

Commit

Permalink
add certus file reader
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph0x45 committed Feb 4, 2023
1 parent 93a8252 commit 634de5d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2012-2022 Scott Chacon and others
Copyright (c) 2012-2023 Scott Chacon and others

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
17 changes: 13 additions & 4 deletions src/interpreter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@


pub fn interpreter(){

pub fn interpreter( certus_file: &str ){
let mut certus_file_content = "";
let file_reader = std::fs::read_to_string(certus_file);
match file_reader {
Ok(content)=>{
println!("{}", content);
certus_file_content = &content;
},
Err(_)=>{
println!("Something went wrong 🥲\nAre you sure this file exists?");
return
}
}
}
15 changes: 13 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ mod interpreter;
mod runner;
mod utils;

use std::path::Path;

use utils::write_template;
use reqwest;
use interpreter::interpreter;
// use reqwest;


fn main() -> () {
Expand Down Expand Up @@ -41,7 +44,15 @@ fn main() -> () {
},
_=>{
//User wants to run a file or a directory
println!("{}", command)
if Path::new(&command).is_dir(){
println!("certus doesn't support running tests in a directory yet. Please pass a certus file instead");
return
}
if !command.ends_with(".certus") {
println!("This is not a certus file");
return
}
interpreter(&command);
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ GET https://jsonplaceholder.typicode.com/todos/1
[CFG]
# Here goes all the configuration for your request, such as headers and body
[EXPECT]
# This is where you specify the status code you expect and what certus must do when it gets such codes
HTTP 200
# You can access the body and header of the response and make assertions on it for further test validation
# HTTP 404
# body.data: "something not found"
"#;
template_file.write(template.as_bytes()).expect("Something went wrong 🥲");
}
11 changes: 11 additions & 0 deletions test.certus
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This is a basic certus test
# The lines preceeded by a '#' are ignored by the interpreter
GET https://jsonplaceholder.typicode.com/todos/1
[CFG]
# Here goes all the configuration for your request, such as headers and body
[EXPECT]
# This is where you specify the status code you expect and what certus must do when it gets such codes
HTTP 200
# You can access the body and header of the response and make assertions on it for further test validation
# HTTP 404
# body.data: "something not found"

0 comments on commit 634de5d

Please sign in to comment.