Debian Codegraph @

tests/nftlib/nftlib_test.go

raw symbols SCIP
1 //go:build !exec
2 // +build !exec
3
4 /* This file is part of the go-nft project
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * Copyright 2021 Red Hat, Inc.
19 *
20 */
21 package main
22
23 import (
24 "testing"
25
26 assert "github.com/stretchr/testify/require"
27
28 "github.com/networkplumbing/go-nft/nft"
29 nftlib "github.com/networkplumbing/go-nft/nft/lib"
30
31 "github.com/networkplumbing/go-nft/tests/testlib"
32 )
33
34 func TestNftlib(t *testing.T) {
35 testlib.RunTestWithFlushTable(t, func(t *testing.T) {
36 config := nft.NewConfig()
37 config.AddTable(nft.NewTable("mytable", nft.FamilyIP))
38
39 assert.NoError(t, nftlib.ApplyConfig(config))
40
41 newConfig, err := nftlib.ReadConfig()
42 assert.NoError(t, err)
43
44 assert.Len(t, newConfig.Nftables, 2, "Expecting the metainfo and an empty table entry")
45 assert.Equal(t, config.Nftables[0], newConfig.Nftables[1])
46 _, err = nftlib.ReadConfig()
47 assert.NoError(t, err)
48
49 newConfig, err = nftlib.ApplyConfigEcho(config)
50 assert.NoError(t, err)
51 assert.Len(t, newConfig.Nftables, 1, "Expecting just the empty table entry")
52 assert.Equal(t, config.Nftables, newConfig.Nftables)
53 })
54 }