test: Switch to goimports instead of gofmt
see https://github.com/purpleidea/mgmt/pull/256#issuecomment-346360414
This commit is contained in:
committed by
James Shubin
parent
3575d597f7
commit
ac629404f4
4
Makefile
4
Makefile
@@ -124,7 +124,9 @@ test:
|
|||||||
./test.sh
|
./test.sh
|
||||||
|
|
||||||
gofmt:
|
gofmt:
|
||||||
find . -maxdepth 3 -type f -name '*.go' -not -path './old/*' -not -path './tmp/*' -exec gofmt -w {} \;
|
# TODO: remove gofmt once goimports has a -s option
|
||||||
|
find . -maxdepth 3 -type f -name '*.go' -not -path './old/*' -not -path './tmp/*' -exec gofmt -s -w {} \;
|
||||||
|
find . -maxdepth 3 -type f -name '*.go' -not -path './old/*' -not -path './tmp/*' -exec goimports -w {} \;
|
||||||
|
|
||||||
yamlfmt:
|
yamlfmt:
|
||||||
find . -maxdepth 3 -type f -name '*.yaml' -not -path './old/*' -not -path './tmp/*' -not -path './omv.yaml' -exec ruby -e "require 'yaml'; x=YAML.load_file('{}').to_yaml.each_line.map(&:rstrip).join(10.chr)+10.chr; File.open('{}', 'w').write x" \;
|
find . -maxdepth 3 -type f -name '*.yaml' -not -path './old/*' -not -path './tmp/*' -not -path './omv.yaml' -exec ruby -e "require 'yaml'; x=YAML.load_file('{}').to_yaml.each_line.map(&:rstrip).join(10.chr)+10.chr; File.open('{}', 'w').write x" \;
|
||||||
|
|||||||
@@ -44,16 +44,16 @@ func TestInitKindMetrics(t *testing.T) {
|
|||||||
// values are expected and actual count of metrics with
|
// values are expected and actual count of metrics with
|
||||||
// that name.
|
// that name.
|
||||||
expectedMetrics := map[string][2]int{
|
expectedMetrics := map[string][2]int{
|
||||||
"mgmt_checkapply_total": [2]int{
|
"mgmt_checkapply_total": {
|
||||||
16, 0,
|
16, 0,
|
||||||
},
|
},
|
||||||
"mgmt_failures_total": [2]int{
|
"mgmt_failures_total": {
|
||||||
4, 0,
|
4, 0,
|
||||||
},
|
},
|
||||||
"mgmt_failures": [2]int{
|
"mgmt_failures": {
|
||||||
4, 0,
|
4, 0,
|
||||||
},
|
},
|
||||||
"mgmt_resources": [2]int{
|
"mgmt_resources": {
|
||||||
2, 0,
|
2, 0,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -692,7 +692,7 @@ func (obj *AwsEc2Res) CheckApply(apply bool) (checkOK bool, err error) {
|
|||||||
_, err = obj.client.CreateTags(&ec2.CreateTagsInput{
|
_, err = obj.client.CreateTags(&ec2.CreateTagsInput{
|
||||||
Resources: []*string{runResult.Instances[0].InstanceId},
|
Resources: []*string{runResult.Instances[0].InstanceId},
|
||||||
Tags: []*ec2.Tag{
|
Tags: []*ec2.Tag{
|
||||||
&ec2.Tag{
|
{
|
||||||
Key: aws.String("Name"),
|
Key: aws.String("Name"),
|
||||||
Value: aws.String(obj.prependName()),
|
Value: aws.String(obj.prependName()),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -22,9 +22,16 @@ find_files() {
|
|||||||
git ls-files | grep '\.go$'
|
git ls-files | grep '\.go$'
|
||||||
}
|
}
|
||||||
|
|
||||||
GOFMT="gofmt" # we prefer to not use the -s flag, which is pretty annoying...
|
# gofmt -s -l
|
||||||
|
GOFMT="gofmt"
|
||||||
|
bad_files=$(find_files | xargs $GOFMT -s -l)
|
||||||
|
if [[ -n "${bad_files}" ]]; then
|
||||||
|
fail_test "The following golang files are not properly formatted (gofmt -s -l): ${bad_files}"
|
||||||
|
fi
|
||||||
|
#goimports -l
|
||||||
|
GOFMT="goimports"
|
||||||
bad_files=$(find_files | xargs $GOFMT -l)
|
bad_files=$(find_files | xargs $GOFMT -l)
|
||||||
if [[ -n "${bad_files}" ]]; then
|
if [[ -n "${bad_files}" ]]; then
|
||||||
fail_test "The following golang files are not properly formatted: ${bad_files}"
|
fail_test "The following golang files are not properly formatted (goimports -l): ${bad_files}"
|
||||||
fi
|
fi
|
||||||
echo 'PASS'
|
echo 'PASS'
|
||||||
|
|||||||
Reference in New Issue
Block a user