Explorar o código

CI: linters and fixes

Signed-off-by: Andrea Barberio <insomniac@slackware.it>
Andrea Barberio %!s(int64=6) %!d(string=hai) anos
pai
achega
c54b03d33a
Modificáronse 6 ficheiros con 33 adicións e 18 borrados
  1. 19 4
      .travis.yml
  2. 5 0
      .travis/linters.sh
  3. 4 1
      .travis/tests.sh
  4. 0 6
      cmds/coredhcp/main.go
  5. 0 1
      plugins/file/plugin.go
  6. 5 6
      plugins/plugin.go

+ 19 - 4
.travis.yml

@@ -3,21 +3,36 @@ language: go
 sudo: required
 
 go:
-  - "1.9"
-  - "1.10"
   - "1.11"
+  - "1.12"
   - tip
 
+env:
+  - TEST_SUITE=unit
+  - TEST_SUITE=linters
+
 before_install:
   - go get -t -v ./...
+  - go get -t -v github.com/stretchr/testify/...
 
 before_script:
   - if [ "${TRAVIS_OS_NAME}" == "linux" ]; then
       sudo sh -c 'echo 0 > /proc/sys/net/ipv6/conf/all/disable_ipv6';
     fi
 
-script:
-  - ./.travis/tests.sh
+script: |
+  set -x
+  case $TEST_SUITE in
+  unit)
+      ./.travis/tests.sh
+      ;;
+  linters)
+      ./.travis/linters.sh
+      ;;
+  *)
+      echo "[!] Unknown test suite: ${TEST_SUITE}. Exiting."
+      exit 1
+  esac
 
 after_success:
   - bash <(curl -s https://codecov.io/bash)

+ 5 - 0
.travis/linters.sh

@@ -0,0 +1,5 @@
+#!/usr/bin/env bash
+
+go get github.com/golangci/golangci-lint/cmd/golangci-lint
+go install github.com/golangci/golangci-lint/cmd/golangci-lint
+golangci-lint run

+ 4 - 1
.travis/tests.sh

@@ -12,6 +12,9 @@ for d in $(go list ./... | grep -v vendor); do
         cat profile.out >> coverage.txt
         rm profile.out
     fi
+done
+
+for d in $(go list -tags=integration ./... | grep -v vendor); do
     # integration tests
     go test -c -tags=integration -race -coverprofile=profile.out -covermode=atomic $d
     testbin="./$(basename $d).test"
@@ -19,6 +22,6 @@ for d in $(go list ./... | grep -v vendor); do
     test -x "${testbin}" && sudo "./${testbin}"
     if [ -f profile.out ]; then
         cat profile.out >> coverage.txt
-        rm profile.out
+        rm -f profile.out
     fi
 done

+ 0 - 6
cmds/coredhcp/main.go

@@ -10,12 +10,6 @@ import (
 	_ "github.com/coredhcp/coredhcp/plugins/server_id"
 )
 
-// Application variables
-var (
-	AppName    = "CoreDHCP"
-	AppVersion = "v0.1"
-)
-
 func main() {
 	logger := logger.GetLogger()
 	config, err := config.Load()

+ 0 - 1
plugins/file/plugin.go

@@ -30,7 +30,6 @@ var (
 	DHCPv6Records map[string]net.IP
 	DHCPv4Records map[string]net.IP
 )
-var serverID *dhcpv6.OptServerId
 
 // LoadDHCPv6Records loads the DHCPv6Records global map with records stored on
 // the specified file. The records have to be one per line, a mac address and an

+ 5 - 6
plugins/plugin.go

@@ -1,8 +1,6 @@
 package plugins
 
 import (
-	"fmt"
-
 	"github.com/coredhcp/coredhcp/handler"
 	"github.com/coredhcp/coredhcp/logger"
 )
@@ -19,7 +17,7 @@ type Plugin struct {
 }
 
 // RegisteredPlugins maps a plugin name to a Plugin instance.
-var RegisteredPlugins = make(map[string]*Plugin, 0)
+var RegisteredPlugins = make(map[string]*Plugin)
 
 // SetupFunc6 defines a plugin setup function for DHCPv6
 type SetupFunc6 func(args ...string) (handler.Handler6, error)
@@ -28,10 +26,12 @@ type SetupFunc6 func(args ...string) (handler.Handler6, error)
 type SetupFunc4 func(args ...string) (handler.Handler4, error)
 
 // RegisterPlugin registers a plugin by its name and setup functions.
-func RegisterPlugin(name string, setup6 SetupFunc6, setup4 SetupFunc4) error {
+func RegisterPlugin(name string, setup6 SetupFunc6, setup4 SetupFunc4) {
 	log.Printf("Registering plugin \"%s\"", name)
 	if _, ok := RegisteredPlugins[name]; ok {
-		return fmt.Errorf("Plugin \"%s\" already registered", name)
+		// TODO this highlights that asking the plugins to register themselves
+		// is not the right approach. Need to register them in the main program.
+		log.Panicf("Plugin '%s' is already registered", name)
 	}
 	plugin := Plugin{
 		Name:   name,
@@ -39,5 +39,4 @@ func RegisterPlugin(name string, setup6 SetupFunc6, setup4 SetupFunc4) error {
 		Setup4: setup4,
 	}
 	RegisteredPlugins[name] = &plugin
-	return nil
 }