diff options
author | Dario Maiocchi <dmaiocchi@suse.com> | 2017-11-09 19:30:33 +0100 |
---|---|---|
committer | Dario Maiocchi <dmaiocchi@suse.com> | 2017-11-16 11:26:28 +0100 |
commit | a73ae701001ab6f1b66dca0f4e9987998f86913a (patch) | |
tree | abbe840b373098272b68f8271ded9fc586126386 | |
parent | 189901b858338555651fcae7b3638a7f6d697202 (diff) | |
download | terraform-provider-libvirt-a73ae701001ab6f1b66dca0f4e9987998f86913a.tar terraform-provider-libvirt-a73ae701001ab6f1b66dca0f4e9987998f86913a.tar.gz |
golint enablement
-rw-r--r-- | .travis.yml | 6 | ||||
-rwxr-xr-x | travis/golinter.rb | 80 |
2 files changed, 85 insertions, 1 deletions
diff --git a/.travis.yml b/.travis.yml index a33675bc..1652c6f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,10 +7,14 @@ go_import_path: github.com/dmacvicar/terraform-provider-libvirt install: true before_script: - go get github.com/mattn/goveralls + - go get github.com/golang/lint/golint - sudo bash ./travis/setup-host - sudo lxc exec libvirt -- bash /code/travis/setup-guest script: - bash ./travis/gofmtcheck.sh + # golint only on specific files ( others will blacklisted by default) + # we need to solve them one by one. (see the ruby file /travis/golinter.rb) + - travis/golinter.rb - sudo lxc exec libvirt -- bash /code/travis/run-tests-inside-guest - - sudo lxc file pull libvirt/root/go/src/github.com/dmacvicar/terraform-provider-libvirt/profile.cov . + - sudo lxc file pull libvirt/root/go/src/github.com/dmacvicar/terraform-provider-libvirt/libvirt/profile.cov . - goveralls -coverprofile=profile.cov -service=travis-ci diff --git a/travis/golinter.rb b/travis/golinter.rb new file mode 100755 index 00000000..52ed4e6e --- /dev/null +++ b/travis/golinter.rb @@ -0,0 +1,80 @@ +#! /usr/bin/ruby + +require 'English' + +# This list contain all files that are golint correct. (in master branch) +GOLINT_FILES_OK = %w[domain_def_test.go domain_def.go + resource_libvirt_domain_netiface.go + resource_libvirt_domain_console.go + qemu_agent_test.go utils_domain_def.go + libvirt_network_mock_test.go + utils_volume_test.go provider_test.go + utils_net_test.go network_def_test.go + utils_libvirt.go + pool_sync_test.go + volume_def_test.go utils_libvirt_test.go + disk_def_test.go + network_interface_def.go + libvirt_domain_mock_test.go ].freeze + +# FIXME: blacklisted files need to go on GOLINT_FILES_OK once the lint are fixed +# The blacklist is usefull for catch golint error on new files +GOLINT_FILES_BLACKLISTED = %w[stream.go resource_libvirt_network.go + resource_libvirt_volume.go + resource_libvirt_volume_test.go + pool_sync.go + resource_libvirt_coreos_ignition_test.go + libvirt_interfaces.go + utils_test.go network_def.go disk_def.go + resource_libvirt_domain.go utils.go + provider.go resource_cloud_init.go + coreos_ignition_def.go utils_net.go qemu_agent.go + config.go resource_libvirt_coreos_ignition.go + volume_def.go cloudinit_def_test.go + cloudinit_def.go + utils_volume.go + resource_libvirt_domain_test.go ].freeze + +# perform validation of the 2 lists +class Basic + # scripts in blacklist are not cleaned to golint. + # (remove them once you fix one) + # this avoid that you forget + def self.check_blacklist_always_fail + GOLINT_FILES_BLACKLISTED.each do |f| + `golint -set_exit_status #{f}` + raise "GOFILE SHOULD FAIL! #{f}" if $CHILD_STATUS.exitstatus.zero? + end + end + + # check duplicata on two lists: + # a go file cannot be in both lists + def self.check_duplicata + raise 'DUPLICATAS found!!' unless (GOLINT_FILES_BLACKLISTED & + GOLINT_FILES_OK).empty? + end +end + +def error_linter(file) + puts '+' * 30 + puts "GOLINT FAILED for #{file}" + puts '+' * 30 + exit 1 +end + +# Main tests + +Dir.chdir 'libvirt/' +Basic.check_blacklist_always_fail +Basic.check_duplicata + +Dir.foreach('.') do |file| + next if (file == '.') || (file == '..') + next if GOLINT_FILES_BLACKLISTED.include? file + puts "Running golint for file #{file}" + # Debug lint error for fixing them + puts `golint -set_exit_status #{file}` + error_linter(file) if $CHILD_STATUS.exitstatus.nonzero? + puts "GOLINT OK! for #{file} !!!" + puts '*' * 50 +end |