Преглед на файлове

Merge pull request #90 from bgilbert/travis

Convert CI from Travis to GitHub Actions; fix lints
Luca Bruno преди 2 години
родител
ревизия
d79d80bc60
променени са 5 файла, в които са добавени 53 реда и са изтрити 31 реда
  1. 37 0
      .github/workflows/go.yml
  2. 0 25
      .travis.yml
  3. 1 1
      README.md
  4. 3 1
      iptables/iptables.go
  5. 12 4
      iptables/iptables_test.go

+ 37 - 0
.github/workflows/go.yml

@@ -0,0 +1,37 @@
+name: Go
+
+on:
+  push:
+    branches: [main]
+  pull_request:
+    branches: [main]
+
+permissions:
+  contents: read
+
+env:
+  SUDO_PERMITTED: 1
+
+jobs:
+  test:
+    name: Test
+    strategy:
+      matrix:
+        go-version: [1.16.x, 1.17.x, 1.18.x]
+    runs-on: ubuntu-latest
+    steps:
+    - name: Set up Go 1.x
+      uses: actions/setup-go@v2
+      with:
+        go-version: ${{ matrix.go-version }}
+    - name: Check out repository
+      uses: actions/checkout@v2
+    - name: Install dependencies
+      run: go get golang.org/x/tools/cmd/cover
+    - name: Run tests
+      run: ./test
+    - name: Run linter
+      uses: golangci/golangci-lint-action@v2
+      with:
+        version: v1.46.2
+        args: -E=gofmt --timeout=30m0s

+ 0 - 25
.travis.yml

@@ -1,25 +0,0 @@
-language: go
-sudo: required
-dist: trusty
-arch:
-  - AMD64
-  - ppc64le
-go:
-  - 1.9.x
-  - 1.10.x
-  - tip
-env:
-  global:
-    - TOOLS_CMD=golang.org/x/tools/cmd
-    - PATH=$GOROOT/bin:$PATH
-    - SUDO_PERMITTED=1
-
-matrix:
-  allow_failures:
-    - go: tip
-
-install:
- - go get golang.org/x/tools/cmd/cover
-
-script:
- - ./test

+ 1 - 1
README.md

@@ -1,7 +1,7 @@
 # go-iptables
 # go-iptables
 
 
 [![GoDoc](https://godoc.org/github.com/coreos/go-iptables/iptables?status.svg)](https://godoc.org/github.com/coreos/go-iptables/iptables)
 [![GoDoc](https://godoc.org/github.com/coreos/go-iptables/iptables?status.svg)](https://godoc.org/github.com/coreos/go-iptables/iptables)
-[![Build Status](https://travis-ci.org/coreos/go-iptables.png?branch=master)](https://travis-ci.org/coreos/go-iptables)
+[![Build status](https://github.com/coreos/go-iptables/actions/workflows/go.yml/badge.svg)](https://github.com/coreos/go-iptables/actions/workflows/go.yml)
 
 
 Go bindings for iptables utility.
 Go bindings for iptables utility.
 
 

+ 3 - 1
iptables/iptables.go

@@ -510,7 +510,9 @@ func (ipt *IPTables) runWithOutput(args []string, stdout io.Writer) error {
 			syscall.Close(fmu.fd)
 			syscall.Close(fmu.fd)
 			return err
 			return err
 		}
 		}
-		defer ul.Unlock()
+		defer func() {
+			_ = ul.Unlock()
+		}()
 	}
 	}
 
 
 	var stderr bytes.Buffer
 	var stderr bytes.Buffer

+ 12 - 4
iptables/iptables_test.go

@@ -473,8 +473,12 @@ func TestIsNotExist(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 	defer func() {
 	defer func() {
-		ipt.ClearChain("filter", chainName)
-		ipt.DeleteChain("filter", chainName)
+		if err := ipt.ClearChain("filter", chainName); err != nil {
+			t.Fatal(err)
+		}
+		if err := ipt.DeleteChain("filter", chainName); err != nil {
+			t.Fatal(err)
+		}
 	}()
 	}()
 
 
 	err = ipt.Append("filter", chainName, "-p", "tcp", "-j", "DROP")
 	err = ipt.Append("filter", chainName, "-p", "tcp", "-j", "DROP")
@@ -542,8 +546,12 @@ func TestIsNotExistForIPv6(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 	defer func() {
 	defer func() {
-		ipt.ClearChain("filter", chainName)
-		ipt.DeleteChain("filter", chainName)
+		if err := ipt.ClearChain("filter", chainName); err != nil {
+			t.Fatal(err)
+		}
+		if err := ipt.DeleteChain("filter", chainName); err != nil {
+			t.Fatal(err)
+		}
 	}()
 	}()
 
 
 	err = ipt.Append("filter", chainName, "-p", "tcp", "-j", "DROP")
 	err = ipt.Append("filter", chainName, "-p", "tcp", "-j", "DROP")