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

Test code cov poc #3082

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft
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
15 changes: 15 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ jobs:
make install-minio
if: matrix.testSuite == 'test'
- run: make ${{ matrix.testSuite }}
- name: Upload coverage results to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.txt
- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
recreate: true
path: code-coverage-results.md
- name: Code Coverage Summary
uses: irongut/[email protected]


build:
runs-on: ubuntu-20.04
needs: gomod
Expand Down
1 change: 1 addition & 0 deletions build/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ check_dependencies
echo "Running tests:"
go test -v ${TARGETS} -list .
go test -v -installsuffix "static" ${TARGETS} -check.v ${GOCHECK_FILTER}
go test -coverprofile=coverage.txt ./...
echo

echo "PASS"
Expand Down
7 changes: 7 additions & 0 deletions codecov.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
comment:
require_changes: false
require_head: false # default true
require_base: false # default true
layout: " diff, flags, files"
behavior: default
hide_project_coverage: false
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,7 @@ require (
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1
)

require github.com/stretchr/testify v1.9.0

require github.com/pmezard/go-difflib v1.0.0 // indirect
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,9 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand Down
19 changes: 19 additions & 0 deletions pkg/function/create_csi_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package function

import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/util/rand"

. "gopkg.in/check.v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -121,3 +123,20 @@ func getPVCManifest(pvcName, storageClassName string) *corev1.PersistentVolumeCl
},
}
}

func (testSuite *CreateCSISnapshotTestSuite) TestDefaultSnapshotName(c *C) {
for _, tc := range []struct {
pvcName string
len int
expectedSnapshotName string
}{
{
pvcName: pvcName,
len: 2,
expectedSnapshotName: fmt.Sprintf("%s-snapshot-%s", pvcName, rand.String(2)),
},
} {
gotSnapshotName := defaultSnapshotName(tc.pvcName, tc.len)
c.Assert(gotSnapshotName[:len(tc.pvcName)], Equals, tc.expectedSnapshotName[:len(tc.pvcName)])
}
}
25 changes: 25 additions & 0 deletions pkg/kancontroller/kancontroller_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package kancontroller

import (
"github.com/stretchr/testify/assert"
"os"
"testing"
)

func TestMetricsEnabled(t *testing.T) {
// Test case 1: Environment variable is not set
os.Unsetenv(kanisterMetricsEnv)
assert.False(t, metricsEnabled(), "Expected metricsEnabled() to return false when environment variable is not set")

// Test case 2: Environment variable is set but has invalid value
os.Setenv(kanisterMetricsEnv, "invalid")
assert.False(t, metricsEnabled(), "Expected metricsEnabled() to return false when environment variable is set to an invalid boolean")

// Test case 3: Environment variable is set to "true"
os.Setenv(kanisterMetricsEnv, "true")
assert.True(t, metricsEnabled(), "Expected metricsEnabled() to return true when environment variable is set to 'true'")

// Test case 4: Environment variable is set to "false"
os.Setenv(kanisterMetricsEnv, "false")
assert.False(t, metricsEnabled(), "Expected metricsEnabled() to return false when environment variable is set to 'false'")
}
Loading