github.com/cilium/cilium@v1.16.2/pkg/health/client/modules_test.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package client_test 5 6 import ( 7 "bytes" 8 "strings" 9 "testing" 10 11 "github.com/stretchr/testify/assert" 12 13 "github.com/cilium/cilium/pkg/health/client" 14 "github.com/cilium/cilium/pkg/hive/health/types" 15 ) 16 17 func TestGetAndFormatModulesHealth(t *testing.T) { 18 uu := map[string]struct { 19 ss []types.Status 20 e string 21 v bool 22 }{ 23 "happy": { 24 e: "Modules Health:\tStopped(0) Degraded(2) OK(2)", 25 }, 26 "happy-verbose": { 27 e: `Modules Health: 28 agent 29 ├── a 30 │ └── b 31 │ └── c 32 │ ├── dork [DEGRADED] doh (n/a, x0) 33 │ └── fred 34 │ ├── [reporter] [OK] yo (n/a, x0) 35 │ └── blee [DEGRADED] bozo (n/a, x0) 36 └── m1 37 └── foo [OK] status nominal (n/a, x0)`, 38 v: true, 39 }, 40 } 41 42 for k := range uu { 43 u := uu[k] 44 t.Run(k, func(t *testing.T) { 45 w := bytes.NewBufferString("") 46 client.GetAndFormatModulesHealth(w, getHealth(), u.v) 47 assert.Equal(t, u.e, strings.TrimSpace(w.String())) 48 }) 49 } 50 } 51 52 // Helpers 53 54 func ident(mid []string, cid ...string) types.Identifier { 55 return types.Identifier{ 56 Module: mid, 57 Component: cid, 58 } 59 } 60 61 func getHealth() []types.Status { 62 return []types.Status{ 63 { 64 ID: ident([]string{"agent", "m1"}, "foo"), 65 Level: types.LevelOK, 66 Message: "status nominal", 67 }, 68 { 69 ID: ident([]string{"agent", "a.b.c"}, "fred"), 70 Level: types.LevelOK, 71 Message: "yo", 72 }, 73 { 74 ID: ident([]string{"agent", "a.b.c"}, "fred", "blee"), 75 Level: types.LevelDegraded, 76 Message: "bozo", 77 }, 78 { 79 ID: ident([]string{"agent", "a.b.c"}, "dork"), 80 Level: types.LevelDegraded, 81 Message: "doh", 82 }, 83 } 84 }