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
- Update GO version to 1.23.2 - Added Dockerfile, Makefile and CI workflows - Added tests for DriverInfo in identity server using Ginkgo Issue: S3C-9222
- Loading branch information
1 parent
f9b93bd
commit 45bc875
Showing
9 changed files
with
244 additions
and
5 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,40 @@ | ||
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.23.2 | ||
|
||
# Install Ginkgo CLI | ||
- name: Install Ginkgo CLI | ||
run: go install github.com/onsi/ginkgo/v2/ginkgo@latest | ||
|
||
- 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,32 @@ | ||
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: ${{ 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: | ||
target_commitish: ${{ github.sha }} | ||
tag_name: ${{ inputs.tag }} | ||
name: Release ${{ 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 | ||
coverage.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,18 @@ | ||
FROM golang:1.23.2 AS builder | ||
|
||
WORKDIR /app | ||
|
||
ENV CGO_ENABLED=0 \ | ||
GOOS=linux \ | ||
GOARCH=amd64 | ||
|
||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
COPY . . | ||
|
||
RUN 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 | ||
BIN_DIR = ./bin | ||
|
||
.PHONY: all build test clean | ||
|
||
all: test build | ||
|
||
build: | ||
@echo "Building $(APP_NAME)..." | ||
go build -o $(BIN_DIR)/$(APP_NAME) ./cmd/$(APP_NAME) | ||
|
||
test: | ||
@echo "Running Ginkgo tests..." | ||
# Running Ginkgo tests recursively (-r) with verbose output (-v) | ||
ginkgo -r -v --cover --coverprofile=coverage.txt | ||
|
||
clean: | ||
@echo "Cleaning up..." | ||
rm -rf $(BIN_DIR) |
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
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,13 @@ | ||
package driver_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestCosiDev(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Driver Suite") | ||
} |
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,90 @@ | ||
package driver_test | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/scality/cosi/pkg/driver" | ||
|
||
cosiapi "sigs.k8s.io/container-object-storage-interface-spec" | ||
) | ||
|
||
var _ = Describe("Identity Server DriverGetInfo", func() { | ||
Context("with valid provisioner names", func() { | ||
var ( | ||
request *cosiapi.DriverGetInfoRequest | ||
server cosiapi.IdentityServer | ||
err error | ||
) | ||
|
||
// Helper function to initialize the server with the given provisioner and perform DriverGetInfo | ||
initAndGetInfo := func(provisionerName string) (*cosiapi.DriverGetInfoResponse, error) { | ||
server, err = driver.InitIdentityServer(provisionerName) | ||
Expect(err).ToNot(HaveOccurred()) | ||
return server.DriverGetInfo(context.Background(), request) | ||
} | ||
|
||
BeforeEach(func() { | ||
request = &cosiapi.DriverGetInfoRequest{} | ||
}) | ||
|
||
It("should return default driver name info", func() { | ||
provisionerName := "scality-cosi-driver" | ||
resp, err := initAndGetInfo(provisionerName) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(resp).ToNot(BeNil()) | ||
Expect(resp.Name).To(Equal(provisionerName)) | ||
}) | ||
|
||
It("should return a long driver name info", func() { | ||
provisionerName := "scality-cosi-driver" + strings.Repeat("x", 1000) | ||
resp, err := initAndGetInfo(provisionerName) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(resp).ToNot(BeNil()) | ||
Expect(resp.Name).To(Equal(provisionerName)) | ||
}) | ||
|
||
It("should return driver name info containing special characters", func() { | ||
provisionerName := "scality-cosi-driver-ß∂ƒ©" | ||
resp, err := initAndGetInfo(provisionerName) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(resp).ToNot(BeNil()) | ||
Expect(resp.Name).To(Equal(provisionerName)) | ||
}) | ||
}) | ||
|
||
Context("with invalid provisioner names", func() { | ||
var ( | ||
err error | ||
) | ||
|
||
It("should return an error for empty driver name", func() { | ||
_, err = driver.InitIdentityServer("") | ||
Expect(err).To(HaveOccurred()) | ||
Expect(err.Error()).To(Equal("driver name must not be empty")) | ||
}) | ||
}) | ||
|
||
// For now no use of request object in DriverInfo | ||
// Test to ensure intentional changes in the future | ||
Context("with nil request object", func() { | ||
var ( | ||
server cosiapi.IdentityServer | ||
err error | ||
) | ||
|
||
BeforeEach(func() { | ||
server, err = driver.InitIdentityServer("scality-cosi-driver") | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
|
||
It("should handle nil request gracefully", func() { | ||
resp, err := server.DriverGetInfo(context.Background(), nil) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(resp).ToNot(BeNil()) | ||
Expect(resp.Name).To(Equal("scality-cosi-driver")) | ||
}) | ||
}) | ||
}) |