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 381122a commit faa6a44
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func pprofStartServer(addr string, timeout time.Duration, setupLog logr.Logger)
}
}

// nolint: funlen // setupManager is a main function that sets up the manager
//nolint: funlen // setupManager is a main function that sets up the manager
func setupManager(flagVar *flags.FlagVar, cacheOptions cache.Options, scheme *machineryruntime.Scheme,
setupLog logr.Logger,
) {
Expand Down
10 changes: 5 additions & 5 deletions internal/maintenancewindows/maintenance_policy_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import (
)

const (
policyName = "policy"
policiesDirectory = "/etc/maintenance-policy"
PolicyName = "policy"
PoliciesDirectory = "/etc/maintenance-policy"
)

func InitializeMaintenanceWindowsPolicy(log logr.Logger) (*resolver.MaintenanceWindowPolicy, error) {
if err := os.Setenv(resolver.PolicyPathENV, policiesDirectory); err != nil {
if err := os.Setenv(resolver.PolicyPathENV, PoliciesDirectory); err != nil {
return nil, fmt.Errorf("failed to set the policy path env variable, %w", err)
}

policyFilePath := fmt.Sprintf("%s/%s.json", policiesDirectory, policyName)
policyFilePath := fmt.Sprintf("%s/%s.json", PoliciesDirectory, PolicyName)
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 @@ -30,7 +30,7 @@ func InitializeMaintenanceWindowsPolicy(log logr.Logger) (*resolver.MaintenanceW
return nil, fmt.Errorf("failed to get maintenance policy pool, %w", err)
}

maintenancePolicy, err := resolver.GetMaintenancePolicy(maintenancePolicyPool, policyName)
maintenancePolicy, err := resolver.GetMaintenancePolicy(maintenancePolicyPool, PolicyName)
if err != nil {
return nil, fmt.Errorf("failed to get maintenance window policy, %w", err)
}
Expand Down
10 changes: 9 additions & 1 deletion internal/maintenancewindows/maintenance_policy_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package maintenancewindows_test
import (
"testing"

"github.com/go-logr/logr"
"github.com/kyma-project/lifecycle-manager/internal/maintenancewindows"
"github.com/stretchr/testify/require"
)
Expand All @@ -14,7 +15,14 @@ func TestMaintenancePolicyFileExists_FileNotExists(t *testing.T) {
}

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

require.True(t, got)
}

func TestInitializeMaintenanceWindowsPolicy_FileNotExist(t *testing.T) {
got, err := maintenancewindows.InitializeMaintenanceWindowsPolicy(logr.Logger{})

require.Nil(t, got)
require.NoError(t, err)
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,12 @@
}
]
}
]
],
"default": {
"days": [
"Sat"
],
"begin": "21:00:00+00:00",
"end": "23:00:00+00:00"
}
}
9 changes: 0 additions & 9 deletions internal/maintenancewindows/testdata/with-default.json

This file was deleted.

0 comments on commit faa6a44

Please sign in to comment.