mirror of
https://github.com/yannh/kubeconform.git
synced 2026-04-14 08:24:45 +00:00
Add example how to use kubeconform as a library
This commit is contained in:
parent
4672ded043
commit
4e96b44a8b
7 changed files with 93 additions and 18 deletions
|
|
@ -88,10 +88,6 @@ func FromFlags(progName string, args []string) (Config, string, error) {
|
|||
c.RejectKinds = splitCSV(rejectKindsCSV)
|
||||
c.IgnoreFilenamePatterns = ignoreFilenamePatterns
|
||||
c.SchemaLocations = schemaLocationsParam
|
||||
if len(c.SchemaLocations) == 0 {
|
||||
c.SchemaLocations = append(c.SchemaLocations, "https://kubernetesjsonschema.dev") // if not specified, default behaviour is to use kubernetesjson-schema.dev as registry
|
||||
}
|
||||
|
||||
c.Files = flags.Args()
|
||||
|
||||
if c.Help {
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ func TestFromFlags(t *testing.T) {
|
|||
KubernetesVersion: "1.18.0",
|
||||
NumberOfWorkers: 4,
|
||||
OutputFormat: "text",
|
||||
SchemaLocations: []string{"https://kubernetesjsonschema.dev"},
|
||||
SchemaLocations: nil,
|
||||
SkipKinds: map[string]bool{},
|
||||
RejectKinds: map[string]bool{},
|
||||
},
|
||||
|
|
@ -65,7 +65,7 @@ func TestFromFlags(t *testing.T) {
|
|||
KubernetesVersion: "1.18.0",
|
||||
NumberOfWorkers: 4,
|
||||
OutputFormat: "text",
|
||||
SchemaLocations: []string{"https://kubernetesjsonschema.dev"},
|
||||
SchemaLocations: nil,
|
||||
SkipKinds: map[string]bool{},
|
||||
RejectKinds: map[string]bool{},
|
||||
},
|
||||
|
|
@ -77,7 +77,7 @@ func TestFromFlags(t *testing.T) {
|
|||
KubernetesVersion: "1.18.0",
|
||||
NumberOfWorkers: 4,
|
||||
OutputFormat: "text",
|
||||
SchemaLocations: []string{"https://kubernetesjsonschema.dev"},
|
||||
SchemaLocations: nil,
|
||||
SkipKinds: map[string]bool{"a": true, "b": true, "c": true},
|
||||
RejectKinds: map[string]bool{},
|
||||
},
|
||||
|
|
@ -89,7 +89,7 @@ func TestFromFlags(t *testing.T) {
|
|||
KubernetesVersion: "1.18.0",
|
||||
NumberOfWorkers: 4,
|
||||
OutputFormat: "text",
|
||||
SchemaLocations: []string{"https://kubernetesjsonschema.dev"},
|
||||
SchemaLocations: nil,
|
||||
SkipKinds: map[string]bool{},
|
||||
RejectKinds: map[string]bool{},
|
||||
Summary: true,
|
||||
|
|
@ -116,10 +116,10 @@ func TestFromFlags(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
for i, testCase := range testCases {
|
||||
cfg, _, _ := FromFlags("kubeconform", testCase.args)
|
||||
if reflect.DeepEqual(cfg, testCase.conf) != true {
|
||||
t.Errorf("failed parsing config - expected , got: \n%+v\n%+v", testCase.conf, cfg)
|
||||
t.Errorf("test %d: failed parsing config - expected , got: \n%+v\n%+v", i, testCase.conf, cfg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue