@@ -4,34 +4,49 @@ import (
44 "os"
55 "os/exec"
66 "path/filepath"
7+ "runtime"
78 "strings"
89 "testing"
910 "time"
1011)
1112
1213// TestEndToEndIntegration performs a full integration test
1314func TestEndToEndIntegration (t * testing.T ) {
14- // Skip if no API key available
15- appKey := os .Getenv ("CIMIS_APP_KEY" )
16- if appKey == "" {
17- t .Skip ("CIMIS_APP_KEY not set, skipping integration test" )
18- }
19-
2015 // Create temporary directory for test data
2116 tmpDir := t .TempDir ()
2217 dataDir := filepath .Join (tmpDir , "data" )
2318
24- // Build CLI
19+ // Build CLI - get project root from current file location
20+ _ , testFile , _ , _ := runtime .Caller (0 )
21+ projectRoot := filepath .Join (filepath .Dir (testFile ), ".." , ".." )
22+
2523 cliPath := filepath .Join (tmpDir , "cimis" )
26- buildCmd := exec .Command ("go" , "build" , "-o" , cliPath , "." )
27- buildCmd .Dir = ".." // Project root
24+ buildCmd := exec .Command ("go" , "build" , "-o" , cliPath , "./cmd/cimis " )
25+ buildCmd .Dir = projectRoot
2826 if output , err := buildCmd .CombinedOutput (); err != nil {
2927 t .Fatalf ("Failed to build CLI: %v\n Output: %s" , err , output )
3028 }
3129
30+ t .Run ("Version" , func (t * testing.T ) {
31+ cmd := exec .Command (cliPath , "version" )
32+ cmd .Dir = tmpDir
33+
34+ output , err := cmd .CombinedOutput ()
35+ if err != nil {
36+ t .Fatalf ("Version failed: %v\n Output: %s" , err , output )
37+ }
38+
39+ outputStr := string (output )
40+ if ! strings .Contains (outputStr , "cimis" ) {
41+ t .Errorf ("Expected 'cimis' in version output, got: %s" , outputStr )
42+ }
43+
44+ t .Logf ("Version output: %s" , outputStr )
45+ })
46+
3247 t .Run ("InitDatabase" , func (t * testing.T ) {
3348 cmd := exec .Command (cliPath , "init" )
34- cmd .Env = append ( os .Environ (), "CIMIS_APP_KEY=" + appKey )
49+ cmd .Env = os .Environ ()
3550 cmd .Dir = tmpDir
3651
3752 output , err := cmd .CombinedOutput ()
@@ -53,6 +68,48 @@ func TestEndToEndIntegration(t *testing.T) {
5368 t .Log ("Database initialized successfully" )
5469 })
5570
71+ t .Run ("Stats" , func (t * testing.T ) {
72+ cmd := exec .Command (cliPath , "stats" )
73+ cmd .Env = os .Environ ()
74+ cmd .Dir = tmpDir
75+
76+ output , err := cmd .CombinedOutput ()
77+ if err != nil {
78+ t .Fatalf ("Stats failed: %v\n Output: %s" , err , output )
79+ }
80+
81+ outputStr := string (output )
82+ if ! strings .Contains (outputStr , "Statistics" ) {
83+ t .Errorf ("Expected 'Statistics' in output, got: %s" , outputStr )
84+ }
85+
86+ t .Logf ("Stats output: %s" , outputStr )
87+ })
88+
89+ t .Run ("Verify" , func (t * testing.T ) {
90+ cmd := exec .Command (cliPath , "verify" )
91+ cmd .Env = os .Environ ()
92+ cmd .Dir = tmpDir
93+
94+ output , err := cmd .CombinedOutput ()
95+ if err != nil {
96+ t .Fatalf ("Verify failed: %v\n Output: %s" , err , output )
97+ }
98+
99+ outputStr := string (output )
100+ if ! strings .Contains (outputStr , "OK" ) && ! strings .Contains (outputStr , "complete" ) && ! strings .Contains (outputStr , "verified" ) {
101+ t .Errorf ("Expected verification result in output, got: %s" , outputStr )
102+ }
103+
104+ t .Logf ("Verify output: %s" , outputStr )
105+ })
106+
107+ // Skip API-dependent tests if no key is available
108+ appKey := os .Getenv ("CIMIS_APP_KEY" )
109+ if appKey == "" {
110+ t .Skip ("Skipping API-dependent tests - CIMIS_APP_KEY not set" )
111+ }
112+
56113 t .Run ("FetchData" , func (t * testing.T ) {
57114 cmd := exec .Command (cliPath , "fetch" , "-station" , "2" , "-days" , "7" )
58115 cmd .Env = append (os .Environ (), "CIMIS_APP_KEY=" + appKey )
@@ -123,42 +180,6 @@ func TestEndToEndIntegration(t *testing.T) {
123180
124181 t .Logf ("Query output: %s" , outputStr )
125182 })
126-
127- t .Run ("Stats" , func (t * testing.T ) {
128- cmd := exec .Command (cliPath , "stats" )
129- cmd .Env = append (os .Environ (), "CIMIS_APP_KEY=" + appKey )
130- cmd .Dir = tmpDir
131-
132- output , err := cmd .CombinedOutput ()
133- if err != nil {
134- t .Fatalf ("Stats failed: %v\n Output: %s" , err , output )
135- }
136-
137- outputStr := string (output )
138- if ! strings .Contains (outputStr , "Statistics" ) {
139- t .Errorf ("Expected 'Statistics' in output, got: %s" , outputStr )
140- }
141-
142- t .Logf ("Stats output: %s" , outputStr )
143- })
144-
145- t .Run ("Verify" , func (t * testing.T ) {
146- cmd := exec .Command (cliPath , "verify" )
147- cmd .Env = append (os .Environ (), "CIMIS_APP_KEY=" + appKey )
148- cmd .Dir = tmpDir
149-
150- output , err := cmd .CombinedOutput ()
151- if err != nil {
152- t .Fatalf ("Verify failed: %v\n Output: %s" , err , output )
153- }
154-
155- outputStr := string (output )
156- if ! strings .Contains (outputStr , "OK" ) && ! strings .Contains (outputStr , "complete" ) {
157- t .Errorf ("Expected verification result in output, got: %s" , outputStr )
158- }
159-
160- t .Logf ("Verify output: %s" , outputStr )
161- })
162183}
163184
164185// TestCompressionBenchmarks runs benchmarks and validates performance
0 commit comments