fleet/server/service/orbit_client_test.go
Victor Lyuboslavsky eb155d17d3
Reducing the number of fleetd calls to fleet/orbit/config endpoint. (#15545)
Reducing the number of fleetd calls to fleet/orbit/config endpoint by
caching the config for 3 seconds.
#15541

# Checklist for submitter
- [x] Changes file added for user-visible changes in `changes/` or
`orbit/changes/`.
- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality
  - For Orbit and Fleet Desktop changes:
- [x] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.
- [x] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).
2023-12-11 07:04:24 -06:00

34 lines
816 B
Go

package service
import (
"errors"
"github.com/fleetdm/fleet/v4/server/fleet"
"github.com/stretchr/testify/require"
"testing"
"time"
)
func TestGetConfig(t *testing.T) {
t.Run(
"config cache", func(t *testing.T) {
oc := OrbitClient{}
oc.configCache.config = &fleet.OrbitConfig{}
oc.configCache.lastUpdated = time.Now().Add(1 * time.Second)
config, err := oc.GetConfig()
require.NoError(t, err)
require.Equal(t, oc.configCache.config, config)
},
)
t.Run(
"config cache error", func(t *testing.T) {
oc := OrbitClient{}
oc.configCache.config = nil
oc.configCache.err = errors.New("test error")
oc.configCache.lastUpdated = time.Now().Add(1 * time.Second)
config, err := oc.GetConfig()
require.Error(t, err)
require.Equal(t, oc.configCache.config, config)
},
)
}