forked from LaconicNetwork/kompose
Merge pull request #259 from kadel/lint-and-vet
Add `go vet`, and `gofmt` tests.
This commit is contained in:
commit
b0514bd2dd
@ -12,10 +12,14 @@ install:
|
||||
- true
|
||||
|
||||
script:
|
||||
- make validate
|
||||
- make test-unit
|
||||
|
||||
# make test-cmd requires kompose binary
|
||||
- make binary
|
||||
|
||||
# $GOPATH/bin is in $PATH
|
||||
- mkdir -p $GOPATH/bin
|
||||
- cp kompose $GOPATH/bin/
|
||||
|
||||
- make test-unit
|
||||
- make test-cmd
|
||||
|
||||
10
Makefile
10
Makefile
@ -26,6 +26,14 @@ clean:
|
||||
|
||||
test-unit:
|
||||
./script/make.sh test-unit
|
||||
|
||||
test-cmd:
|
||||
./script/make.sh test-cmd
|
||||
|
||||
validate: gofmt vet
|
||||
|
||||
vet:
|
||||
./script/make.sh validate-vet
|
||||
lint:
|
||||
./script/make.sh validate-lint
|
||||
gofmt:
|
||||
./script/make.sh validate-gofmt
|
||||
|
||||
@ -241,7 +241,7 @@ func getTransformer(opt kobject.ConvertOptions) transformer.Transformer {
|
||||
} else {
|
||||
// Create/Init new OpenShift object that is initialized with a newly
|
||||
// created Kubernetes object. Openshift inherits from Kubernetes
|
||||
t = &openshift.OpenShift{kubernetes.Kubernetes{Opt: opt}}
|
||||
t = &openshift.OpenShift{Kubernetes: kubernetes.Kubernetes{Opt: opt}}
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
@ -106,16 +106,16 @@ func TestParseVolume(t *testing.T) {
|
||||
t.Errorf("In test case %q, returned unexpected error %v", test.test, err)
|
||||
}
|
||||
if name != test.name {
|
||||
t.Errorf("In test case %q, returned volume name %s, expected %s", name, test.name)
|
||||
t.Errorf("In test case %q, returned volume name %s, expected %s", test.test, name, test.name)
|
||||
}
|
||||
if host != test.host {
|
||||
t.Errorf("In test case %q, returned host path %s, expected %s", host, test.host)
|
||||
t.Errorf("In test case %q, returned host path %s, expected %s", test.test, host, test.host)
|
||||
}
|
||||
if container != test.container {
|
||||
t.Errorf("In test case %q, returned container path %s, expected %s", container, test.container)
|
||||
t.Errorf("In test case %q, returned container path %s, expected %s", test.test, container, test.container)
|
||||
}
|
||||
if mode != test.mode {
|
||||
t.Errorf("In test case %q, returned access mode %s, expected %s", mode, test.mode)
|
||||
t.Errorf("In test case %q, returned access mode %s, expected %s", test.test, mode, test.mode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,12 +133,12 @@ func (b *Bundle) LoadFile(file string) kobject.KomposeObject {
|
||||
|
||||
buf, err := ioutil.ReadFile(file)
|
||||
if err != nil {
|
||||
logrus.Fatalf("Failed to read bundles file: ", err)
|
||||
logrus.Fatalf("Failed to read bundles file: %s ", err)
|
||||
}
|
||||
reader := strings.NewReader(string(buf))
|
||||
bundle, err := loadFile(reader)
|
||||
if err != nil {
|
||||
logrus.Fatalf("Failed to parse bundles file: ", err)
|
||||
logrus.Fatalf("Failed to parse bundles file: %s", err)
|
||||
}
|
||||
|
||||
for name, service := range bundle.Services {
|
||||
|
||||
@ -245,6 +245,7 @@ func (k *Kubernetes) CreateService(name string, service kobject.ServiceConfig, o
|
||||
svc.Spec.Ports = servicePorts
|
||||
|
||||
svc.Spec.Type = api.ServiceType(service.ServiceType)
|
||||
|
||||
// Configure annotations
|
||||
annotations := transformer.ConfigAnnotations(service)
|
||||
svc.ObjectMeta.Annotations = annotations
|
||||
|
||||
@ -382,7 +382,7 @@ func (k *Kubernetes) Deploy(komposeObject kobject.KomposeObject, opt kobject.Con
|
||||
if !opt.EmptyVols {
|
||||
pvcStr = " and PersistentVolumeClaims "
|
||||
}
|
||||
fmt.Println("We are going to create Kubernetes Deployments, Services" +pvcStr+ "for your Dockerized application. \n" +
|
||||
fmt.Println("We are going to create Kubernetes Deployments, Services" + pvcStr + "for your Dockerized application. \n" +
|
||||
"If you need different kind of resources, use the 'kompose convert' and 'kubectl create -f' commands instead. \n")
|
||||
|
||||
factory := cmdutil.NewFactory(nil)
|
||||
@ -424,7 +424,7 @@ func (k *Kubernetes) Deploy(komposeObject kobject.KomposeObject, opt kobject.Con
|
||||
} else {
|
||||
pvcStr = ""
|
||||
}
|
||||
fmt.Println("\nYour application has been deployed to Kubernetes. You can run 'kubectl get deployment,svc,pods" +pvcStr+ "' for details.")
|
||||
fmt.Println("\nYour application has been deployed to Kubernetes. You can run 'kubectl get deployment,svc,pods" + pvcStr + "' for details.")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -178,7 +178,7 @@ func (o *OpenShift) Deploy(komposeObject kobject.KomposeObject, opt kobject.Conv
|
||||
if !opt.EmptyVols {
|
||||
pvcStr = " and PersistentVolumeClaims "
|
||||
}
|
||||
fmt.Println("We are going to create OpenShift DeploymentConfigs, Services" +pvcStr+ "for your Dockerized application. \n" +
|
||||
fmt.Println("We are going to create OpenShift DeploymentConfigs, Services" + pvcStr + "for your Dockerized application. \n" +
|
||||
"If you need different kind of resources, use the 'kompose convert' and 'oc create -f' commands instead. \n")
|
||||
|
||||
// initialize OpenShift Client
|
||||
@ -238,7 +238,7 @@ func (o *OpenShift) Deploy(komposeObject kobject.KomposeObject, opt kobject.Conv
|
||||
} else {
|
||||
pvcStr = ""
|
||||
}
|
||||
fmt.Println("\nYour application has been deployed to OpenShift. You can run 'oc get dc,svc,is" +pvcStr+ "' for details.")
|
||||
fmt.Println("\nYour application has been deployed to OpenShift. You can run 'oc get dc,svc,is" + pvcStr + "' for details.")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -14,34 +14,5 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
if [ -z "$VALIDATE_UPSTREAM" ]; then
|
||||
# this is kind of an expensive check, so let's not do this twice if we
|
||||
# are running more than one validate bundlescript
|
||||
|
||||
VALIDATE_REPO='https://github.com/kubernetes-incubator/kompose.git'
|
||||
VALIDATE_BRANCH='master'
|
||||
|
||||
if [ "$TRAVIS" = 'true' -a "$TRAVIS_PULL_REQUEST" != 'false' ]; then
|
||||
VALIDATE_REPO="https://github.com/${TRAVIS_REPO_SLUG}.git"
|
||||
VALIDATE_BRANCH="${TRAVIS_BRANCH}"
|
||||
fi
|
||||
|
||||
VALIDATE_HEAD="$(git rev-parse --verify HEAD)"
|
||||
|
||||
git fetch -q "$VALIDATE_REPO" "refs/heads/$VALIDATE_BRANCH"
|
||||
VALIDATE_UPSTREAM="$(git rev-parse --verify FETCH_HEAD)"
|
||||
|
||||
VALIDATE_COMMIT_LOG="$VALIDATE_UPSTREAM..$VALIDATE_HEAD"
|
||||
VALIDATE_COMMIT_DIFF="$VALIDATE_UPSTREAM...$VALIDATE_HEAD"
|
||||
|
||||
validate_diff() {
|
||||
if [ "$VALIDATE_UPSTREAM" != "$VALIDATE_HEAD" ]; then
|
||||
git diff "$VALIDATE_COMMIT_DIFF" "$@"
|
||||
fi
|
||||
}
|
||||
validate_log() {
|
||||
if [ "$VALIDATE_UPSTREAM" != "$VALIDATE_HEAD" ]; then
|
||||
git log "$VALIDATE_COMMIT_LOG" "$@"
|
||||
fi
|
||||
}
|
||||
fi
|
||||
# all Kompose packages (skip vendor dir)
|
||||
PKGS=$( go list -e ./... | grep -v '/vendor/' )
|
||||
|
||||
@ -25,10 +25,6 @@ DEFAULT_BUNDLES=(
|
||||
validate-lint
|
||||
validate-vet
|
||||
binary
|
||||
|
||||
# test-unit
|
||||
# test-integration
|
||||
# test-acceptance
|
||||
)
|
||||
bundle() {
|
||||
local bundle="$1"; shift
|
||||
|
||||
@ -16,29 +16,24 @@
|
||||
|
||||
source "$(dirname "$BASH_SOURCE")/.validate"
|
||||
|
||||
IFS=$'\n'
|
||||
files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/' || true) )
|
||||
unset IFS
|
||||
GO_FILES=$(find . -path ./vendor -prune -o -name '*.go' -print )
|
||||
|
||||
badFiles=()
|
||||
for f in "${files[@]}"; do
|
||||
# we use "git show" here to validate that what's committed is formatted
|
||||
if [ "$(git show "$VALIDATE_HEAD:$f" | gofmt -s -l)" ]; then
|
||||
badFiles+=( "$f" )
|
||||
|
||||
for file in $GO_FILES; do
|
||||
gofmtOutput=$(gofmt -l "$file")
|
||||
if [ "$gofmtOutput" ]; then
|
||||
errors+=("$gofmtOutput")
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${#badFiles[@]} -eq 0 ]; then
|
||||
echo 'Congratulations! All Go source files are properly formatted.'
|
||||
|
||||
|
||||
if [ ${#errors[@]} -eq 0 ]; then
|
||||
echo "gofmt OK"
|
||||
else
|
||||
{
|
||||
echo "These files are not properly gofmt'd:"
|
||||
for f in "${badFiles[@]}"; do
|
||||
echo " - $f"
|
||||
echo "gofmt ERROR - These files are not formated by gofmt:"
|
||||
for err in "${errors[@]}"; do
|
||||
echo "$err"
|
||||
done
|
||||
echo
|
||||
echo 'Please reformat the above files using "gofmt -s -w" and commit the result.'
|
||||
echo
|
||||
} >&2
|
||||
false
|
||||
exit 1
|
||||
fi
|
||||
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||
#
|
||||
@ -16,33 +17,21 @@
|
||||
|
||||
source "$(dirname "$BASH_SOURCE")/.validate"
|
||||
|
||||
# We will eventually get to the point where packages should be the complete list
|
||||
# of subpackages, vendoring excluded, as given by:
|
||||
#
|
||||
IFS=$'\n'
|
||||
files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/\|^integration' || true) )
|
||||
unset IFS
|
||||
|
||||
errors=()
|
||||
for f in "${files[@]}"; do
|
||||
# we use "git show" here to validate that what's committed passes go lint
|
||||
failedLint=$(golint "$f")
|
||||
if [ "$failedLint" ]; then
|
||||
errors+=( "$failedLint" )
|
||||
for pkg in $PKGS; do
|
||||
lintOutput=$(golint "$pkg")
|
||||
# if lineOutput is not empty, save it to errros array
|
||||
if [ "$lintOutput" ]; then
|
||||
errors+=("$lintOutput")
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
if [ ${#errors[@]} -eq 0 ]; then
|
||||
echo 'Congratulations! All Go source files have been linted.'
|
||||
echo "golint OK"
|
||||
else
|
||||
{
|
||||
echo "Errors from golint:"
|
||||
echo "golint ERRORS:"
|
||||
for err in "${errors[@]}"; do
|
||||
echo "$err"
|
||||
done
|
||||
echo
|
||||
echo 'Please fix the above errors. You can test via "golint" and commit the result.'
|
||||
echo
|
||||
} >&2
|
||||
false
|
||||
exit 1
|
||||
fi
|
||||
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||
#
|
||||
@ -16,31 +17,5 @@
|
||||
|
||||
source "$(dirname "$BASH_SOURCE")/.validate"
|
||||
|
||||
IFS=$'\n'
|
||||
files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/' || true) )
|
||||
unset IFS
|
||||
go vet $PKGS;
|
||||
|
||||
errors=()
|
||||
for f in "${files[@]}"; do
|
||||
# we use "git show" here to validate that what's committed passes go vet
|
||||
failedVet=$(go vet "$f")
|
||||
if [ "$failedVet" ]; then
|
||||
errors+=( "$failedVet" )
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
if [ ${#errors[@]} -eq 0 ]; then
|
||||
echo 'Congratulations! All Go source files have been vetted.'
|
||||
else
|
||||
{
|
||||
echo "Errors from go vet:"
|
||||
for err in "${errors[@]}"; do
|
||||
echo " - $err"
|
||||
done
|
||||
echo
|
||||
echo 'Please fix the above errors. You can test via "go vet" and commit the result.'
|
||||
echo
|
||||
} >&2
|
||||
false
|
||||
fi
|
||||
|
||||
Loading…
Reference in New Issue
Block a user