Files
story/internal/deviceactivation/state_test.go
T

32 lines
1.1 KiB
Go
Raw Normal View History

2026-09-06 17:04:11 +08:00
package deviceactivation
import "testing"
func TestCanTransition(t *testing.T) {
allowed := [][2]State{{Factory, Claimable}, {Claimable, Bound}, {Bound, Provisioning}, {Provisioning, Active}, {Active, Lost}, {Lost, Active}, {Active, Claimable}, {Active, Provisioning}, {Bound, Revoked}}
for _, edge := range allowed {
if !CanTransition(edge[0], edge[1]) {
t.Fatalf("expected %s -> %s to be allowed", edge[0], edge[1])
}
}
rejected := [][2]State{{Factory, Active}, {Claimable, Active}, {Active, Bound}, {Revoked, Claimable}, {Lost, Provisioning}}
for _, edge := range rejected {
if CanTransition(edge[0], edge[1]) {
t.Fatalf("expected %s -> %s to be rejected", edge[0], edge[1])
}
}
}
func TestAllowsDeviceAuthentication(t *testing.T) {
for _, state := range []string{"", "CLAIMABLE", "BOUND", "PROVISIONING", "ACTIVE"} {
if !AllowsDeviceAuthentication(state) {
t.Fatalf("expected %q to authenticate", state)
}
}
for _, state := range []string{"FACTORY", "LOST", "REVOKED", "invalid"} {
if AllowsDeviceAuthentication(state) {
t.Fatalf("expected %q to be blocked", state)
}
}
}