mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-11 14:09:21 +00:00
fix usage of context
This commit is contained in:
parent
f63d329742
commit
b524ace87f
2 changed files with 13 additions and 8 deletions
|
|
@ -85,7 +85,13 @@
|
|||
@test "Fail when parsing a config that is missing a Kind" {
|
||||
run bin/kubeconform -summary fixtures/missing_kind.yaml
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" = *resource\ missing\ a\ Kind* ]]
|
||||
[[ "$output" == *"resource missing a Kind"* ]]
|
||||
}
|
||||
|
||||
@test "Fail when parsing a config that is missing a Kind value" {
|
||||
run bin/kubeconform -summary fixtures/missing_kind_value.yaml
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" == *"resource missing a Kind"* ]]
|
||||
}
|
||||
|
||||
@test "Fail when parsing a config with CRD" {
|
||||
|
|
@ -136,7 +142,7 @@
|
|||
|
||||
@test "Fail early when passing a non valid -schema-location template" {
|
||||
run bin/kubeconform -schema-location 'foo {{ .Foo }}' fixtures/valid.yaml
|
||||
[[ "$output" = failed\ initialising* ]]
|
||||
[[ "$output" == "failed initialising"* ]]
|
||||
[[ `echo "$output" | wc -l` -eq 1 ]]
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/yannh/kubeconform/pkg/validator"
|
||||
)
|
||||
|
||||
func processResults(ctx context.Context, o output.Output, validationResults <-chan validator.Result, exitOnError bool) <-chan bool {
|
||||
func processResults(cancel context.CancelFunc, o output.Output, validationResults <-chan validator.Result, exitOnError bool) <-chan bool {
|
||||
success := true
|
||||
result := make(chan bool)
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ func processResults(ctx context.Context, o output.Output, validationResults <-ch
|
|||
}
|
||||
}
|
||||
if success == false && exitOnError {
|
||||
ctx.Done() // early exit - signal to stop searching for resources
|
||||
cancel() // early exit - signal to stop searching for resources
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
@ -36,7 +36,6 @@ func processResults(ctx context.Context, o output.Output, validationResults <-ch
|
|||
}
|
||||
|
||||
result <- success
|
||||
close(result)
|
||||
}()
|
||||
|
||||
return result
|
||||
|
|
@ -79,8 +78,8 @@ func realMain() int {
|
|||
}
|
||||
|
||||
validationResults := make(chan validator.Result)
|
||||
ctx := context.Background()
|
||||
successChan := processResults(ctx, o, validationResults, cfg.ExitOnError)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
successChan := processResults(cancel, o, validationResults, cfg.ExitOnError)
|
||||
|
||||
var resourcesChan <-chan resource.Resource
|
||||
var errors <-chan error
|
||||
|
|
@ -123,7 +122,7 @@ func realMain() int {
|
|||
Status: validator.Error,
|
||||
}
|
||||
}
|
||||
ctx.Done()
|
||||
cancel()
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
|
|
|
|||
Loading…
Reference in a new issue