From 4fe0f045e8600c2aca5dc7136185a0aeb516a231 Mon Sep 17 00:00:00 2001 From: bilalcaliskan Date: Sun, 9 Jan 2022 13:57:46 +0300 Subject: [PATCH] cover more lines --- .gitignore | 3 ++- go.mod | 1 + internal/logging/logging_test.go | 8 +++----- internal/metrics/metrics_test.go | 17 +---------------- internal/options/options_test.go | 14 ++++++++++++++ 5 files changed, 21 insertions(+), 22 deletions(-) create mode 100644 internal/options/options_test.go diff --git a/.gitignore b/.gitignore index fda7061..d9c0977 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ vendor/ *.test # Output of the go coverage tool, specifically when used with LiteIDE -*.out \ No newline at end of file +*.out +coverage.txt diff --git a/go.mod b/go.mod index fbd905b..c16cf48 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/mattn/go-isatty v0.0.14 // indirect github.com/prometheus/client_golang v1.11.0 github.com/spf13/pflag v1.0.5 + github.com/stretchr/testify v1.7.0 go.uber.org/atomic v1.9.0 // indirect go.uber.org/multierr v1.7.0 // indirect go.uber.org/zap v1.20.0 diff --git a/internal/logging/logging_test.go b/internal/logging/logging_test.go index cce2505..b6ff845 100644 --- a/internal/logging/logging_test.go +++ b/internal/logging/logging_test.go @@ -1,13 +1,11 @@ package logging import ( - "go.uber.org/zap" + "github.com/stretchr/testify/assert" "testing" ) func TestGetLogger(t *testing.T) { - _, err := zap.NewProduction() - if err != nil { - t.Errorf("%v\n", err.Error()) - } + logger := GetLogger() + assert.NotNil(t, logger) } diff --git a/internal/metrics/metrics_test.go b/internal/metrics/metrics_test.go index ca269fc..eb00f20 100644 --- a/internal/metrics/metrics_test.go +++ b/internal/metrics/metrics_test.go @@ -1,30 +1,15 @@ package metrics import ( - "fmt" - "net/http" "testing" "time" - - "github.com/gorilla/mux" - "github.com/prometheus/client_golang/prometheus/promhttp" - "go.uber.org/zap" ) func TestRunMetricsServer(t *testing.T) { errChan := make(chan error, 1) go func() { - router := mux.NewRouter() - metricServer := &http.Server{ - Handler: router, - Addr: fmt.Sprintf(":%d", opts.MetricsPort), - WriteTimeout: time.Duration(int32(opts.WriteTimeoutSeconds)) * time.Second, - ReadTimeout: time.Duration(int32(opts.ReadTimeoutSeconds)) * time.Second, - } - router.Handle("/metrics", promhttp.Handler()) - logger.Info("starting metrics server", zap.Int("port", opts.MetricsPort)) - errChan <- metricServer.ListenAndServe() + errChan <- RunMetricsServer() }() for { diff --git a/internal/options/options_test.go b/internal/options/options_test.go new file mode 100644 index 0000000..7f4eeb1 --- /dev/null +++ b/internal/options/options_test.go @@ -0,0 +1,14 @@ +package options + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +// TestGetOreillyTrialOptions function tests if GetOreillyTrialOptions function running properly +func TestGetVarnishCacheInvalidatorOptions(t *testing.T) { + t.Log("fetching default options.VarnishCacheInvalidatorOptions") + opts := GetVarnishCacheInvalidatorOptions() + assert.NotNil(t, opts) + t.Logf("fetched default options.VarnishCacheInvalidatorOptions, %v\n", opts) +}