Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cheina97 committed Jan 11, 2024
1 parent fbea8ae commit 415bd8b
Show file tree
Hide file tree
Showing 14 changed files with 2,374 additions and 78 deletions.
225 changes: 225 additions & 0 deletions chain_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
// Copyright 2018 Google LLC. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package nftables

import (
"reflect"
"testing"

"github.com/mdlayher/netlink"
)

func TestChainHookRef(t *testing.T) {
type args struct {
h ChainHook
}
tests := []struct {
name string
args args
want *ChainHook
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ChainHookRef(tt.args.h); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ChainHookRef() = %v, want %v", got, tt.want)
}
})
}
}

func TestChainPriorityRef(t *testing.T) {
type args struct {
p ChainPriority
}
tests := []struct {
name string
args args
want *ChainPriority
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ChainPriorityRef(tt.args.p); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ChainPriorityRef() = %v, want %v", got, tt.want)
}
})
}
}

func TestConn_AddChain(t *testing.T) {
type args struct {
c *Chain
}
tests := []struct {
name string
cc *Conn
args args
want *Chain
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.cc.AddChain(tt.args.c); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Conn.AddChain() = %v, want %v", got, tt.want)
}
})
}
}

func TestConn_DelChain(t *testing.T) {
type args struct {
c *Chain
}
tests := []struct {
name string
cc *Conn
args args
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.cc.DelChain(tt.args.c)
})
}
}

func TestConn_FlushChain(t *testing.T) {
type args struct {
c *Chain
}
tests := []struct {
name string
cc *Conn
args args
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.cc.FlushChain(tt.args.c)
})
}
}

func TestConn_ListChains(t *testing.T) {
tests := []struct {
name string
cc *Conn
want []*Chain
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := tt.cc.ListChains()
if (err != nil) != tt.wantErr {
t.Errorf("Conn.ListChains() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Conn.ListChains() = %v, want %v", got, tt.want)
}
})
}
}

func TestConn_ListChainsOfTableFamily(t *testing.T) {
type args struct {
family TableFamily
}
tests := []struct {
name string
cc *Conn
args args
want []*Chain
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := tt.cc.ListChainsOfTableFamily(tt.args.family)
if (err != nil) != tt.wantErr {
t.Errorf("Conn.ListChainsOfTableFamily() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Conn.ListChainsOfTableFamily() = %v, want %v", got, tt.want)
}
})
}
}

func Test_chainFromMsg(t *testing.T) {
type args struct {
msg netlink.Message
}
tests := []struct {
name string
args args
want *Chain
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := chainFromMsg(tt.args.msg)
if (err != nil) != tt.wantErr {
t.Errorf("chainFromMsg() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("chainFromMsg() = %v, want %v", got, tt.want)
}
})
}
}

func Test_hookFromMsg(t *testing.T) {
type args struct {
b []byte
}
tests := []struct {
name string
args args
want *ChainHook
want1 *ChainPriority
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, got1, err := hookFromMsg(tt.args.b)
if (err != nil) != tt.wantErr {
t.Errorf("hookFromMsg() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("hookFromMsg() got = %v, want %v", got, tt.want)
}
if !reflect.DeepEqual(got1, tt.want1) {
t.Errorf("hookFromMsg() got1 = %v, want %v", got1, tt.want1)
}
})
}
}
27 changes: 27 additions & 0 deletions compat_policy_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nftables

import (
"reflect"
"testing"

"github.com/google/nftables/expr"
Expand Down Expand Up @@ -75,3 +76,29 @@ func TestGetCompatPolicy(t *testing.T) {
t.Fatalf("getCompatPolicy fail compat policy of conntrack match should be nil")
}
}

func Test_getCompatPolicy(t *testing.T) {
type args struct {
exprs []expr.Any
}
tests := []struct {
name string
args args
want *compatPolicy
wantErr bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := getCompatPolicy(tt.args.exprs)
if (err != nil) != tt.wantErr {
t.Errorf("getCompatPolicy() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("getCompatPolicy() = %v, want %v", got, tt.want)
}
})
}
}
Loading

0 comments on commit 415bd8b

Please sign in to comment.