mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
4f4185372d
This is just to pass down the context to the datastore layer, it doesn't use it just yet - this will be in a follow-up PR.
56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
"github.com/fleetdm/fleet/v4/server/mock"
|
|
"github.com/fleetdm/fleet/v4/server/ptr"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestAgentOptionsForHost(t *testing.T) {
|
|
ds := new(mock.Store)
|
|
svc := newTestService(ds, nil, nil)
|
|
|
|
teamID := uint(1)
|
|
ds.TeamFunc = func(ctx context.Context, tid uint) (*fleet.Team, error) {
|
|
assert.Equal(t, teamID, tid)
|
|
opt := json.RawMessage(`{"config":{"foo":"bar"},"overrides":{"platforms":{"darwin":{"foo":"override"}}}}`)
|
|
return &fleet.Team{AgentOptions: &opt}, nil
|
|
}
|
|
ds.AppConfigFunc = func(ctx context.Context) (*fleet.AppConfig, error) {
|
|
return &fleet.AppConfig{
|
|
AgentOptions: ptr.RawMessage(json.RawMessage(`{"config":{"baz":"bar"},"overrides":{"platforms":{"darwin":{"foo":"override2"}}}}`)),
|
|
}, nil
|
|
}
|
|
|
|
host := &fleet.Host{
|
|
TeamID: &teamID,
|
|
Platform: "darwin",
|
|
}
|
|
|
|
opt, err := svc.AgentOptionsForHost(context.Background(), host)
|
|
require.NoError(t, err)
|
|
assert.JSONEq(t, `{"foo":"override"}`, string(opt))
|
|
|
|
host.Platform = "windows"
|
|
opt, err = svc.AgentOptionsForHost(context.Background(), host)
|
|
require.NoError(t, err)
|
|
assert.JSONEq(t, `{"foo":"bar"}`, string(opt))
|
|
|
|
// Should take gobal option with no team
|
|
host.TeamID = nil
|
|
opt, err = svc.AgentOptionsForHost(context.Background(), host)
|
|
require.NoError(t, err)
|
|
assert.JSONEq(t, `{"baz":"bar"}`, string(opt))
|
|
|
|
host.Platform = "darwin"
|
|
opt, err = svc.AgentOptionsForHost(context.Background(), host)
|
|
require.NoError(t, err)
|
|
assert.JSONEq(t, `{"foo":"override2"}`, string(opt))
|
|
}
|