TestWireFieldNames verifies that every field of every wire type has a CBOR field name matching wireFieldNames, so that the same Go field name always gets the same short name (and no short name ever means two different things).
(t *testing.T)
| 41 | // field name always gets the same short name (and no short name ever |
| 42 | // means two different things). |
| 43 | func TestWireFieldNames(t *testing.T) { |
| 44 | longToShort := make(map[string]string) |
| 45 | for short, long := range wireFieldNames { |
| 46 | if prev, ok := longToShort[long]; ok { |
| 47 | t.Fatalf("wireFieldNames maps both %q and %q to %q", prev, short, long) |
| 48 | } |
| 49 | longToShort[long] = short |
| 50 | } |
| 51 | |
| 52 | seen := make(map[string]bool) |
| 53 | for _, typ := range []reflect.Type{ |
| 54 | reflect.TypeFor[wireConnInfo](), |
| 55 | reflect.TypeFor[wireRegion](), |
| 56 | reflect.TypeFor[wireNode](), |
| 57 | } { |
| 58 | for i := range typ.NumField() { |
| 59 | f := typ.Field(i) |
| 60 | short, _, _ := strings.Cut(f.Tag.Get("cbor"), ",") |
| 61 | if short == "" { |
| 62 | t.Errorf("%v.%s: missing cbor field name", typ, f.Name) |
| 63 | continue |
| 64 | } |
| 65 | if want, ok := longToShort[f.Name]; !ok { |
| 66 | t.Errorf("%v.%s: field not in wireFieldNames", typ, f.Name) |
| 67 | } else if short != want { |
| 68 | t.Errorf("%v.%s: cbor field name %q; want %q", typ, f.Name, short, want) |
| 69 | } |
| 70 | seen[short] = true |
| 71 | } |
| 72 | } |
| 73 | for short, long := range wireFieldNames { |
| 74 | if !seen[short] { |
| 75 | t.Errorf("wireFieldNames entry %q => %q matches no wire type field", short, long) |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | // TestWireRegionRoundTrip tests the mapping between the upstream |
| 81 | // tailcfg DERP types (as fetched from the control plane's DERP map) |