Skip to content

Commit

Permalink
fix codecov settings
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Paskal <[email protected]>
  • Loading branch information
maksim-paskal committed Mar 20, 2024
1 parent af9a7d3 commit 0880b67
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 13 deletions.
10 changes: 10 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ignore:
# ignore cmd/main.go because it's a main file
- "cmd/main.go"
# ignore because to test need active connection to the Telegram
- "pkg/alert/alert.go"
# ignore because to test need active connection to the kubernetes cluster
- "pkg/web/web.go"
- "pkg/api/api.go"
- "pkg/events/events.go"
- "pkg/client/client.go"
13 changes: 6 additions & 7 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,17 @@ func TestConfig(t *testing.T) {
},
}

for _, testCase := range testCases {
tc := testCase
t.Run(testCase.testName, func(t *testing.T) {
for i := range testCases {
t.Run(testCases[i].testName, func(t *testing.T) {
newConfig := config.Type{
TaintEffect: &tc.taintEffect,
NodeName: &tc.nodeName,
TelegramChatID: &tc.telegramID,
TaintEffect: &testCases[i].taintEffect,
NodeName: &testCases[i].nodeName,
TelegramChatID: &testCases[i].telegramID,
}
config.Set(newConfig)
err := config.Check()

if tc.err {
if testCases[i].err {
require.Error(t, err)
} else {
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func printType(prefix string, message interface{}) {
v := reflect.ValueOf(message)
typeOfS := v.Type()

for i := 0; i < v.NumField(); i++ {
for i := range v.NumField() {
switch typeOfS.Field(i).Name {
case "Template":
case "Event":
Expand Down
2 changes: 0 additions & 2 deletions pkg/types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ func TestAzureResource(t *testing.T) {
})

for testID, test := range tests {
test := test

t.Run("Test"+strconv.Itoa(testID), func(t *testing.T) {
t.Parallel()

Expand Down
45 changes: 45 additions & 0 deletions pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Copyright [email protected]
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
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package utils_test

import (
"context"
"testing"
"time"

"github.com/maksim-paskal/aks-node-termination-handler/pkg/utils"
)

func TestSleepWithContext(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.TODO())
defer cancel()

startTime := time.Now()

utils.SleepWithContext(ctx, 1*time.Second)

if time.Since(startTime) < 1*time.Second || time.Since(startTime) > 2*time.Second {
t.Error("SleepWithContext() not working as expected")
}

cancel()

startTime = time.Now()
utils.SleepWithContext(ctx, 1*time.Second)

if time.Since(startTime) >= 1*time.Second {
t.Error("SleepWithContext() not working as expected")
}
}
5 changes: 2 additions & 3 deletions pkg/webhook/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,8 @@ func TestWebHook(t *testing.T) { //nolint:funlen,tparallel
}
}

for _, test := range tests { //nolint:paralleltest
tc := test
t.Run(test.Name, func(t *testing.T) {
for _, tc := range tests { //nolint:paralleltest
t.Run(tc.Name, func(t *testing.T) {
cleanAllFlags()

for key, value := range tc.Args {
Expand Down

0 comments on commit 0880b67

Please sign in to comment.