From 9124a47ee92b33b2e2aac90d87ccf36439e93947 Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Mon, 6 Nov 2017 20:48:34 -0300 Subject: [PATCH] Add nginx helper tests --- pkg/ingress/controller/process/nginx.go | 1 + pkg/ingress/controller/process/nginx_test.go | 44 ++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 pkg/ingress/controller/process/nginx_test.go diff --git a/pkg/ingress/controller/process/nginx.go b/pkg/ingress/controller/process/nginx.go index 326b7ca48..4a925a3e1 100644 --- a/pkg/ingress/controller/process/nginx.go +++ b/pkg/ingress/controller/process/nginx.go @@ -29,6 +29,7 @@ import ( "github.com/ncabatoff/process-exporter/proc" ) +// IsRespawnIfRequired checks if error type is exec.ExitError or not func IsRespawnIfRequired(err error) bool { exitError, ok := err.(*exec.ExitError) if !ok { diff --git a/pkg/ingress/controller/process/nginx_test.go b/pkg/ingress/controller/process/nginx_test.go new file mode 100644 index 000000000..7174e4d8e --- /dev/null +++ b/pkg/ingress/controller/process/nginx_test.go @@ -0,0 +1,44 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package process + +import ( + "fmt" + "os" + "os/exec" + "testing" +) + +func TestIsRespawnIfRequired(t *testing.T) { + cases := []struct { + err error + isReq bool + }{ + {nil, false}, + {fmt.Errorf("dummy"), false}, + {&exec.ExitError{ + ProcessState: &os.ProcessState{}, + }, true}, + } + + for _, tc := range cases { + isReq := IsRespawnIfRequired(tc.err) + if tc.isReq != isReq { + t.Error("expected an error but none returned") + } + } +}