Files
netbird/client/internal/pqkem/env_test.go
T
riccardom fb6e955f00 [client] pqkem: cover the env flags, signal port, offer marker and status flag
These branches decide whether ML-KEM runs, which port a peer is reached
on, and what the status reports, and none of them had a test.
2026-10-20 17:53:03 +02:00

59 lines
1.1 KiB
Go

package pqkem
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestEnvFlags(t *testing.T) {
cases := []struct {
value string
want bool
}{
{"", false},
{"on", true},
{"ON", true},
{" on ", true},
{"off", false},
{"Off", false},
{"true", true},
{"TRUE", true},
{"1", true},
{"t", true},
{"false", false},
{"0", false},
{" 1 ", true},
{"yes", false},
{"garbage", false},
}
flags := []struct {
env string
get func() bool
}{
{EnvEnabled, Enabled},
{EnvStrict, Strict},
}
for _, f := range flags {
for _, c := range cases {
t.Run(f.env+"="+c.value, func(t *testing.T) {
t.Setenv(f.env, c.value)
assert.Equal(t, c.want, f.get(), "%s=%q", f.env, c.value)
})
}
}
}
func TestEnvFlagsUnset(t *testing.T) {
for _, env := range []string{EnvEnabled, EnvStrict} {
t.Setenv(env, "")
require.NoError(t, os.Unsetenv(env))
}
assert.False(t, Enabled(), "an unset %s must leave ML-KEM disabled", EnvEnabled)
assert.False(t, Strict(), "an unset %s must leave strict mode off", EnvStrict)
}