Debian Codegraph @

error_test.go

raw symbols SCIP
1 /*
2 Copyright 2023 The Kubernetes Authors.
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
17 package knftablesscip-go gomod sigs.k8s.io/knftables . `sigs.k8s.io/knftables`/
18
19 import (
20 "fmtscip-go gomod github.com/golang/go/src go1.20 fmt/"
21 "os/execscip-go gomod github.com/golang/go/src go1.20 `os/exec`/"
22 "testingscip-go gomod github.com/golang/go/src go1.20 testing/"
23 )
24
25 func mkExecErrorscip-go gomod sigs.k8s.io/knftables . `sigs.k8s.io/knftables`/mkExecError().(stderr string) error {
26 return wrapErrorscip-go gomod sigs.k8s.io/knftables . `sigs.k8s.io/knftables`/wrapError().(&execscip-go gomod github.com/golang/go/src go1.20 `os/exec`/.ExitErrorscip-go gomod github.com/golang/go/src go1.20 `os/exec`/ExitError#{Stderrscip-go gomod github.com/golang/go/src go1.20 `os/exec`/ExitError#Stderr.: []byte(stderr)})
27 }
28
29 func TestErrorscip-go gomod sigs.k8s.io/knftables . `sigs.k8s.io/knftables`/TestError().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) {
30 for _, tc := range []struct {
31 name string
32 err error
33 isNotFound bool
34 isExists bool
35 }{
36 {
37 name: "generic doesn't exist",
38 err: mkExecErrorscip-go gomod sigs.k8s.io/knftables . `sigs.k8s.io/knftables`/mkExecError().("Error: No such file or directory\ndelete element ip nosuchtable set {10.0.0.1}\n ^^^^^^^^^^^\n"),
39 isNotFound: true,
40 isExists: false,
41 },
42 {
43 name: "doesn't exist with suggestion",
44 err: mkExecErrorscip-go gomod sigs.k8s.io/knftables . `sigs.k8s.io/knftables`/mkExecError().("Error: No such file or directory; did you mean table ‘foo’ in family ip?\nblah blah blah\n"),
45 isNotFound: true,
46 isExists: false,
47 },
48 {
49 name: "already exists",
50 err: mkExecErrorscip-go gomod sigs.k8s.io/knftables . `sigs.k8s.io/knftables`/mkExecError().("Error: Could not process rule: File exists\ncreate table foo\n ^^^"),
51 isNotFound: false,
52 isExists: true,
53 },
54 {
55 name: "wrapped doesn't exist",
56 err: fmtscip-go gomod github.com/golang/go/src go1.20 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.20 fmt/Errorf().("oh my! %w", mkExecErrorscip-go gomod sigs.k8s.io/knftables . `sigs.k8s.io/knftables`/mkExecError().("Error: No such file or directory")),
57 isNotFound: true,
58 isExists: false,
59 },
60 {
61 name: "misc error",
62 err: mkExecErrorscip-go gomod sigs.k8s.io/knftables . `sigs.k8s.io/knftables`/mkExecError().("Error: syntax error, unexpected string, expecting '{' or '$'"),
63 isNotFound: false,
64 isExists: false,
65 },
66 {
67 name: "misleading misc error",
68 err: mkExecErrorscip-go gomod sigs.k8s.io/knftables . `sigs.k8s.io/knftables`/mkExecError().("Error: syntax error, unexpected comment\nadd rule foo chain1 comment \"No such file or directory\" drop\n ^^^^^^^"),
69 isNotFound: false,
70 isExists: false,
71 },
72 {
73 name: "not an ExecError, so not interpreted",
74 err: wrapErrorscip-go gomod sigs.k8s.io/knftables . `sigs.k8s.io/knftables`/wrapError().(fmtscip-go gomod github.com/golang/go/src go1.20 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.20 fmt/Errorf().("Error: No such file or directory\ndelete element ip nosuchtable set {10.0.0.1}\n ^^^^^^^^^^^\n")), //nolint:revive
75 isNotFound: false,
76 isExists: false,
77 },
78 {
79 name: "fake not found",
80 err: notFoundErrorscip-go gomod sigs.k8s.io/knftables . `sigs.k8s.io/knftables`/notFoundError().("not found"),
81 isNotFound: true,
82 isExists: false,
83 },
84 {
85 name: "fake exists",
86 err: existsErrorscip-go gomod sigs.k8s.io/knftables . `sigs.k8s.io/knftables`/existsError().("already exists"),
87 isNotFound: false,
88 isExists: true,
89 },
90 } {
91 t.Runscip-go gomod github.com/golang/go/src go1.20 testing/T#Run().(tc.name, func(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) {
92 if IsNotFoundscip-go gomod sigs.k8s.io/knftables . `sigs.k8s.io/knftables`/IsNotFound().(tc.err) != tc.isNotFound {
93 t.Errorfscip-go gomod github.com/golang/go/src go1.20 testing/common#Errorf().("expected IsNotFound %v, got %v", tc.isNotFound, IsNotFoundscip-go gomod sigs.k8s.io/knftables . `sigs.k8s.io/knftables`/IsNotFound().(tc.err))
94 }
95 if IsAlreadyExistsscip-go gomod sigs.k8s.io/knftables . `sigs.k8s.io/knftables`/IsAlreadyExists().(tc.err) != tc.isExists {
96 t.Errorfscip-go gomod github.com/golang/go/src go1.20 testing/common#Errorf().("expected IsAlreadyExists %v, got %v", tc.isExists, IsAlreadyExistsscip-go gomod sigs.k8s.io/knftables . `sigs.k8s.io/knftables`/IsAlreadyExists().(tc.err))
97 }
98 })
99 }
100 }