Skip to content

Commit

Permalink
update Makefile with vet, fmt and unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Jiffin Tony Thottan <[email protected]>
  • Loading branch information
thotz committed Jul 18, 2023
1 parent ec6e275 commit fed3305
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 8 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/test-golang.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
name: Run Golang tests

# yamllint disable-line rule:truthy
on:
pull_request:
branches:
- "*"

jobs:
make_test:
name: make_test
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3

- name: Set up Golang
uses: actions/setup-go@v4
with:
go-version: "1.20"

- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
version: '3.19.6'

- name: Run "make vet"
run: make vet

- name: Run "make fmt"
run: make fmt

- name: Run "make test"
run: make test

- name: Show the uncommitted "git diff"
if: ${{ failure() }}
run: git diff ; false
24 changes: 21 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

CMDS=ceph-cosi-driver

REGISTRY_NAME=quay.io/cephcosi
IMAGE_TAGS=canary
REGISTRY_NAME=quay.io/ceph/cosi
IMAGE_TAGS=latest

all: build

Expand Down Expand Up @@ -55,6 +55,12 @@ IMAGE_NAME=$(REGISTRY_NAME)/$*

ARCH := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH))

# detect container tools, prefer Podman over Docker
CONTAINER_CMD ?= $(shell podman version >/dev/null 2>&1 && echo podman)
ifeq ($(CONTAINER_CMD),)
CONTAINER_CMD = $(shell docker version >/dev/null 2>&1 && echo docker)
endif

# Specific packages can be excluded from each of the tests below by setting the *_FILTER_CMD variables
# to something like "| grep -v 'github.com/kubernetes-csi/project/pkg/foobar'". See usage below.

Expand All @@ -67,10 +73,22 @@ build-%:
fi

container-%: build-%
docker build -t $*:latest -f $(shell if [ -e ./cmd/$*/Dockerfile ]; then echo ./cmd/$*/Dockerfile; else echo Dockerfile; fi) --label revision=$(REV) .
$(CONTAINER_CMD) build -t $*:latest -f $(shell if [ -e ./cmd/$*/Dockerfile ]; then echo ./cmd/$*/Dockerfile; else echo Dockerfile; fi) --label revision=$(REV) .

build: $(CMDS:%=build-%)
container: $(CMDS:%=container-%)

clean:
-rm -rf bin

.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...

.PHONY: vet
vet: ## Run go vet against code.
go vet ./...

.PHONY: test
test: ## Run unit tests against code.
go test ./... -coverprofile=coverage.txt -covermode=atomic
1 change: 1 addition & 0 deletions pkg/driver/identityserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
type identityServer struct {
provisioner string
}

var _ cosispec.IdentityServer = &identityServer{}

func NewIdentityServer(provisionerName string) (cosispec.IdentityServer, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/driver/mockclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ func (m mockS3Client) PutBucketPolicy(input *s3.PutBucketPolicyInput) (*s3.PutBu
func (m mockS3Client) GetBucketPolicy(input *s3.GetBucketPolicyInput) (*s3.GetBucketPolicyOutput, error) {
switch *input.Bucket {
case "test-bucket":
policy := `{"Version":"2012-10-17","Statement":[{"Sid":"AddPerm","Effect":"Allow","Principal":"*","Action":["s3:GetObject"],"Resource":["arn:aws:s3:::test-bucket/*"]}]}`
policy := `{"Version":"2012-10-17","Statement":[{"Sid":"AddPerm","Effect":"Allow","Principal":"*","Action":["s3:GetObject"],"Resource":["arn:aws:s3:::test-bucket/*"]}]}`
return &s3.GetBucketPolicyOutput{Policy: &policy}, nil
case "test-bucket-fail-internal":
return nil, awserr.New("InternalError", "InternalError", nil)
}
return nil, awserr.New("NoSuchBucket", "NoSuchBucket", nil)
}
}
2 changes: 1 addition & 1 deletion pkg/util/s3client/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
You may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
3 changes: 1 addition & 2 deletions pkg/util/s3client/s3-handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func NewS3Agent(accessKey, secretKey, endpoint string, tlsCert []byte, debug boo
if strings.HasPrefix(endpoint, "https") && len(tlsCert) == 0 {
insecure = true
}
if len(tlsCert) > 0 || insecure{
if len(tlsCert) > 0 || insecure {
tlsEnabled = true
client.Transport = buildTransportTLS(tlsCert, insecure)
}
Expand All @@ -80,7 +80,6 @@ func NewS3Agent(accessKey, secretKey, endpoint string, tlsCert []byte, debug boo
}, nil
}


// CreateBucket creates a bucket with the given name
func (s *S3Agent) CreateBucketNoInfoLogging(name string) error {
return s.createBucket(name, false)
Expand Down

0 comments on commit fed3305

Please sign in to comment.