@@ -67,3 +67,97 @@ ports:
6767 . success ( )
6868 . stdout ( predicate:: str:: contains ( "Port 9999 is available" ) ) ;
6969}
70+
71+ #[ test]
72+ fn test_cli_init ( ) {
73+ let temp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
74+ let config_path = temp_dir. path ( ) . join ( ".envcheck.yaml" ) ;
75+
76+ let mut cmd = Command :: cargo_bin ( "envcheck" ) . unwrap ( ) ;
77+ cmd. current_dir ( temp_dir. path ( ) ) . arg ( "init" ) ;
78+ cmd. assert ( ) . success ( ) ;
79+
80+ assert ! ( config_path. exists( ) ) ;
81+ let content = std:: fs:: read_to_string ( config_path) . unwrap ( ) ;
82+ assert ! ( content. contains( "version: \" 1\" " ) ) ;
83+ assert ! ( content. contains( "tools:" ) ) ;
84+ }
85+
86+ #[ test]
87+ fn test_cli_json_output ( ) {
88+ let mut file = NamedTempFile :: new ( ) . unwrap ( ) ;
89+ writeln ! (
90+ file,
91+ r#"version: "1"
92+ env_vars:
93+ - name: PATH
94+ required: true
95+ "#
96+ ) . unwrap ( ) ;
97+
98+ let mut cmd = Command :: cargo_bin ( "envcheck" ) . unwrap ( ) ;
99+ cmd. arg ( "--config" ) . arg ( file. path ( ) ) . arg ( "--json" ) ;
100+
101+ let output = cmd. assert ( ) . success ( ) . get_output ( ) . stdout . clone ( ) ;
102+ let stdout_str = String :: from_utf8 ( output) . unwrap ( ) ;
103+
104+ // Check if it's valid JSON and has expected fields
105+ let v: serde_json:: Value = serde_json:: from_str ( & stdout_str) . unwrap ( ) ;
106+ assert ! ( v[ "results" ] . is_array( ) ) ;
107+ assert ! ( v[ "summary" ] . is_object( ) ) ;
108+ assert ! ( v[ "passed" ] . is_boolean( ) ) ;
109+ }
110+
111+ #[ test]
112+ fn test_cli_env_regex ( ) {
113+ let mut file = NamedTempFile :: new ( ) . unwrap ( ) ;
114+ writeln ! (
115+ file,
116+ r#"version: "1"
117+ env_vars:
118+ - name: TEST_REGEX_VAR
119+ pattern: "^[0-9]{{3}}$"
120+ required: true
121+ "#
122+ ) . unwrap ( ) ;
123+
124+ // Test failure
125+ let mut cmd = Command :: cargo_bin ( "envcheck" ) . unwrap ( ) ;
126+ cmd. arg ( "--config" ) . arg ( file. path ( ) )
127+ . env ( "TEST_REGEX_VAR" , "abc" ) ;
128+ cmd. assert ( )
129+ . failure ( )
130+ . stdout ( predicate:: str:: contains ( "TEST_REGEX_VAR is set but does not match pattern" ) ) ;
131+
132+ // Test success
133+ let mut cmd = Command :: cargo_bin ( "envcheck" ) . unwrap ( ) ;
134+ cmd. arg ( "--config" ) . arg ( file. path ( ) )
135+ . env ( "TEST_REGEX_VAR" , "123" ) ;
136+ cmd. assert ( )
137+ . success ( )
138+ . stdout ( predicate:: str:: contains ( "TEST_REGEX_VAR is set and matches pattern" ) ) ;
139+ }
140+
141+ #[ test]
142+ fn test_cli_directory_check ( ) {
143+ let temp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
144+ let dir_path = temp_dir. path ( ) . to_str ( ) . unwrap ( ) ;
145+
146+ let mut file = NamedTempFile :: new ( ) . unwrap ( ) ;
147+ writeln ! (
148+ file,
149+ r#"version: "1"
150+ files:
151+ - path: "{}"
152+ is_directory: true
153+ required: true
154+ "# ,
155+ dir_path
156+ ) . unwrap ( ) ;
157+
158+ let mut cmd = Command :: cargo_bin ( "envcheck" ) . unwrap ( ) ;
159+ cmd. arg ( "--config" ) . arg ( file. path ( ) ) ;
160+ cmd. assert ( )
161+ . success ( )
162+ . stdout ( predicate:: str:: contains ( format ! ( "Directory {} exists" , dir_path) ) ) ;
163+ }
0 commit comments