"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "go/test/netspoc_test.go" between
Netspoc-6.025.tar.gz and Netspoc-6.026.tar.gz

About: NetSPoC is a network security policy compiler (using its own description language) to manage all the packet filter devices inside your network topology.

netspoc_test.go  (Netspoc-6.025):netspoc_test.go  (Netspoc-6.026)
package netspoc_test package netspoc_test
import ( import (
"fmt"
"github.com/hknutzen/Netspoc/go/pkg/addto" "github.com/hknutzen/Netspoc/go/pkg/addto"
"github.com/hknutzen/Netspoc/go/pkg/format" "github.com/hknutzen/Netspoc/go/pkg/format"
"github.com/hknutzen/Netspoc/go/pkg/pass1" "github.com/hknutzen/Netspoc/go/pkg/pass1"
"github.com/hknutzen/Netspoc/go/pkg/pass2" "github.com/hknutzen/Netspoc/go/pkg/pass2"
"github.com/hknutzen/Netspoc/go/pkg/removefrom" "github.com/hknutzen/Netspoc/go/pkg/removefrom"
"github.com/hknutzen/Netspoc/go/pkg/rename" "github.com/hknutzen/Netspoc/go/pkg/rename"
"github.com/hknutzen/Netspoc/go/test/capture" "github.com/hknutzen/Netspoc/go/test/capture"
"github.com/hknutzen/Netspoc/go/test/tstdata" "github.com/hknutzen/Netspoc/go/test/tstdata"
"gotest.tools/assert" "gotest.tools/assert"
"io/ioutil" "io/ioutil"
skipping to change at line 38 skipping to change at line 37
) )
type test struct { type test struct {
dir string dir string
typ int typ int
run func() int run func() int
check func(*testing.T, string, string) check func(*testing.T, string, string)
} }
var tests = []test{ var tests = []test{
{".", outDirT, netspocRun, netspocCheck}, {".", outDirT, pass1.SpocMain, netspocCheck},
{"pipe", outDirT, netspocPipeRun, netspocCheck},
{"export-netspoc", outDirT, pass1.ExportMain, exportCheck}, {"export-netspoc", outDirT, pass1.ExportMain, exportCheck},
{"format-netspoc", chgInputT, format.Main, formatCheck}, {"format-netspoc", chgInputT, format.Main, formatCheck},
{"add-to-netspoc", chgInputT, addto.Main, chgInputCheck}, {"add-to-netspoc", chgInputT, addto.Main, chgInputCheck},
{"remove-from-netspoc", chgInputT, removefrom.Main, chgInputCheck}, {"remove-from-netspoc", chgInputT, removefrom.Main, chgInputCheck},
{"rename-netspoc", chgInputT, rename.Main, chgInputCheck}, {"rename-netspoc", chgInputT, rename.Main, chgInputCheck},
{"cut-netspoc", stdoutT, pass1.CutNetspocMain, stdoutCheck}, {"cut-netspoc", stdoutT, pass1.CutNetspocMain, stdoutCheck},
{"print-group", stdoutT, pass1.PrintGroupMain, stdoutCheck}, {"print-group", stdoutT, pass1.PrintGroupMain, stdoutCheck},
{"print-service", stdoutT, pass1.PrintServiceMain, stdoutCheck}, {"print-service", stdoutT, pass1.PrintServiceMain, stdoutCheck},
{"check-acl", outDirStdoutT, checkACLRun, stdoutCheck}, {"check-acl", outDirStdoutT, checkACLRun, stdoutCheck},
} }
skipping to change at line 64 skipping to change at line 62
count = 0 count = 0
for _, tc := range tests { for _, tc := range tests {
tc := tc // capture range variable tc := tc // capture range variable
t.Run(tc.dir, func(t *testing.T) { t.Run(tc.dir, func(t *testing.T) {
runTestFiles(t, tc) runTestFiles(t, tc)
}) })
} }
t.Logf("Checked %d assertions", count) t.Logf("Checked %d assertions", count)
} }
// Run Netspoc pass1 + pass2 sequentially.
// Use file 'code/.devices' to communicate.
func netspocRun() int {
status := pass1.SpocMain()
if status == 0 {
pass2.Spoc2Main()
}
return status
}
// Run Netspoc pass1 + pass2 sequentially.
// Stdout of pass1 is sent to stdin of pass2.
func netspocPipeRun() int {
// Collect output of pass1.
var status int
devices := capture.Capture(&os.Stdout, func() {
status = pass1.SpocMain()
})
if status != 0 {
return status
}
// Send output to stdin of pass2.
r, w, err := os.Pipe()
if err != nil {
panic(err)
}
old := os.Stdin
os.Stdin = r
defer func() { os.Stdin = old }()
go func() { fmt.Fprint(w, devices) }()
pass2.Spoc2Main()
return 0
}
func runTestFiles(t *testing.T, tc test) { func runTestFiles(t *testing.T, tc test) {
dataFiles := tstdata.GetFiles("../testdata/" + tc.dir) dataFiles := tstdata.GetFiles("../testdata/" + tc.dir)
os.Unsetenv("SHOW_DIAG") os.Unsetenv("SHOW_DIAG")
for _, file := range dataFiles { for _, file := range dataFiles {
file := file // capture range variable file := file // capture range variable
t.Run(path.Base(file), func(t *testing.T) { t.Run(path.Base(file), func(t *testing.T) {
l, err := tstdata.ParseFile(file) l, err := tstdata.ParseFile(file)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
 End of changes. 3 change blocks. 
39 lines changed or deleted 1 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)