mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 00:49:03 +00:00
49 lines
1 KiB
Go
49 lines
1 KiB
Go
|
|
package capabilities
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"net/http"
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
||
|
|
"github.com/stretchr/testify/require"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestCapabilitiesExist(t *testing.T) {
|
||
|
|
cases := []struct {
|
||
|
|
name string
|
||
|
|
in string
|
||
|
|
out fleet.CapabilityMap
|
||
|
|
}{
|
||
|
|
{"empty", "", fleet.CapabilityMap{}},
|
||
|
|
{"one", "test", fleet.CapabilityMap{fleet.Capability("test"): struct{}{}}},
|
||
|
|
{
|
||
|
|
"many",
|
||
|
|
"test,foo,bar",
|
||
|
|
fleet.CapabilityMap{
|
||
|
|
fleet.Capability("test"): struct{}{},
|
||
|
|
fleet.Capability("foo"): struct{}{},
|
||
|
|
fleet.Capability("bar"): struct{}{},
|
||
|
|
},
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
for _, tt := range cases {
|
||
|
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
|
r := http.Request{
|
||
|
|
Header: http.Header{fleet.CapabilitiesHeader: []string{tt.in}},
|
||
|
|
}
|
||
|
|
ctx := NewContext(context.Background(), &r)
|
||
|
|
mp, ok := FromContext(ctx)
|
||
|
|
require.True(t, ok)
|
||
|
|
require.Equal(t, tt.out, mp)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestCapabilitiesNotExist(t *testing.T) {
|
||
|
|
mp, ok := FromContext(context.Background())
|
||
|
|
require.False(t, ok)
|
||
|
|
require.Nil(t, mp)
|
||
|
|
}
|