MCPcopy Create free account
hub / github.com/google/nftables / TestTarget

Function TestTarget

expr/target_test.go:13–56  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestTarget(t *testing.T) {
14 t.Parallel()
15 payload := xt.Unknown([]byte{0xb0, 0x1d, 0xca, 0xfe, 0x00})
16 tests := []struct {
17 name string
18 tgt Target
19 }{
20 {
21 name: "Unmarshal Target case",
22 tgt: Target{
23 Name: "foobar",
24 Rev: 1234567890,
25 Info: &payload,
26 },
27 },
28 }
29
30 for _, tt := range tests {
31 t.Run(tt.name, func(t *testing.T) {
32 ntgt := Target{}
33 data, err := tt.tgt.marshal(0 /* don't care in this test */)
34 if err != nil {
35 t.Fatalf("marshal error: %+v", err)
36
37 }
38 ad, err := netlink.NewAttributeDecoder(data)
39 if err != nil {
40 t.Fatalf("NewAttributeDecoder() error: %+v", err)
41 }
42 ad.ByteOrder = binary.BigEndian
43 for ad.Next() {
44 if ad.Type() == unix.NFTA_EXPR_DATA {
45 if err := ntgt.unmarshal(0 /* don't care in this test */, ad.Bytes()); err != nil {
46 t.Errorf("unmarshal error: %+v", err)
47 break
48 }
49 }
50 }
51 if !reflect.DeepEqual(tt.tgt, ntgt) {
52 t.Fatalf("original %+v and recovered %+v Target structs are different", tt.tgt, ntgt)
53 }
54 })
55 }
56}

Callers

nothing calls this directly

Calls 3

unmarshalMethod · 0.95
UnknownTypeAlias · 0.92
marshalMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…