(t *testing.T)
| 61 | } |
| 62 | |
| 63 | func TestControllerLevelChecks(t *testing.T) { |
| 64 | testResources := func(res *kube.ResourceProvider) { |
| 65 | c := conf.Configuration{ |
| 66 | Checks: map[string]conf.Severity{ |
| 67 | "deploymentMissingReplicas": conf.SeverityDanger, |
| 68 | }, |
| 69 | } |
| 70 | expectedResult := ResultMessage{ |
| 71 | ID: "deploymentMissingReplicas", |
| 72 | Severity: "danger", |
| 73 | Category: "Reliability", |
| 74 | } |
| 75 | for _, controller := range res.Resources["Deployment"] { |
| 76 | actualResult, err := applyControllerSchemaChecks(context.Background(), &c, nil, controller) |
| 77 | if err != nil { |
| 78 | panic(err) |
| 79 | } |
| 80 | if controller.ObjectMeta.GetName() == "test-deployment-2" { |
| 81 | expectedResult.Success = true |
| 82 | expectedResult.Message = "Multiple replicas are scheduled" |
| 83 | } else if controller.ObjectMeta.GetName() == "test-deployment" { |
| 84 | expectedResult.Success = false |
| 85 | expectedResult.Message = "Only one replica is scheduled" |
| 86 | } |
| 87 | expectedResults := ResultSet{ |
| 88 | "deploymentMissingReplicas": expectedResult, |
| 89 | } |
| 90 | |
| 91 | assert.Equal(t, "Deployment", actualResult.Kind) |
| 92 | assert.Equal(t, 1, len(actualResult.Results), "should be equal") |
| 93 | assert.EqualValues(t, expectedResults, actualResult.Results, controller.ObjectMeta.GetName()) |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | res, err := kube.CreateResourceProviderFromPath("../kube/test_files/test_1") |
| 98 | assert.Equal(t, nil, err, "Error should be nil") |
| 99 | assert.Equal(t, 10, res.Resources.GetLength()) |
| 100 | testResources(res) |
| 101 | |
| 102 | replicaSpec := map[string]any{"replicas": 2} |
| 103 | b, err := json.Marshal(replicaSpec) |
| 104 | assert.NoError(t, err) |
| 105 | err = json.Unmarshal(b, &replicaSpec) |
| 106 | |
| 107 | d1, p1 := test.MockDeploy("test", "test-deployment") |
| 108 | d2, p2 := test.MockDeploy("test", "test-deployment-2") |
| 109 | two := int32(2) |
| 110 | d2.Spec.Replicas = &two |
| 111 | k8s, dynamicClient := test.SetupTestAPI(&d1, &p1, &d2, &p2) |
| 112 | res, err = kube.CreateResourceProviderFromAPI(context.Background(), k8s, "test", dynamicClient, conf.Configuration{}) |
| 113 | assert.Equal(t, err, nil, "error should be nil") |
| 114 | assert.Equal(t, 2, res.Resources.GetLength(), "Should have two controllers") |
| 115 | testResources(res) |
| 116 | } |
| 117 | |
| 118 | func TestSkipHealthChecks(t *testing.T) { |
| 119 | c := conf.Configuration{ |
nothing calls this directly
no test coverage detected