Jelajahi Sumber

Use GitHub Actions to run automated tests

Rod Hynes 4 tahun lalu
induk
melakukan
2ffdc7d4b3
6 mengubah file dengan 137 tambahan dan 85 penghapusan
  1. 129 0
      .github/workflows/tests.yml
  2. 0 77
      .travis.yml
  3. 2 1
      README.md
  4. TEMPAT SAMPAH
      psiphon/controller_test.config.enc
  5. TEMPAT SAMPAH
      psiphon/feedback_test.config.enc
  6. 6 7
      psiphon/feedback_test.go

+ 129 - 0
.github/workflows/tests.yml

@@ -0,0 +1,129 @@
+name: CI
+
+on:
+  push:
+    branches:
+      - master
+      - staging-client
+      - staging-server
+
+jobs:
+  run_tests:
+
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [ "ubuntu" ]
+        go: [ "1.14.12" ]
+        test-type: [ "detector", "coverage", "memory" ]
+
+    runs-on: ${{ matrix.os }}-latest
+
+    name: psiphon-tunnel-core ${{ matrix.test-type }} tests on ${{ matrix.os}}, Go ${{ matrix.go }}
+
+    env:
+      GOPATH: ${{ github.workspace }}/go
+
+    steps:
+
+      - name: Clone repository
+        uses: actions/checkout@v2
+        with:
+          path: ${{ github.workspace }}/go/src/github.com/Psiphon-Labs/psiphon-tunnel-core
+
+      - name: Install Go
+        uses: actions/setup-go@v2
+        with:
+          go-version: ${{ matrix.go }}
+
+      - name: Install networking components
+        run: |
+          sudo apt-get update
+          sudo apt-get install libnetfilter-queue-dev
+          sudo apt-get install conntrack
+
+      - name: Install coverage tools
+        if: ${{ matrix.test-type == 'coverage' }}
+        run: |
+          go get github.com/axw/gocov/gocov
+          go get github.com/modocache/gover
+          go get github.com/mattn/goveralls
+          go get golang.org/x/tools/cmd/cover
+
+      - name: Check environment
+        run: |
+          echo "GitHub workspace: $GITHUB_WORKSPACE"
+          echo "Working directory: `pwd`"
+          echo "GOROOT: $GOROOT"
+          echo "GOPATH: $GOPATH"
+          echo "Go version: `go version`"
+
+      - name: Pave config files
+        env:
+          CONTROLLER_TEST_CONFIG: ${{ secrets.CONTROLLER_TEST_CONFIG }}
+        run: |
+          cd ${{ github.workspace }}/go/src/github.com/Psiphon-Labs/psiphon-tunnel-core
+          echo "$CONTROLLER_TEST_CONFIG" > ./psiphon/controller_test.config
+
+      # TODO: fix and re-enable test
+      # sudo -E env "PATH=$PATH" go test -v -race ./psiphon/common/tun
+      - name: Run tests with data race detector
+        if: ${{ matrix.test-type == 'detector' }}
+        run: |
+          cd ${{ github.workspace }}/go/src/github.com/Psiphon-Labs/psiphon-tunnel-core
+          go test -v -race ./psiphon/common
+          go test -v -race ./psiphon/common/accesscontrol
+          go test -v -race ./psiphon/common/crypto/ssh
+          go test -v -race ./psiphon/common/fragmentor
+          go test -v -race ./psiphon/common/obfuscator
+          go test -v -race ./psiphon/common/osl
+          sudo -E env "PATH=$PATH" go test -v -race -tags "PSIPHON_RUN_PACKET_MANIPULATOR_TEST" ./psiphon/common/packetman
+          go test -v -race ./psiphon/common/parameters
+          go test -v -race ./psiphon/common/protocol
+          go test -v -race ./psiphon/common/quic
+          go test -v -race ./psiphon/common/tactics
+          go test -v -race ./psiphon/common/values
+          go test -v -race ./psiphon/common/wildcard
+          go test -v -race ./psiphon/transferstats
+          sudo -E env "PATH=$PATH" go test -v -race -tags "PSIPHON_RUN_PACKET_MANIPULATOR_TEST" ./psiphon/server
+          go test -v -race ./psiphon/server/psinet
+          go test -v -race ./psiphon
+          go test -v -race ./ClientLibrary/clientlib
+          go test -v -race ./Server/logging/analysis
+
+      # TODO: fix and re-enable test
+      # sudo -E env "PATH=$PATH" go test -v -covermode=count -coverprofile=tun.coverprofile ./psiphon/common/tun
+      - name: Run tests with coverage
+        env:
+          COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
+        if: ${{ matrix.test-type == 'coverage' && env.COVERALLS_TOKEN != '' }}
+        run: |
+          cd ${{ github.workspace }}/go/src/github.com/Psiphon-Labs/psiphon-tunnel-core
+          go test -v -covermode=count -coverprofile=common.coverprofile ./psiphon/common
+          go test -v -covermode=count -coverprofile=accesscontrol.coverprofile ./psiphon/common/accesscontrol
+          go test -v -covermode=count -coverprofile=ssh.coverprofile ./psiphon/common/crypto/ssh
+          go test -v -covermode=count -coverprofile=fragmentor.coverprofile ./psiphon/common/fragmentor
+          go test -v -covermode=count -coverprofile=obfuscator.coverprofile ./psiphon/common/obfuscator
+          go test -v -covermode=count -coverprofile=osl.coverprofile ./psiphon/common/osl
+          sudo -E env "PATH=$PATH" go test -v -covermode=count -coverprofile=packetman.coverprofile -tags "PSIPHON_RUN_PACKET_MANIPULATOR_TEST" ./psiphon/common/packetman
+          go test -v -covermode=count -coverprofile=parameters.coverprofile ./psiphon/common/parameters
+          go test -v -covermode=count -coverprofile=protocol.coverprofile ./psiphon/common/protocol
+          go test -v -covermode=count -coverprofile=quic.coverprofile ./psiphon/common/quic
+          go test -v -covermode=count -coverprofile=tactics.coverprofile ./psiphon/common/tactics
+          go test -v -covermode=count -coverprofile=values.coverprofile ./psiphon/common/values
+          go test -v -covermode=count -coverprofile=wildcard.coverprofile ./psiphon/common/wildcard
+          go test -v -covermode=count -coverprofile=transferstats.coverprofile ./psiphon/transferstats
+          sudo -E env "PATH=$PATH" go test -v -covermode=count -coverprofile=server.coverprofile -tags "PSIPHON_RUN_PACKET_MANIPULATOR_TEST" ./psiphon/server
+          go test -v -covermode=count -coverprofile=psinet.coverprofile ./psiphon/server/psinet
+          go test -v -covermode=count -coverprofile=psiphon.coverprofile ./psiphon
+          go test -v -covermode=count -coverprofile=clientlib.coverprofile ./ClientLibrary/clientlib
+          go test -v -covermode=count -coverprofile=analysis.coverprofile ./Server/logging/analysis
+          $GOPATH/bin/gover
+          $GOPATH/bin/goveralls -coverprofile=gover.coverprofile -service=github -repotoken "$COVERALLS_TOKEN"
+
+      - name: Run memory tests
+        if: ${{ matrix.test-type == 'memory' }}
+        run: |
+          cd ${{ github.workspace }}/go/src/github.com/Psiphon-Labs/psiphon-tunnel-core
+          go test -v ./psiphon/memory_test -run TestReconnectTunnel
+          go test -v ./psiphon/memory_test -run TestRestartController

