This repository has been archived by the owner on Nov 20, 2024. It is now read-only.
forked from kubernetes-sigs/cosi-driver-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CI workflows for testing and building COSI
- Added Dockerfile, Makefile and CI workflows - Added tests for DriverInfo in identity server Issue: S3C-9222
- Loading branch information
1 parent
f9b93bd
commit a280c3c
Showing
7 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- '**' | ||
|
||
jobs: | ||
test: | ||
name: Run Tests | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.22.6 | ||
|
||
- name: Install dependencies | ||
run: go mod tidy | ||
|
||
- name: Run tests | ||
run: make test | ||
|
||
dev-container-build: | ||
permissions: | ||
contents: read | ||
packages: write | ||
uses: scality/workflows/.github/workflows/docker-build.yaml@v2 | ||
with: | ||
name: cosi | ||
namespace: ${{ github.repository_owner }} | ||
tag: ${{ github.sha }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Release | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
tag: | ||
description: "Tag to be released (e.g., v1.0.0)" | ||
required: true | ||
jobs: | ||
prod-container-build: | ||
permissions: | ||
contents: read | ||
packages: write | ||
uses: scality/workflows/.github/workflows/docker-build.yaml@v2 | ||
with: | ||
name: cosi | ||
namespace: ${{ github.repository_owner }} | ||
tag: ${{ github.event.inputs.tag }} | ||
|
||
create-github-release: | ||
runs-on: ubuntu-latest | ||
needs: prod-container-build | ||
steps: | ||
- name: Create GitHub Release | ||
uses: softprops/action-gh-release@v2 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ github.event.inputs.tag }} | ||
name: Release ${{ github.event.inputs.tag }} | ||
generate_release_notes: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ release-tools | |
bin | ||
.idea | ||
vendor | ||
*.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM golang:1.22.6 AS builder | ||
|
||
WORKDIR /app | ||
|
||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
# Copy the source code into the container | ||
COPY . . | ||
|
||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o scality-cosi-driver ./cmd/scality-cosi-driver | ||
|
||
FROM gcr.io/distroless/static:latest | ||
COPY --from=builder /app/scality-cosi-driver /scality-cosi-driver | ||
ENTRYPOINT ["/scality-cosi-driver"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
APP_NAME = scality-cosi-driver | ||
|
||
.PHONY: all | ||
all: test build | ||
|
||
.PHONY: build | ||
build: | ||
@echo "Building $(APP_NAME)..." | ||
GOOS=linux GOARCH=amd64 go build -o ./bin/$(APP_NAME) ./cmd/$(APP_NAME) | ||
|
||
.PHONY: test | ||
test: | ||
@echo "Running tests..." | ||
go test ./... -coverprofile=coverage.txt -covermode=atomic | ||
|
||
.PHONY: clean | ||
clean: | ||
@echo "Cleaning up..." | ||
rm -rf ./bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package driver | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
cosiapi "sigs.k8s.io/container-object-storage-interface-spec" | ||
) | ||
|
||
func TestDriverGetInfo(t *testing.T) { | ||
// Define a long provisioner name to reuse in the test cases | ||
longProvisioner := "scality-cosi-driver" + strings.Repeat("x", 1000) | ||
|
||
// Define a table of test cases | ||
tests := []struct { | ||
name string | ||
provisioner string | ||
request *cosiapi.DriverGetInfoRequest | ||
want *cosiapi.DriverGetInfoResponse | ||
wantErr bool | ||
errCode codes.Code | ||
}{ | ||
{ | ||
name: "Valid provisioner name", | ||
provisioner: "scality-cosi-driver", | ||
request: &cosiapi.DriverGetInfoRequest{}, | ||
want: &cosiapi.DriverGetInfoResponse{Name: "scality-cosi-driver"}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Empty provisioner name", | ||
provisioner: "", | ||
request: &cosiapi.DriverGetInfoRequest{}, | ||
want: nil, | ||
wantErr: true, | ||
errCode: codes.InvalidArgument, | ||
}, | ||
{ | ||
name: "Empty request object", | ||
provisioner: "scality-cosi-driver", | ||
request: nil, // Test for nil request to ensure function handles nil input gracefully. | ||
want: &cosiapi.DriverGetInfoResponse{Name: "scality-cosi-driver"}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Long provisioner name", | ||
provisioner: longProvisioner, | ||
request: &cosiapi.DriverGetInfoRequest{}, | ||
want: &cosiapi.DriverGetInfoResponse{Name: longProvisioner}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Provisioner name with special characters", | ||
provisioner: "scality-cosi-driver-ß∂ƒ©", | ||
request: &cosiapi.DriverGetInfoRequest{}, | ||
want: &cosiapi.DriverGetInfoResponse{Name: "scality-cosi-driver-ß∂ƒ©"}, | ||
wantErr: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
// Create identityServer instance | ||
server := newIdentityServer(tt.provisioner) | ||
|
||
// Call DriverGetInfo with provided request | ||
resp, err := server.DriverGetInfo(context.Background(), tt.request) | ||
|
||
// Handle errors and assertions | ||
if tt.wantErr { | ||
assertErrorWithCode(t, err, tt.errCode) | ||
} else { | ||
assert.NoError(t, err) | ||
assert.NotNil(t, resp) | ||
assert.Equal(t, tt.want, resp) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
// Helper function to create identityServer | ||
func newIdentityServer(provisioner string) *identityServer { | ||
return &identityServer{ | ||
provisioner: provisioner, | ||
} | ||
} | ||
|
||
// Helper function to assert error codes | ||
func assertErrorWithCode(t *testing.T, err error, expectedCode codes.Code) { | ||
assert.Error(t, err) | ||
st, _ := status.FromError(err) | ||
assert.Equal(t, expectedCode, st.Code()) | ||
} |