| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package policy |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/stretchr/testify/assert" |
| 9 | "github.com/stretchr/testify/require" |
| 10 | ) |
| 11 | |
| 12 | func TestRunModeConstructors(t *testing.T) { |
| 13 | tests := map[string]struct { |
| 14 | makePolicy func() RunModePolicy |
| 15 | want RunModePolicy |
| 16 | }{ |
| 17 | "agent terminal": { |
| 18 | makePolicy: func() RunModePolicy { return Agent(true) }, |
| 19 | want: RunModePolicy{ |
| 20 | IsTerminal: true, |
| 21 | AutoEnableDiscovered: true, |
| 22 | UseFileStatusPersistence: false, |
| 23 | EnableServiceDiscovery: false, |
| 24 | EnableRuntimeCharts: false, |
| 25 | }, |
| 26 | }, |
| 27 | "agent daemon": { |
| 28 | makePolicy: func() RunModePolicy { return Agent(false) }, |
| 29 | want: RunModePolicy{ |
| 30 | IsTerminal: false, |
| 31 | AutoEnableDiscovered: false, |
| 32 | UseFileStatusPersistence: true, |
| 33 | EnableServiceDiscovery: true, |
| 34 | EnableRuntimeCharts: true, |
| 35 | }, |
| 36 | }, |
| 37 | "function cli": { |
| 38 | makePolicy: FunctionCLI, |
| 39 | want: RunModePolicy{ |
| 40 | IsTerminal: false, |
| 41 | AutoEnableDiscovered: true, |
| 42 | UseFileStatusPersistence: true, |
| 43 | EnableServiceDiscovery: false, |
| 44 | EnableRuntimeCharts: false, |
| 45 | }, |
| 46 | }, |
| 47 | } |
| 48 | |
| 49 | for name, test := range tests { |
| 50 | t.Run(name, func(t *testing.T) { |
| 51 | require.NotNil(t, test.makePolicy) |
| 52 | assert.Equal(t, test.want, test.makePolicy()) |
| 53 | }) |
| 54 | } |
| 55 | } |