+ 0 - 77
.travis.yml

@@ -1,77 +0,0 @@
-dist: trusty
-language: go
-sudo: required
-go:
-- 1.14.12
-addons:
-  apt_packages:
-    - libx11-dev
-    - libgles2-mesa-dev
-script:
-- cd psiphon
-- go test -race -v ./common
-- go test -race -v ./common/accesscontrol
-- go test -race -v ./common/crypto/ssh
-- go test -race -v ./common/fragmentor
-- go test -race -v ./common/obfuscator
-- go test -race -v ./common/osl
-- sudo -E env "PATH=$PATH" go test -race -v -tags "PSIPHON_RUN_PACKET_MANIPULATOR_TEST" ./common/packetman
-- go test -race -v ./common/parameters
-- go test -race -v ./common/protocol
-- go test -race -v ./common/quic
-- go test -race -v ./common/tactics
-# TODO: fix and reenable test, which is failing in TravisCI environment:
-# --- FAIL: TestTunneledTCPIPv4
-#    tun_test.go:226: startTestTCPClient failed: syscall.Connect failed: connection timed out
-#
-#- sudo -E env "PATH=$PATH" go test -race -v ./common/tun
-- go test -race -v ./common/values
-- go test -race -v ./common/wildcard
-- go test -race -v ./transferstats
-- sudo -E env "PATH=$PATH" go test -race -v -tags "PSIPHON_RUN_PACKET_MANIPULATOR_TEST" ./server
-- go test -race -v ./server/psinet
-- go test -race -v ../Server/logging/analysis
-- go test -race -v ../ClientLibrary/clientlib
-- go test -race -v
-- go test -v -covermode=count -coverprofile=common.coverprofile ./common
-- go test -v -covermode=count -coverprofile=accesscontrol.coverprofile ./common/accesscontrol
-- go test -v -covermode=count -coverprofile=ssh.coverprofile ./common/crypto/ssh
-- go test -v -covermode=count -coverprofile=fragmentor.coverprofile ./common/fragmentor
-- go test -v -covermode=count -coverprofile=obfuscator.coverprofile ./common/obfuscator
-- go test -v -covermode=count -coverprofile=osl.coverprofile ./common/osl
-- go test -v -covermode=count -coverprofile=parameters.coverprofile ./common/parameters
-- sudo -E env "PATH=$PATH" go test -v -covermode=count -coverprofile=packetman.coverprofile -tags "PSIPHON_RUN_PACKET_MANIPULATOR_TEST" ./common/packetman
-- go test -v -covermode=count -coverprofile=protocol.coverprofile ./common/protocol
-- go test -v -covermode=count -coverprofile=quic.coverprofile ./common/quic
-- go test -v -covermode=count -coverprofile=tactics.coverprofile ./common/tactics
-# TODO: see "tun" test comment above
-#- sudo -E env "PATH=$PATH" go test -v -covermode=count -coverprofile=tun.coverprofile ./common/tun
-- go test -v -covermode=count -coverprofile=values.coverprofile ./common/values
-- go test -v -covermode=count -coverprofile=wildcard.coverprofile ./common/wildcard
-- go test -v -covermode=count -coverprofile=transferstats.coverprofile ./transferstats
-- sudo -E env "PATH=$PATH" go test -v -covermode=count -coverprofile=server.coverprofile -tags "PSIPHON_RUN_PACKET_MANIPULATOR_TEST" ./server
-- go test -v -covermode=count -coverprofile=psinet.coverprofile ./server/psinet
-- go test -v -covermode=count -coverprofile=analysis.coverprofile ../Server/logging/analysis
-- go test -v -covermode=count -coverprofile=clientlib.coverprofile ../ClientLibrary/clientlib
-- go test -v -covermode=count -coverprofile=psiphon.coverprofile
-- go test -v ./memory_test -run TestReconnectTunnel
-- go test -v ./memory_test -run TestRestartController
-after_script:
-- $HOME/gopath/bin/gover
-- $HOME/gopath/bin/goveralls -coverprofile=gover.coverprofile -service=travis-ci -repotoken $COVERALLS_TOKEN
-before_install:
-- go get github.com/axw/gocov/gocov
-- go get github.com/modocache/gover
-- go get github.com/mattn/goveralls
-- if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi
-- git rev-parse --short HEAD > psiphon/git_rev
-- openssl aes-256-cbc -K $encrypted_bf83b4ab4874_key -iv $encrypted_bf83b4ab4874_iv
-  -in psiphon/controller_test.config.enc -out psiphon/controller_test.config -d
-- openssl aes-256-cbc -K $encrypted_560fd0d04977_key -iv $encrypted_560fd0d04977_iv 
-  -in psiphon/feedback_test.config.enc -out psiphon/feedback_test.config -d
-notifications:
-  slack:
-    rooms:
-      secure: jVo/BZ1iFtg4g5V+eNxETwXPnbhwVwGzN1vkHJnCLAhV/md3/uHGsZQIMfitqgrX/T+9JBVRbRezjBwfJHYLs40IJTCWt167Lz8R1NlazLyEpcGcdesG05cTl9oEcBb7X52kZt7r8ZIBwdB7W6U/E0/i41qKamiEJqISMsdOoFA=
-    on_success: always
-    on_failure: always

