Debian Codegraph @

tests/example/skeleton.go

raw symbols SCIP
1 /*
2 * This file is part of the go-nft project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * Copyright 2021 Red Hat, Inc.
17 *
18 */
19
20 package examplescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/tests/example`/
21
22 import (
23 "fmtscip-go gomod github.com/golang/go/src go1.16 fmt/"
24
25 "github.com/networkplumbing/go-nft/tests/testlibscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/tests/testlib`/"
26
27 "github.com/networkplumbing/go-nft/nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/"
28 )
29
30 type buildConfigTscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/tests/example`/buildConfigT# func() *nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.Configscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/Config#
31
32 func setupExamplescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/tests/example`/setupExample().(buildConfig buildConfigTscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/tests/example`/buildConfigT#) (string, string, error) {
33 desiredConfig := buildConfig()
34 if err := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.ApplyConfigscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/ApplyConfig().(desiredConfig); err != nil {
35 return "", "", fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.16 fmt/Errorf().("failed to setup example: %v", err)
36 }
37
38 actualConfig, err := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.ReadConfigscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/ReadConfig().()
39 if err != nil {
40 return "", "", fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.16 fmt/Errorf().("failed to setup example: %v", err)
41 }
42
43 desiredNftablesEntries := len(desiredConfig.Nftablesscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Root#Nftables.) + 1 // +1 for the metainfo entry.
44 actualNftablesEntries := len(actualConfig.Nftablesscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Root#Nftables.)
45 if actualNftablesEntries != desiredNftablesEntries {
46 desiredJson, _ := desiredConfig.ToJSONscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#ToJSON().()
47 actualJson, _ := actualConfig.ToJSONscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#ToJSON().()
48 return "", "", fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.16 fmt/Errorf().(
49 "failed to setup example, unexpected entries in post-setup resuts, desired(%d): %s, actual(%d): %s",
50 desiredNftablesEntries, desiredJson, actualNftablesEntries, actualJson,
51 )
52 }
53
54 desiredConfig = testlibscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/tests/testlib`/.NormalizeConfigForComparisonscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/tests/testlib`/NormalizeConfigForComparison().(desiredConfig)
55 actualConfig = testlibscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/tests/testlib`/.NormalizeConfigForComparisonscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/tests/testlib`/NormalizeConfigForComparison().(actualConfig)
56
57 desiredJson, err := desiredConfig.ToJSONscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#ToJSON().()
58 if err != nil {
59 return "", "", fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.16 fmt/Errorf().("failed to setup example, error json encoding: %v", err)
60 }
61 actualJson, err := actualConfig.ToJSONscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#ToJSON().()
62 if err != nil {
63 return "", "", fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.16 fmt/Errorf().("failed to setup example, error json encoding: %v", err)
64 }
65
66 return string(desiredJson), string(actualJson), nil
67 }