Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Todd Ekenstam <[email protected]>
  • Loading branch information
tekenstam committed Oct 7, 2023
1 parent 96bd017 commit 8d3ce97
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 55 deletions.
2 changes: 1 addition & 1 deletion pkg/reaper/pdbreaper/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (ctx *ReaperContext) validate(args *Args) error {

if args.K8sConfigPath != "" {
if ok := common.PathExists(args.K8sConfigPath); !ok {
return errors.Errorf("--kubeconfig path '%v' was not found", ctx.KubernetesConfigPath)
return errors.Errorf("--kubeconfig path '%v' was not found", args.K8sConfigPath)
}
ctx.KubernetesConfigPath = args.K8sConfigPath
}
Expand Down
61 changes: 7 additions & 54 deletions pkg/reaper/pdbreaper/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,77 +16,30 @@ limitations under the License.
package pdbreaper

import (
"io/ioutil"
"testing"

"github.com/keikoproj/governor/pkg/reaper/common"
"k8s.io/client-go/kubernetes/fake"
)

func newFakeReaperContext() *ReaperContext {
if !loggingEnabled {
log.Out = ioutil.Discard
common.Log.Out = ioutil.Discard
}
ctx := ReaperContext{}
ctx.KubernetesClient = fake.NewSimpleClientset()
// Default Flags
ctx.DryRun = false
return &ctx
}

func TestReaperContext_validate(t *testing.T) {
// type fields struct {
// KubernetesClient kubernetes.Interface
// KubernetesConfigPath string
// DryRun bool
// LocalMode bool
// ReapMisconfigured bool
// ReapMultiple bool
// ReapCrashLoop bool
// AllCrashLoop bool
// CrashLoopRestartCount int
// ReapNotReady bool
// ReapNotReadyThreshold int
// AllNotReady bool
// ReapablePodDisruptionBudgets []policyv1.PodDisruptionBudget
// ClusterBlockingPodDisruptionBudgets map[string][]policyv1.PodDisruptionBudget
// NamespacesWithMultiplePodDisruptionBudgets map[string][]policyv1.PodDisruptionBudget
// ExcludedNamespaces []string
// ReapablePodDisruptionBudgetsCount int
// ReapedPodDisruptionBudgetCount int
// PromPushgateway string
// MetricsAPI common.MetricsAPI
// }
// type args struct {
// args *Args
// }
reaperArgs := &Args{
reaperArgsValid := Args{
LocalMode: true,
K8sConfigPath: "foobar",
K8sConfigPath: common.HomeDir() + "/.kube/config",
DryRun: true,
CrashLoopRestartCount: 1,
}
reaperArgs.DryRun = true

reaperArgsInvalidK8sConfigPath := Args(reaperArgsValid)
reaperArgsInvalidK8sConfigPath.K8sConfigPath = "/tmp/invalid/path"

tests := []struct {
name string
fields ReaperContext
args *Args
wantErr bool
}{
// TODO: Add test cases.
{"Invalid-CrashLoopRestartCount", *_fakeReaperContext(), &Args{
LocalMode: false,
DryRun: true,
CrashLoopRestartCount: 1,
}, false},

// {"Invalid-CrashLoopRestartCount", ReaperContext{DryRun: true, CrashLoopRestartCount: -1, KubernetesConfigPath: "foobar"}, &Args{
// LocalMode: true,
// DryRun: true,
// CrashLoopRestartCount: 1,
// }, false},
{"Valid-Args", *_fakeReaperContext(), &reaperArgsValid, false},
{"Invalid-K8sConfigPath", *_fakeReaperContext(), &reaperArgsInvalidK8sConfigPath, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 8d3ce97

Please sign in to comment.