Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
96 lines
1.5 KiB
Go
96 lines
1.5 KiB
Go
package dal
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestSensitivityLevelIncluded(t *testing.T) {
|
|
t.Run("does not include; empty", func(t *testing.T) {
|
|
ll := sensitivityLevelIndex{}
|
|
|
|
require.False(t, ll.includes(1))
|
|
})
|
|
|
|
t.Run("does not include; not in there", func(t *testing.T) {
|
|
ll := SensitivityLevelIndex(SensitivityLevel{
|
|
Handle: "a",
|
|
ID: 0,
|
|
Level: 1,
|
|
})
|
|
|
|
require.False(t, ll.includes(1))
|
|
})
|
|
|
|
t.Run("includes", func(t *testing.T) {
|
|
ll := SensitivityLevelIndex(SensitivityLevel{
|
|
Handle: "a",
|
|
ID: 1,
|
|
Level: 1,
|
|
})
|
|
|
|
require.True(t, ll.includes(1))
|
|
})
|
|
}
|
|
|
|
func TestSensitivityLevelSubset(t *testing.T) {
|
|
commonLevels := SensitivityLevelSet{{
|
|
ID: 1,
|
|
Handle: "a",
|
|
Level: 1,
|
|
}, {
|
|
ID: 2,
|
|
Handle: "b",
|
|
Level: 2,
|
|
}, {
|
|
ID: 3,
|
|
Handle: "c",
|
|
Level: 3,
|
|
}}
|
|
|
|
cases := []struct {
|
|
name string
|
|
a uint64
|
|
b uint64
|
|
out bool
|
|
}{{
|
|
name: "lower is zero",
|
|
a: 0,
|
|
b: 1,
|
|
out: true,
|
|
}, {
|
|
name: "both zero",
|
|
a: 0,
|
|
b: 0,
|
|
out: true,
|
|
}, {
|
|
name: "upper zero, lower not",
|
|
a: 1,
|
|
b: 0,
|
|
out: false,
|
|
}, {
|
|
name: "lower less",
|
|
a: 1,
|
|
b: 2,
|
|
out: true,
|
|
}, {
|
|
name: "equal",
|
|
a: 2,
|
|
b: 2,
|
|
out: true,
|
|
}, {
|
|
name: "lower higher",
|
|
a: 3,
|
|
b: 2,
|
|
out: false,
|
|
}}
|
|
|
|
ix := SensitivityLevelIndex(commonLevels...)
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
require.Equal(t, c.out, ix.isSubset(c.a, c.b))
|
|
})
|
|
}
|
|
}
|