package wire import ( "encoding/json" "reflect" "testing" ) // The ability keys, in the spec's order (ยง3); Base's internal/equipo // pins the same list. func TestAbilityKeysMatchSpec(t *testing.T) { want := []string{"web", "apps_read", "apps_write", "build", "go_live", "services", "services_add"} if !reflect.DeepEqual(Abilities, want) { t.Errorf("Abilities %v, want %v", Abilities, want) } for _, k := range want { if !KnownAbility(k) { t.Errorf("%s not known", k) } } if KnownAbility("future") || KnownAbility("") { t.Error("an unknown key is known") } } // Base's board keeps only the keys Equipo knows; a key Equipo doesn't // know is ignored, and a known key Base left out reads as missing. func TestAbilityBoardIgnoresUnknownKeys(t *testing.T) { var b AbilityBoard if err := json.Unmarshal([]byte(`{"revision":7,"admin":true,"ask":"Paul","abilities":{"web":true,"future":false,"build":false}}`), &b); err != nil { t.Fatal(err) } want := AbilityBoard{Revision: 7, Admin: true, Ask: "Paul", Abilities: map[string]bool{"web": true, "build": false}} if !reflect.DeepEqual(b, want) { t.Errorf("board %+v, want %+v", b, want) } if _, ok := b.Abilities["future"]; ok { t.Error("an unknown key was kept") } }