1
0
Fork 0
mirror of https://github.com/kyverno/policy-reporter.git synced 2024-12-15 17:50:58 +00:00
policy-reporter/pkg/config/load_test.go
Frank Jogeleit 836d6fe436
API to render Violations Report (#429)
* API to render Violations Report

Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
2024-05-04 10:04:27 +02:00

67 lines
2.2 KiB
Go

package config_test
import (
"testing"
"github.com/spf13/cobra"
"github.com/kyverno/policy-reporter/pkg/config"
)
func createCMD() *cobra.Command {
cmd := &cobra.Command{}
cmd.Flags().StringP("kubeconfig", "k", "", "absolute path to the kubeconfig file")
cmd.Flags().StringP("config", "c", "", "target configuration file")
cmd.Flags().IntP("port", "p", 8080, "http port for the optional rest api")
cmd.Flags().StringP("dbfile", "d", "sqlite-database.db", "path to the SQLite DB File")
cmd.Flags().BoolP("metrics-enabled", "m", false, "Enable Policy Reporter's Metrics API")
cmd.Flags().BoolP("rest-enabled", "r", false, "Enable Policy Reporter's REST API")
cmd.Flags().Bool("profile", false, "Enable application profiling with pprof")
cmd.Flags().StringP("template-dir", "t", "./templates", "template directory for email reports")
cmd.Flags().String("lease-name", "policy-reporter", "name of the LeaseLock")
cmd.Flags().String("pod-name", "policy-reporter", "name of the pod, used for leaderelection")
return cmd
}
func Test_Load(t *testing.T) {
cmd := createCMD()
_ = cmd.Flags().Set("kubeconfig", "./config")
_ = cmd.Flags().Set("port", "8081")
_ = cmd.Flags().Set("rest-enabled", "1")
_ = cmd.Flags().Set("metrics-enabled", "1")
_ = cmd.Flags().Set("profile", "1")
_ = cmd.Flags().Set("template-dir", "/app/templates")
_ = cmd.Flags().Set("dbfile", "")
_ = cmd.Flags().Set("pod-name", "policy-reporter")
_ = cmd.Flags().Set("lease-name", "policy-reporter")
c, err := config.Load(cmd)
if err != nil {
t.Errorf("Unexpected Error: %s", err)
}
if c.K8sClient.Kubeconfig != "./config" {
t.Errorf("Unexpected TemplateDir Config: %s", c.K8sClient.Kubeconfig)
}
if c.API.Port != 8081 {
t.Errorf("Unexpected Port Config: %d", c.API.Port)
}
if c.REST.Enabled != true {
t.Errorf("Unexpected REST Config: %v", c.REST.Enabled)
}
if c.Metrics.Enabled != true {
t.Errorf("Unexpected Metrics Config: %v", c.Metrics.Enabled)
}
if c.Profiling.Enabled != true {
t.Errorf("Unexpected Profiling Config: %v", c.Profiling.Enabled)
}
if c.Templates.Dir != "/app/templates" {
t.Errorf("Unexpected TemplateDir Config: %s", c.Templates.Dir)
}
if c.DBFile != "sqlite-database.db" {
t.Errorf("Unexpected DBFile Config: %s", c.DBFile)
}
}