Skip to content

Commit

Permalink
Merge pull request #106 from Charliekenney23/github-actions
Browse files Browse the repository at this point in the history
add Github Action workflow for unit tests
  • Loading branch information
0xch4z authored Feb 9, 2022
2 parents bd48a30 + 7497e88 commit d2a6c52
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 170 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Test
on:
push:
branches:
- master
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- name: lint
run: make lint
- name: build
run: make docker-build
- name: unit test
run: make test
66 changes: 22 additions & 44 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,24 @@
run:
tests: false

linters-settings:
errcheck:
check-type-assertions: true
check-blank: true

govet:
check-shadowing: true

enable:
- atomicalign
enable-all: false
disable:
- shadow
disable-all: false
golint:
min-confidence: 0.8
gocyclo:
min-complexity: 30
gocognit:
min-complexity: 30
maligned:
suggest-new: true
dupl:
threshold: 100

linters:
enable-all: true
enable:
- gofmt
- goimports
- structcheck
- varcheck
- staticcheck
- unconvert
- revive
- ineffassign
- vet
- unused
- misspell
disable:
- vetshadow
- gocyclo
- unparam
- nakedret
- lll
- dupl
- gosec
- gochecknoinits
- gochecknoglobals
- wsl
- gomnd
- godot
- goerr113
- nestif
fast: false
- errcheck

run:
tests: false
timeout: 8m
skip-dirs:
- api
- design
- docs
- docs/man
38 changes: 0 additions & 38 deletions .travis.yml

This file was deleted.