+ 2 - 1
README.md

@@ -1,4 +1,5 @@
-[![Build Status](https://travis-ci.org/Psiphon-Labs/psiphon-tunnel-core.png)](https://travis-ci.org/Psiphon-Labs/psiphon-tunnel-core) [![Coverage Status](https://coveralls.io/repos/github/Psiphon-Labs/psiphon-tunnel-core/badge.svg?branch=master)](https://coveralls.io/github/Psiphon-Labs/psiphon-tunnel-core?branch=master)
+[![CI](https://github.com/Psiphon-Labs/psiphon-tunnel-core/actions/workflows/tests.yml/badge.svg)](https://github.com/Psiphon-Labs/psiphon-tunnel-core/actions/workflows/tests.yml) [![Coverage Status](https://coveralls.io/repos/github/Psiphon-Labs/psiphon-tunnel-core/badge.svg?branch=master)](https://coveralls.io/github/Psiphon-Labs/psiphon-tunnel-core?branch=master)
+
 
 Psiphon Tunnel Core README
 ================================================================================

TEMPAT SAMPAH
psiphon/controller_test.config.enc


TEMPAT SAMPAH
psiphon/feedback_test.config.enc


+ 6 - 7
psiphon/feedback_test.go

@@ -23,6 +23,7 @@ import (
 	"context"
 	"encoding/json"
 	"io/ioutil"
+	"os/exec"
 	"testing"
 )
 
@@ -41,7 +42,7 @@ type Diagnostics struct {
 }
 
 func TestFeedbackUpload(t *testing.T) {
-	configFileContents, err := ioutil.ReadFile("feedback_test.config")
+	configFileContents, err := ioutil.ReadFile("controller_test.config")
 	if err != nil {
 		// Skip, don't fail, if config file is not present
 		t.Skipf("error loading configuration file: %s", err)
@@ -65,13 +66,11 @@ func TestFeedbackUpload(t *testing.T) {
 		t.Fatalf("error committing configuration file: %s", err)
 	}
 
-	// git_rev is a file which contains the shortened hash of the latest commit
-	// pointed to by HEAD, i.e. git rev-parse --short HEAD.
-
-	shortRevHash, err := ioutil.ReadFile("git_rev")
+	shortRevHash, err := exec.Command("git", "rev-parse", "--short", "HEAD").Output()
 	if err != nil {
-		// Skip, don't fail, if git rev file is not present
-		t.Skipf("error loading git revision file: %s", err)
+		// Log, don't fail, if git rev is not available
+		t.Logf("error loading git revision file: %s", err)
+		shortRevHash = []byte("unknown")
 	}
 
 	// Construct feedback data which can be verified later