|
| 1 | +package monitor |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | +) |
| 6 | + |
| 7 | +func TestGetReadOnlyMonitorCommands_ContainsMetricsCommands(t *testing.T) { |
| 8 | + commands := GetReadOnlyMonitorCommands() |
| 9 | + |
| 10 | + // Verify we have the expected number of commands |
| 11 | + expectedCommands := 3 |
| 12 | + if len(commands) != expectedCommands { |
| 13 | + t.Errorf("Expected %d read-only commands, got %d", expectedCommands, len(commands)) |
| 14 | + } |
| 15 | + |
| 16 | + // Check that specific metric commands are included |
| 17 | + foundMetricsList := false |
| 18 | + foundMetricsDefinitions := false |
| 19 | + foundMetricsNamespaces := false |
| 20 | + |
| 21 | + for _, cmd := range commands { |
| 22 | + switch cmd.Name { |
| 23 | + case "az monitor metrics list": |
| 24 | + foundMetricsList = true |
| 25 | + if cmd.Description == "" { |
| 26 | + t.Error("Expected metrics list command to have a description") |
| 27 | + } |
| 28 | + if cmd.ArgsExample == "" { |
| 29 | + t.Error("Expected metrics list command to have an args example") |
| 30 | + } |
| 31 | + if cmd.Category != "metrics" { |
| 32 | + t.Errorf("Expected metrics list command to have category 'metrics', got '%s'", cmd.Category) |
| 33 | + } |
| 34 | + case "az monitor metrics list-definitions": |
| 35 | + foundMetricsDefinitions = true |
| 36 | + if cmd.Description == "" { |
| 37 | + t.Error("Expected metrics list-definitions command to have a description") |
| 38 | + } |
| 39 | + if cmd.ArgsExample == "" { |
| 40 | + t.Error("Expected metrics list-definitions command to have an args example") |
| 41 | + } |
| 42 | + if cmd.Category != "metrics" { |
| 43 | + t.Errorf("Expected metrics list-definitions command to have category 'metrics', got '%s'", cmd.Category) |
| 44 | + } |
| 45 | + case "az monitor metrics list-namespaces": |
| 46 | + foundMetricsNamespaces = true |
| 47 | + if cmd.Description == "" { |
| 48 | + t.Error("Expected metrics list-namespaces command to have a description") |
| 49 | + } |
| 50 | + if cmd.ArgsExample == "" { |
| 51 | + t.Error("Expected metrics list-namespaces command to have an args example") |
| 52 | + } |
| 53 | + if cmd.Category != "metrics" { |
| 54 | + t.Errorf("Expected metrics list-namespaces command to have category 'metrics', got '%s'", cmd.Category) |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + if !foundMetricsList { |
| 60 | + t.Error("Expected to find 'az monitor metrics list' command in read-only commands") |
| 61 | + } |
| 62 | + |
| 63 | + if !foundMetricsDefinitions { |
| 64 | + t.Error("Expected to find 'az monitor metrics list-definitions' command in read-only commands") |
| 65 | + } |
| 66 | + |
| 67 | + if !foundMetricsNamespaces { |
| 68 | + t.Error("Expected to find 'az monitor metrics list-namespaces' command in read-only commands") |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +func TestRegisterMonitorCommand_MetricsCommands(t *testing.T) { |
| 73 | + // Test that metrics list command can be registered |
| 74 | + listCmd := MonitorCommand{ |
| 75 | + Name: "az monitor metrics list", |
| 76 | + Description: "List the metric values for a resource", |
| 77 | + ArgsExample: "--resource /subscriptions/{subscription}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines/{vmName} --metric \"Percentage CPU\"", |
| 78 | + Category: "metrics", |
| 79 | + } |
| 80 | + |
| 81 | + tool := RegisterMonitorCommand(listCmd) |
| 82 | + |
| 83 | + if tool.Name != "az_monitor_metrics_list" { |
| 84 | + t.Errorf("Expected tool name 'az_monitor_metrics_list', got '%s'", tool.Name) |
| 85 | + } |
| 86 | + |
| 87 | + if tool.Description == "" { |
| 88 | + t.Error("Expected tool description to be set") |
| 89 | + } |
| 90 | + |
| 91 | + expectedDescription := "Run az monitor metrics list command: List the metric values for a resource.\nExample: `--resource /subscriptions/{subscription}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines/{vmName} --metric \"Percentage CPU\"`" |
| 92 | + if tool.Description != expectedDescription { |
| 93 | + t.Errorf("Expected tool description to contain example, got: %s", tool.Description) |
| 94 | + } |
| 95 | + |
| 96 | + // Test that metrics list-definitions command can be registered |
| 97 | + definitionsCmd := MonitorCommand{ |
| 98 | + Name: "az monitor metrics list-definitions", |
| 99 | + Description: "List the metric definitions for a resource", |
| 100 | + ArgsExample: "--resource /subscriptions/{subscription}/resourceGroups/{resourceGroup}/providers/Microsoft.ContainerService/managedClusters/{clusterName}", |
| 101 | + Category: "metrics", |
| 102 | + } |
| 103 | + |
| 104 | + tool2 := RegisterMonitorCommand(definitionsCmd) |
| 105 | + |
| 106 | + if tool2.Name != "az_monitor_metrics_list-definitions" { |
| 107 | + t.Errorf("Expected tool name 'az_monitor_metrics_list-definitions', got '%s'", tool2.Name) |
| 108 | + } |
| 109 | + |
| 110 | + if tool2.Description == "" { |
| 111 | + t.Error("Expected tool description to be set") |
| 112 | + } |
| 113 | +} |
| 114 | + |
| 115 | +func TestRegisterMonitorCommand_WithoutArgsExample(t *testing.T) { |
| 116 | + // Test command registration without args example |
| 117 | + cmd := MonitorCommand{ |
| 118 | + Name: "az monitor test", |
| 119 | + Description: "Test command", |
| 120 | + ArgsExample: "", |
| 121 | + Category: "test", |
| 122 | + } |
| 123 | + |
| 124 | + tool := RegisterMonitorCommand(cmd) |
| 125 | + |
| 126 | + if tool.Name != "az_monitor_test" { |
| 127 | + t.Errorf("Expected tool name 'az_monitor_test', got '%s'", tool.Name) |
| 128 | + } |
| 129 | + |
| 130 | + expectedDescription := "Run az monitor test command: Test command." |
| 131 | + if tool.Description != expectedDescription { |
| 132 | + t.Errorf("Expected tool description '%s', got '%s'", expectedDescription, tool.Description) |
| 133 | + } |
| 134 | +} |
| 135 | + |
| 136 | +func TestGetReadWriteMonitorCommands_IsEmpty(t *testing.T) { |
| 137 | + commands := GetReadWriteMonitorCommands() |
| 138 | + |
| 139 | + if len(commands) != 0 { |
| 140 | + t.Errorf("Expected read-write commands to be empty, got %d commands", len(commands)) |
| 141 | + } |
| 142 | +} |
| 143 | + |
| 144 | +func TestGetAdminMonitorCommands_IsEmpty(t *testing.T) { |
| 145 | + commands := GetAdminMonitorCommands() |
| 146 | + |
| 147 | + if len(commands) != 0 { |
| 148 | + t.Errorf("Expected admin commands to be empty, got %d commands", len(commands)) |
| 149 | + } |
| 150 | +} |
| 151 | + |
| 152 | +func TestMonitorCommand_StructFields(t *testing.T) { |
| 153 | + cmd := MonitorCommand{ |
| 154 | + Name: "test name", |
| 155 | + Description: "test description", |
| 156 | + ArgsExample: "test args", |
| 157 | + Category: "test category", |
| 158 | + } |
| 159 | + |
| 160 | + if cmd.Name != "test name" { |
| 161 | + t.Errorf("Expected Name to be 'test name', got '%s'", cmd.Name) |
| 162 | + } |
| 163 | + |
| 164 | + if cmd.Description != "test description" { |
| 165 | + t.Errorf("Expected Description to be 'test description', got '%s'", cmd.Description) |
| 166 | + } |
| 167 | + |
| 168 | + if cmd.ArgsExample != "test args" { |
| 169 | + t.Errorf("Expected ArgsExample to be 'test args', got '%s'", cmd.ArgsExample) |
| 170 | + } |
| 171 | + |
| 172 | + if cmd.Category != "test category" { |
| 173 | + t.Errorf("Expected Category to be 'test category', got '%s'", cmd.Category) |
| 174 | + } |
| 175 | +} |
0 commit comments