25 changes: 9 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,23 @@ clean:
go clean .
rm -r dist/*

$(GOPATH)/bin/goimports:
GO111MODULE=off go get golang.org/x/tools/cmd/goimports

$(GOPATH)/bin/ginkgo:
GO111MODULE=off go get -u github.com/onsi/ginkgo/ginkgo

.PHONY: codegen
codegen:
go generate ./...

.PHONY: vet
# lint the codebase
vet:
go vet . ./cloud/...
.PHONY: lint
lint:
docker run --rm -v "$(shell pwd):/var/work:ro" -w /var/work \
golangci/golangci-lint:v1.44.0 golangci-lint run -v --timeout=5m

.PHONY: fmt
# goimports runs a go fmt
# we say code is not worth formatting unless it's linted
fmt: vet $(GOPATH)/bin/goimports
goimports -w *.go cloud
fmt:
go fmt ./...

.PHONY: test
# we say code is not worth testing unless it's formatted
test: $(GOPATH)/bin/ginkgo fmt codegen
ginkgo -r --v --progress --trace --cover --skipPackage=test $(TEST_ARGS)
test: fmt codegen
go test -v -cover ./cloud/... $(TEST_ARGS)

.PHONY: build-linux
build-linux: codegen
Expand Down Expand Up @@ -83,3 +75,4 @@ run-debug: build
--kubeconfig=${KUBECONFIG} \
--linodego-debug


2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Kubernetes Cloud Controller Manager for Linode

[![Go Report Card](https://goreportcard.com/badge/github.com/linode/linode-cloud-controller-manager)](https://goreportcard.com/report/github.com/linode/linode-cloud-controller-manager)
[![Build Status](https://travis-ci.com/linode/linode-cloud-controller-manager.svg?branch=master)](https://travis-ci.com/linode/linode-cloud-controller-manager)
[![Test](https://github.com/linode/linode-cloud-controller-manager/actions/workflows/test.yml/badge.svg)](https://github.com/linode/linode-cloud-controller-manager/actions/workflows/test.yml)
[![Coverage Status](https://coveralls.io/repos/github/linode/linode-cloud-controller-manager/badge.svg?branch=master)](https://coveralls.io/github/linode/linode-cloud-controller-manager?branch=master)
[![Docker Pulls](https://img.shields.io/docker/pulls/linode/linode-cloud-controller-manager.svg)](https://hub.docker.com/r/linode/linode-cloud-controller-manager/)
<!-- [![Slack](http://slack.kubernetes.io/badge.svg)](http://slack.kubernetes.io/#linode) -->
Expand Down
8 changes: 4 additions & 4 deletions cloud/linode/client.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package linode

//go:generate go run github.com/golang/mock/mockgen -destination mock_client_test.go -package linode github.com/linode/linode-cloud-controller-manager/cloud/linode LinodeClient
//go:generate go run github.com/golang/mock/mockgen -destination mock_client_test.go -package linode github.com/linode/linode-cloud-controller-manager/cloud/linode Client

import (
"context"

"github.com/linode/linodego"
)

type LinodeClient interface {
type Client interface {
GetInstance(context.Context, int) (*linodego.Instance, error)
ListInstances(context.Context, *linodego.ListOptions) ([]linodego.Instance, error)
GetInstanceIPAddresses(context.Context, int) (*linodego.InstanceIPAddressResponse, error)
Expand All @@ -25,5 +25,5 @@ type LinodeClient interface {
RebuildNodeBalancerConfig(context.Context, int, int, linodego.NodeBalancerConfigRebuildOptions) (*linodego.NodeBalancerConfig, error)
}

// linodego.Client implements LinodeClient
var _ LinodeClient = (*linodego.Client)(nil)
// linodego.Client implements Client
var _ Client = (*linodego.Client)(nil)
2 changes: 1 addition & 1 deletion cloud/linode/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var Options struct {
}

type linodeCloud struct {
client LinodeClient
client Client
instances cloudprovider.Instances
zones cloudprovider.Zones
loadbalancers cloudprovider.LoadBalancer
Expand Down
7 changes: 3 additions & 4 deletions cloud/linode/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"

"github.com/linode/linodego"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/types"
cloudprovider "k8s.io/cloud-provider"
)
Expand Down Expand Up @@ -38,7 +37,7 @@ func linodeFilterListOptions(targetLabel string) *linodego.ListOptions {
return linodego.NewListOptions(0, jsonFilter)
}

func linodeByName(ctx context.Context, client LinodeClient, nodeName types.NodeName) (*linodego.Instance, error) {
func linodeByName(ctx context.Context, client Client, nodeName types.NodeName) (*linodego.Instance, error) {
linodes, err := client.ListInstances(ctx, linodeFilterListOptions(string(nodeName)))
if err != nil {
return nil, err
Expand All @@ -47,13 +46,13 @@ func linodeByName(ctx context.Context, client LinodeClient, nodeName types.NodeN
if len(linodes) == 0 {
return nil, cloudprovider.InstanceNotFound
} else if len(linodes) > 1 {
return nil, errors.New(fmt.Sprintf("Multiple instances found with name %v", nodeName))
return nil, fmt.Errorf("Multiple instances found with name %v", nodeName)
}

return &linodes[0], nil
}

func linodeByID(ctx context.Context, client LinodeClient, id int) (*linodego.Instance, error) {
func linodeByID(ctx context.Context, client Client, id int) (*linodego.Instance, error) {
instance, err := client.GetInstance(ctx, id)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions cloud/linode/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
)

type instances struct {
client LinodeClient
client Client
}

func newInstances(client LinodeClient) cloudprovider.Instances {
func newInstances(client Client) cloudprovider.Instances {
return &instances{client}
}

Expand Down
12 changes: 6 additions & 6 deletions cloud/linode/instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestInstanceExistsByProviderID(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

client := NewMockLinodeClient(ctrl)
client := NewMockClient(ctrl)
instances := newInstances(client)

t.Run("should propagate generic api error", func(t *testing.T) {
Expand Down Expand Up @@ -64,7 +64,7 @@ func TestNodeAddresses(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

client := NewMockLinodeClient(ctrl)
client := NewMockClient(ctrl)
instances := newInstances(client)

t.Run("errors when linode does not exist", func(t *testing.T) {
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestNodeAddressesByProviderID(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

client := NewMockLinodeClient(ctrl)
client := NewMockClient(ctrl)
instances := newInstances(client)

t.Run("fails on malformed providerID", func(t *testing.T) {
Expand Down Expand Up @@ -207,7 +207,7 @@ func TestInstanceID(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

client := NewMockLinodeClient(ctrl)
client := NewMockClient(ctrl)
instances := newInstances(client)

t.Run("fails when instance not found", func(t *testing.T) {
Expand Down Expand Up @@ -239,7 +239,7 @@ func TestInstanceType(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

client := NewMockLinodeClient(ctrl)
client := NewMockClient(ctrl)
instances := newInstances(client)

t.Run("fails when instance not found", func(t *testing.T) {
Expand Down Expand Up @@ -272,7 +272,7 @@ func TestInstanceTypeByProviderID(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

client := NewMockLinodeClient(ctrl)
client := NewMockClient(ctrl)
instances := newInstances(client)

t.Run("fails when instance not found", func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions cloud/linode/loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (e lbNotFoundError) Error() string {
}

type loadbalancers struct {
client LinodeClient
client Client
zone string

kubeClient kubernetes.Interface
Expand All @@ -81,7 +81,7 @@ type portConfig struct {
}

// newLoadbalancers returns a cloudprovider.LoadBalancer whose concrete type is a *loadbalancer.
func newLoadbalancers(client LinodeClient, zone string) cloudprovider.LoadBalancer {
func newLoadbalancers(client Client, zone string) cloudprovider.LoadBalancer {
return &loadbalancers{client: client, zone: zone}
}

Expand Down
Loading

0 comments on commit d2a6c52

Please sign in to comment.