(t *testing.T)
| 25 | ) |
| 26 | |
| 27 | func TestGetTemplateData(t *testing.T) { |
| 28 | c := conf.Configuration{ |
| 29 | Checks: map[string]conf.Severity{ |
| 30 | "readinessProbeMissing": conf.SeverityDanger, |
| 31 | "livenessProbeMissing": conf.SeverityWarning, |
| 32 | }, |
| 33 | } |
| 34 | |
| 35 | k8s, dynamicClient := test.SetupTestAPI(test.GetMockControllers("test")...) |
| 36 | resources, err := kube.CreateResourceProviderFromAPI(context.Background(), k8s, "test", dynamicClient, c) |
| 37 | assert.Equal(t, err, nil, "error should be nil") |
| 38 | assert.Equal(t, 5, len(resources.Resources)) |
| 39 | |
| 40 | sum := CountSummary{ |
| 41 | Successes: uint(0), |
| 42 | Warnings: uint(3), |
| 43 | Dangers: uint(3), |
| 44 | } |
| 45 | score := uint(0) |
| 46 | |
| 47 | var actualAudit AuditData |
| 48 | actualAudit, err = RunAudit(context.Background(), c, resources) |
| 49 | assert.Equal(t, err, nil, "error should be nil") |
| 50 | assert.Equal(t, score, actualAudit.Score, "") |
| 51 | assert.EqualValues(t, sum, actualAudit.GetSummary()) |
| 52 | assert.Equal(t, actualAudit.SourceType, "Cluster", "should be from a cluster") |
| 53 | assert.Equal(t, actualAudit.SourceName, "test", "should be from a cluster") |
| 54 | |
| 55 | expectedResults := []struct { |
| 56 | kind string |
| 57 | results int |
| 58 | }{ |
| 59 | {kind: "StatefulSet", results: 2}, |
| 60 | {kind: "DaemonSet", results: 2}, |
| 61 | {kind: "Deployment", results: 2}, |
| 62 | {kind: "Job", results: 0}, |
| 63 | {kind: "CronJob", results: 0}, |
| 64 | } |
| 65 | |
| 66 | assert.Equal(t, len(expectedResults), len(actualAudit.Results)) |
| 67 | for _, result := range actualAudit.Results { |
| 68 | found := false |
| 69 | for _, expected := range expectedResults { |
| 70 | if expected.kind != result.Kind { |
| 71 | continue |
| 72 | } |
| 73 | found = true |
| 74 | if assert.Equal(t, 1, len(result.PodResult.ContainerResults), "bad container results for "+result.Kind) { |
| 75 | assert.Equal(t, expected.results, len(result.PodResult.ContainerResults[0].Results)) |
| 76 | } |
| 77 | } |
| 78 | assert.Equal(t, found, true) |
| 79 | } |
| 80 | } |
nothing calls this directly
no test coverage detected