Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to use Go modules #553

Merged
merged 23 commits into from
Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
25 changes: 14 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
dist: trusty
sudo: false
language: go

go:
- 1.9
go_import_path: github.com/dmacvicar/terraform-provider-libvirt
- 1.11.x
env:
- GO111MODULE=on GOFLAGS=-mod=vendor
git:
depth: 1
go_import_path: github.com/dmacvicar/terraform-provider-libvirt
install: true
before_script:
- go get github.com/mattn/goveralls
- go get golang.org/x/lint/golint
- curl -sLo /tmp/terraform.zip https://releases.hashicorp.com/terraform/0.11.10/terraform_0.11.10_linux_amd64.zip
- sudo unzip /tmp/terraform.zip -d /usr/local/bin
addons:
apt:
packages:
- libvirt-dev
- xsltproc
script:
- make gofmtcheck
- make vet
- golint -set_exit_status libvirt/
- curl -sLo /tmp/terraform.zip https://releases.hashicorp.com/terraform/0.11.10/terraform_0.11.10_linux_amd64.zip
- sudo unzip /tmp/terraform.zip -d /usr/local/bin
- travis/validate_terraform_files.sh
- make fmt-check
- make vet-check
- make lint-check
- make tf-check
- make test
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

## Implementation notes

- Creation and update resource. Consider to implement the `update` CRUD of terraform-libvirt of an existing resource and also testing it in testacc.
- Creation and update resource. Consider to implement the `update` CRUD of terraform-libvirt of an existing resource and also testing it in acceptance tests.
For example if an user rerun 2 times a terraform apply with a different parameter, this call will update the existing resource with the new parameter.
This step is not trivial and need some special care on the implementation.
An example of updating a resource in testacc is here: https://github.com/dmacvicar/terraform-provider-libvirt/blob/master/libvirt/resource_libvirt_cloud_init_test.go#L73
An example of updating a resource in acceptance tests is here: https://github.com/dmacvicar/terraform-provider-libvirt/blob/master/libvirt/resource_libvirt_cloud_init_test.go#L73

## Conventions

Expand All @@ -41,7 +41,7 @@ For example the `domain` resource, and others are organized like follow:
- the `domain_def` contains libvirt xml schemas and operation
- `resource_libvirt_domain.go` (contains terraform CRUD operations and call the libvirt_xml)
you can imagine the `resource` file as a sort of "main" file for each resource.
- `resource_libvirt_domain_test.go` ( contains testacc for resource)
- `resource_libvirt_domain_test.go` ( contains acceptance tests for resource)

## Testing

Expand Down Expand Up @@ -77,15 +77,15 @@ Then you can visualize the profile in html format:
go tool cover -html=profile.cov
```

The codecoverage can give you more usefull infos about were you could write a new tests for improving our testacc.
The codecoverage can give you more usefull infos about were you could write a new tests for improving our acceptance tests.

Feel free to read more about this on : https://blog.golang.org/cover.

### Writing acceptance tests:

Take a look at Terraform's docs about [writing acceptance tests](https://github.com/hashicorp/terraform/blob/master/.github/CONTRIBUTING.md#writing-an-acceptance-test).

For resource names etc, use random names with the helper function. Take example from other testacc.
For resource names etc, use random names with the helper function. Take example from other acceptance tests.

## Other learning resources

Expand Down
33 changes: 15 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ TEST_ARGS_DEF := -covermode=count -coverprofile=profile.cov

default: build

build: gofmtcheck golint vet
terraform-provider-libvirt:
go build -ldflags "${LDFLAGS}"

build: fmt-check lint-check vet-check terraform-provider-libvirt

install:
go install -ldflags "${LDFLAGS}"

Expand All @@ -17,7 +19,6 @@ install:
# - run some particular test: make test TEST_ARGS="-run TestAccLibvirtDomain_Cpu"
test:
go test -v $(TEST_ARGS_DEF) $(TEST_ARGS) ./libvirt
go test -v .

# acceptance tests
# usage:
Expand All @@ -32,28 +33,24 @@ test:
# TF_LOG=DEBUG make testacc TEST_ARGS="-run TestAccLibvirtNet*"
#
testacc:
go test -v .
./travis/run-tests-acceptance $(TEST_ARGS)

vet:
@echo "go vet ."
@go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \
echo ""; \
echo "Vet found suspicious constructs. Please check the reported constructs"; \
echo "and fix them if necessary before submitting the code for review."; \
exit 1; \
fi
vet-check:
go vet ./libvirt

golint:
golint ./libvirt
lint-check:
go run golang.org/x/lint/golint -set_exit_status ./libvirt .

gofmtcheck:
bash travis/run-gofmt
fmt-check:
go fmt ./libvirt .

fmt:
(cd libvirt && go fmt .)
tf-check:
terraform fmt -write=false -check=true -diff=true examples/

clean:
rm -f terraform-provider-libvirt

cleanup:
./travis/cleanup.sh

.PHONY: build install test vet fmt golint
.PHONY: build install test testacc vet-check fmt-check lint-check
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ Before building, you will need the following
* latest [golang](https://golang.org/dl/) version
* `cgo` is required by the [libvirt-go](https://github.com/libvirt/libvirt-go) package. `export CGO_ENABLED="1"`

This project uses [glide](https://github.com/Masterminds/glide) to vendor all its
This project uses [go modules](https://github.com/golang/go/wiki/Modules) to vendor all its
dependencies.

You do not have to interact with `glide` since the vendored packages are **already included in the repo**.
You do not have to interact with `modules` since the vendored packages are **already included in the repo**.

Ensure you have the latest version of Go installed on your system, terraform usually
takes advantage of features available only inside of the latest stable release.
Expand All @@ -77,7 +77,15 @@ You need also need libvirt-dev(el) package installed.
```console
go get github.com/dmacvicar/terraform-provider-libvirt
cd $GOPATH/src/github.com/dmacvicar/terraform-provider-libvirt
go install
make
```

If you are using Go >= 1.11, you don't need to build inside GOPATH:

```
export GO111MODULE=on
export GOFLAGS=-mod=vendor
make
```

You will now find the binary at `$GOPATH/bin/terraform-provider-libvirt`.
Expand Down