github.com/gopacket/gopacket@v1.1.0/afpacket/afpacket_test.go (about) 1 // Copyright 2012 Google, Inc. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style license 4 // that can be found in the LICENSE file in the root of the source 5 // tree. 6 7 //go:build linux 8 // +build linux 9 10 package afpacket 11 12 import ( 13 "reflect" 14 "testing" 15 ) 16 17 func TestParseOptions(t *testing.T) { 18 wanted1 := defaultOpts 19 wanted1.frameSize = 1 << 10 20 wanted1.framesPerBlock = wanted1.blockSize / wanted1.frameSize 21 for i, test := range []struct { 22 opts []interface{} 23 want options 24 err bool 25 }{ 26 {opts: []interface{}{OptBlockSize(2)}, err: true}, 27 {opts: []interface{}{OptFrameSize(333)}, err: true}, 28 {opts: []interface{}{OptTPacketVersion(-3)}, err: true}, 29 {opts: []interface{}{OptTPacketVersion(5)}, err: true}, 30 {opts: []interface{}{OptFrameSize(1 << 10)}, want: wanted1}, 31 } { 32 got, err := parseOptions(test.opts...) 33 t.Logf("got: %#v\nerr: %v", got, err) 34 if test.err && err == nil || !test.err && err != nil { 35 t.Errorf("%d error mismatch, want error? %v. error: %v", i, test.err, err) 36 } 37 if !test.err && !reflect.DeepEqual(test.want, got) { 38 t.Errorf("%d opts mismatch, want\n%#v", i, test.want) 39 } 40 } 41 }