Skip to content

Commit

Permalink
Start unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nesmabadr committed Jan 13, 2025
1 parent 8c83717 commit 381122a
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/maintenancewindows/maintenance_policy_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func InitializeMaintenanceWindowsPolicy(log logr.Logger) (*resolver.MaintenanceW
}

policyFilePath := fmt.Sprintf("%s/%s.json", policiesDirectory, policyName)
if !maintenancePolicyFileExists(policyFilePath) {
if !MaintenancePolicyFileExists(policyFilePath) {
log.Info("maintenance windows policy file does not exist")
return nil, nil //nolint:nilnil //use nil to indicate an empty Maintenance Window Policy
}
Expand All @@ -38,7 +38,7 @@ func InitializeMaintenanceWindowsPolicy(log logr.Logger) (*resolver.MaintenanceW
return maintenancePolicy, nil
}

func maintenancePolicyFileExists(policyFilePath string) bool {
func MaintenancePolicyFileExists(policyFilePath string) bool {
if _, err := os.Stat(policyFilePath); os.IsNotExist(err) {
return false
}
Expand Down
20 changes: 20 additions & 0 deletions internal/maintenancewindows/maintenance_policy_handler_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package maintenancewindows_test

import (
"testing"

"github.com/kyma-project/lifecycle-manager/internal/maintenancewindows"
"github.com/stretchr/testify/require"
)

func TestMaintenancePolicyFileExists_FileNotExists(t *testing.T) {
got := maintenancewindows.MaintenancePolicyFileExists("testdata/file.json")

require.False(t, got)
}

func TestMaintenancePolicyFileExists_FileExists(t *testing.T) {
got := maintenancewindows.MaintenancePolicyFileExists("testdata/with-default.json")

require.True(t, got)
}
9 changes: 9 additions & 0 deletions internal/maintenancewindows/testdata/with-default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"default": {
"days": [
"Sat"
],
"begin": "21:00:00+00:00",
"end": "23:00:00+00:00"
}
}
38 changes: 38 additions & 0 deletions internal/maintenancewindows/testdata/with-rules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"rules": [
{
"match": {
"plan": "trial|free"
},
"windows": [
{
"days": [
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
"Sun"
],
"begin": "01:00:00+00:00",
"end": "01:00:00+00:00"
}
]
},
{
"match": {
"region": "europe|eu-|uksouth"
},
"windows": [
{
"days": [
"Sat"
],
"begin": "21:00:00+00:00",
"end": "00:00:00+00:00"
}
]
}
]
}

0 comments on commit 381122a

Please sign in to comment.