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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: nutanix_guest_tools attributes #43

Merged
merged 5 commits into from
Apr 18, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ linters:
# waiting on terraform/hashi to let us know how they want us to changle those errors
# see Error return value of `d.Set` is not checked (errcheck)
- typecheck
- gosec
- gochecknoinits
- gochecknoglobals

issues:
exclude:
Expand Down
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
dist: trusty
dist: xenial
sudo: required
services:
- docker
language: go
go:
- "1.11.x"
- "1.12.x"

git:
depth: 1


go_import_path: github.com/terraform-providers/terraform-provider-nutanix

install:
# This script is used by the Travis build to install a cookie for
# go.googlesource.com so rate limits are higher when using `go get` to fetch
Expand Down
24 changes: 9 additions & 15 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,31 @@ build: fmtcheck
go install

test: fmtcheck
go test -i $(TEST) || exit 1
echo $(TEST) | \
xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4
go test $(TEST) -timeout=30s -parallel=4

testacc: fmtcheck
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m -coverprofile c.out
go tool cover -html=c.out

fmt:
@echo "==> Fixing source code with gofmt..."
gofmt -s -w ./$(PKG_NAME)
goimports -s -w ./$(PKG_NAME)
goimports -s -w ./client
goimports -s -w ./utils

fmtcheck:
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"

errcheck:
@sh -c "'$(CURDIR)/scripts/errcheck.sh'"

lint:
lint: fmtcheck
@echo "==> Checking source code against linters..."
# @gometalinter ./$(PKG_NAME)
$(GOPATH)/bin/golangci-lint run
@GOGC=30 golangci-lint run

tools:
GO111MODULE=off curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $(GOPATH)/bin v1.9.3
GO111MODULE=off go get -u github.com/alecthomas/gometalinter
GO111MODULE=off gometalinter --install
GO111MODULE=off go get -u github.com/client9/misspell/cmd/misspell
GO111MODULE=off go get -u github.com/golangci/golangci-lint/cmd/golangci-lint


vet:
Expand Down Expand Up @@ -69,10 +67,6 @@ cibuild:
citest:
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m -coverprofile c.out

extrasanity:
echo "==>sanity: golangci-lint"
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $(GOPATH)/bin v1.9.3
$(GOPATH)/bin/golangci-lint run

website:
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
Expand All @@ -94,4 +88,4 @@ endif

.NOTPARALLEL:

.PHONY: default build test testacc fmt fmtcheck errcheck lint tools vet test-compile cibuild citest extrasanity website website-lint website-test
.PHONY: default build test testacc fmt fmtcheck errcheck lint tools vet test-compile cibuild citest website website-lint website-test
44 changes: 20 additions & 24 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,14 @@ import (
"testing"
)

var (
mux *http.ServeMux
func setup() (*http.ServeMux, *Client, *httptest.Server) {
mux := http.NewServeMux()
server := httptest.NewServer(mux)

ctx = context.TODO()

client *Client

server *httptest.Server
)

func setup() {
mux = http.NewServeMux()
server = httptest.NewServer(mux)

client, _ = NewClient(&Credentials{"", "username", "password", "", "", true, ""})
client, _ := NewClient(&Credentials{"", "username", "password", "", "", true, ""})
client.BaseURL, _ = url.Parse(server.URL)
}

func teardown() {
server.Close()
return mux, client, server
}

func TestNewClient(t *testing.T) {
Expand Down Expand Up @@ -62,7 +50,7 @@ func TestNewRequest(t *testing.T) {
inURL, outURL := "/foo", fmt.Sprintf(defaultBaseURL+absolutePath+"/foo", "foo.com")
inBody, outBody := map[string]interface{}{"name": "bar"}, `{"name":"bar"}`+"\n"

req, _ := c.NewRequest(ctx, http.MethodPost, inURL, inBody)
req, _ := c.NewRequest(context.TODO(), http.MethodPost, inURL, inBody)

// test relative URL was expanded
if req.URL.String() != outURL {
Expand Down Expand Up @@ -128,8 +116,9 @@ func TestCheckResponse(t *testing.T) {
}

func TestDo(t *testing.T) {
setup()
defer teardown()
ctx := context.TODO()
mux, client, server := setup()
defer server.Close()

type foo struct {
A string
Expand Down Expand Up @@ -159,8 +148,9 @@ func TestDo(t *testing.T) {
}

func TestDo_httpError(t *testing.T) {
setup()
defer teardown()
ctx := context.TODO()
mux, client, server := setup()
defer server.Close()

mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Bad Request", 400)
Expand All @@ -177,8 +167,9 @@ func TestDo_httpError(t *testing.T) {
// / Test handling of an error caused by the internal http client's Do()
// function.
func TestDo_redirectLoop(t *testing.T) {
setup()
defer teardown()
ctx := context.TODO()
mux, client, server := setup()
defer server.Close()

mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/", http.StatusFound)
Expand Down Expand Up @@ -266,6 +257,7 @@ func TestClient_NewRequest(t *testing.T) {
// TODO: Add test cases.
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
c := &Client{
Credentials: tt.fields.Credentials,
Expand Down Expand Up @@ -310,6 +302,7 @@ func TestClient_NewUploadRequest(t *testing.T) {
// TODO: Add test cases.
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
c := &Client{
Credentials: tt.fields.Credentials,
Expand Down Expand Up @@ -349,6 +342,7 @@ func TestClient_OnRequestCompleted(t *testing.T) {
// TODO: Add test cases.
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
c := &Client{
Credentials: tt.fields.Credentials,
Expand Down Expand Up @@ -384,6 +378,7 @@ func TestClient_Do(t *testing.T) {
// TODO: Add test cases.
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
c := &Client{
Credentials: tt.fields.Credentials,
Expand Down Expand Up @@ -412,6 +407,7 @@ func Test_fillStruct(t *testing.T) {
// TODO: Add test cases.
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
if err := fillStruct(tt.args.data, tt.args.result); (err != nil) != tt.wantErr {
t.Errorf("fillStruct() error = %v, wantErr %v", err, tt.wantErr)
Expand Down
Loading