|
1 | | -//go:build integration |
2 | | - |
3 | | -package integration |
4 | | - |
5 | | -import ( |
6 | | - "gotest.tools/assert" |
7 | | - "os" |
8 | | - "strings" |
9 | | - "testing" |
10 | | -) |
11 | | - |
12 | | -var filePath = "data/config.yaml" |
13 | | - |
14 | | -func TestIntegration_LoadConfiguration_EnvVarConfigFilePath(t *testing.T) { |
15 | | - os.Setenv("CX_CONFIG_FILE_PATH", filePath) |
16 | | - defer os.Unsetenv("CX_CONFIG_FILE_PATH") |
17 | | - |
18 | | - cmd, buffer := createRedirectedTestCommand(t) |
19 | | - |
20 | | - err := execute(cmd, "configure", "show") |
21 | | - assert.NilError(t, err) |
22 | | - |
23 | | - output := buffer.String() |
24 | | - if !strings.Contains(output, "cx_base_uri: https://example.com") { |
25 | | - t.Errorf("expected output to contain 'cx_base_uri: https://example.com', but it did not") |
26 | | - } |
27 | | -} |
28 | | - |
29 | | -func TestIntegration_LoadConfiguration_FileNotFound(t *testing.T) { |
30 | | - // Set an invalid file path |
31 | | - os.Setenv("CX_CONFIG_FILE_PATH", "data/nonexistent_config.yaml") |
32 | | - defer os.Unsetenv("CX_CONFIG_FILE_PATH") |
33 | | - |
34 | | - cmd, buffer := createRedirectedTestCommand(t) |
35 | | - |
36 | | - // Execute the command |
37 | | - err := execute(cmd, "configure", "show") |
38 | | - |
39 | | - // Verify that an error occurred |
40 | | - assert.ErrorContains(t, err, "The specified file does not exist") |
41 | | - |
42 | | - // Verify the output contains the expected error message |
43 | | - output := buffer.String() |
44 | | - if !strings.Contains(output, "The specified file does not exist") { |
45 | | - t.Errorf("expected output to contain 'The specified file does not exist', but it did not") |
46 | | - } |
47 | | -} |
48 | | - |
49 | | -func TestIntegration_LoadConfiguration_FileWithoutPermission_UsingConfigFile(t *testing.T) { |
50 | | - |
51 | | - // Set the file to have no permissions |
52 | | - if err := os.Chmod(filePath, 0000); err != nil { |
53 | | - t.Fatalf("failed to set file permissions: %v", err) |
54 | | - } |
55 | | - defer os.Chmod(filePath, 0644) // Restore permissions for cleanup |
56 | | - |
57 | | - // Set the environment variable to point to the restricted file |
58 | | - os.Setenv("CX_CONFIG_FILE_PATH", filePath) |
59 | | - defer os.Unsetenv("CX_CONFIG_FILE_PATH") |
60 | | - |
61 | | - cmd, buffer := createRedirectedTestCommand(t) |
62 | | - |
63 | | - // Execute the command |
64 | | - err := execute(cmd, "configure", "show") |
65 | | - |
66 | | - // Verify that an error occurred |
67 | | - assert.ErrorContains(t, err, "Access to the specified file is restricted") |
68 | | - |
69 | | - // Verify the output contains the expected error message |
70 | | - output := buffer.String() |
71 | | - if !strings.Contains(output, "Access to the specified file is restricted") { |
72 | | - t.Errorf("expected output to contain 'Access to the specified file is restricted', but it did not") |
73 | | - } |
74 | | -} |
75 | | - |
| 1 | +////go:build integration |
| 2 | +// |
| 3 | +//package integration |
| 4 | +// |
| 5 | +//import ( |
| 6 | +// "gotest.tools/assert" |
| 7 | +// "os" |
| 8 | +// "strings" |
| 9 | +// "testing" |
| 10 | +//) |
| 11 | +// |
| 12 | +//var filePath = "data/config.yaml" |
| 13 | +// |
| 14 | +//func TestIntegration_LoadConfiguration_EnvVarConfigFilePath(t *testing.T) { |
| 15 | +// os.Setenv("CX_CONFIG_FILE_PATH", filePath) |
| 16 | +// defer os.Unsetenv("CX_CONFIG_FILE_PATH") |
| 17 | +// |
| 18 | +// cmd, buffer := createRedirectedTestCommand(t) |
| 19 | +// |
| 20 | +// err := execute(cmd, "configure", "show") |
| 21 | +// assert.NilError(t, err) |
| 22 | +// |
| 23 | +// output := buffer.String() |
| 24 | +// if !strings.Contains(output, "cx_base_uri: https://example.com") { |
| 25 | +// t.Errorf("expected output to contain 'cx_base_uri: https://example.com', but it did not") |
| 26 | +// } |
| 27 | +//} |
| 28 | +// |
| 29 | +//func TestIntegration_LoadConfiguration_FileNotFound(t *testing.T) { |
| 30 | +// // Set an invalid file path |
| 31 | +// os.Setenv("CX_CONFIG_FILE_PATH", "data/nonexistent_config.yaml") |
| 32 | +// defer os.Unsetenv("CX_CONFIG_FILE_PATH") |
| 33 | +// |
| 34 | +// cmd, buffer := createRedirectedTestCommand(t) |
| 35 | +// |
| 36 | +// // Execute the command |
| 37 | +// err := execute(cmd, "configure", "show") |
| 38 | +// |
| 39 | +// // Verify that an error occurred |
| 40 | +// assert.ErrorContains(t, err, "The specified file does not exist") |
| 41 | +// |
| 42 | +// // Verify the output contains the expected error message |
| 43 | +// output := buffer.String() |
| 44 | +// if !strings.Contains(output, "The specified file does not exist") { |
| 45 | +// t.Errorf("expected output to contain 'The specified file does not exist', but it did not") |
| 46 | +// } |
| 47 | +//} |
| 48 | +// |
| 49 | +//func TestIntegration_LoadConfiguration_FileWithoutPermission_UsingConfigFile(t *testing.T) { |
| 50 | +// |
| 51 | +// // Set the file to have no permissions |
| 52 | +// if err := os.Chmod(filePath, 0000); err != nil { |
| 53 | +// t.Fatalf("failed to set file permissions: %v", err) |
| 54 | +// } |
| 55 | +// defer os.Chmod(filePath, 0644) // Restore permissions for cleanup |
| 56 | +// |
| 57 | +// // Set the environment variable to point to the restricted file |
| 58 | +// os.Setenv("CX_CONFIG_FILE_PATH", filePath) |
| 59 | +// defer os.Unsetenv("CX_CONFIG_FILE_PATH") |
| 60 | +// |
| 61 | +// cmd, buffer := createRedirectedTestCommand(t) |
| 62 | +// |
| 63 | +// // Execute the command |
| 64 | +// err := execute(cmd, "configure", "show") |
| 65 | +// |
| 66 | +// // Verify that an error occurred |
| 67 | +// assert.ErrorContains(t, err, "Access to the specified file is restricted") |
| 68 | +// |
| 69 | +// // Verify the output contains the expected error message |
| 70 | +// output := buffer.String() |
| 71 | +// if !strings.Contains(output, "Access to the specified file is restricted") { |
| 72 | +// t.Errorf("expected output to contain 'Access to the specified file is restricted', but it did not") |
| 73 | +// } |
| 74 | +//} |
| 75 | +// |
76 | 76 | // |
77 | 77 | //func TestIntegration_SetConfigProperty_EnvVarConfigFilePath(t *testing.T) { |
78 | 78 | // // Set environment variable |
|
0 commit comments