|
6 | 6 | "k8s.io/apimachinery/pkg/runtime/schema" |
7 | 7 | "k8s.io/client-go/dynamic" |
8 | 8 | "sigs.k8s.io/yaml" |
| 9 | + "strings" |
9 | 10 | "testing" |
10 | 11 | ) |
11 | 12 |
|
@@ -204,7 +205,31 @@ func TestResourcesCreateOrUpdate(t *testing.T) { |
204 | 205 | return |
205 | 206 | } |
206 | 207 | if resourcesCreateOrUpdateCm1.IsError { |
207 | | - t.Fatalf("call tool failed") |
| 208 | + t.Errorf("call tool failed") |
| 209 | + return |
| 210 | + } |
| 211 | + }) |
| 212 | + var decodedCreateOrUpdateCm1 []unstructured.Unstructured |
| 213 | + err = yaml.Unmarshal([]byte(resourcesCreateOrUpdateCm1.Content[0].(map[string]interface{})["text"].(string)), &decodedCreateOrUpdateCm1) |
| 214 | + t.Run("resources_create_or_update with valid namespaced yaml resource returns yaml content", func(t *testing.T) { |
| 215 | + if err != nil { |
| 216 | + t.Errorf("invalid tool result content %v", err) |
| 217 | + return |
| 218 | + } |
| 219 | + if !strings.HasPrefix(resourcesCreateOrUpdateCm1.Content[0].(map[string]interface{})["text"].(string), "# The following resources (YAML) have been created or updated successfully") { |
| 220 | + t.Errorf("Excpected success message, got %v", resourcesCreateOrUpdateCm1.Content[0].(map[string]interface{})["text"].(string)) |
| 221 | + return |
| 222 | + } |
| 223 | + if len(decodedCreateOrUpdateCm1) != 1 { |
| 224 | + t.Errorf("invalid resource count, expected 1, got %v", len(decodedCreateOrUpdateCm1)) |
| 225 | + return |
| 226 | + } |
| 227 | + if decodedCreateOrUpdateCm1[0].GetName() != "a-cm-created-or-updated" { |
| 228 | + t.Errorf("invalid resource name, expected a-cm-created-or-updated, got %v", decodedCreateOrUpdateCm1[0].GetName()) |
| 229 | + return |
| 230 | + } |
| 231 | + if decodedCreateOrUpdateCm1[0].GetUID() == "" { |
| 232 | + t.Errorf("invalid uid, got %v", decodedCreateOrUpdateCm1[0].GetUID()) |
208 | 233 | return |
209 | 234 | } |
210 | 235 | }) |
|
0 commit comments