Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Add unit tests #56

Merged
merged 17 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/Guidewire/fern-reporter/badge)](https://securityscorecards.dev/viewer/?uri=github.com/Guidewire/fern-reporter)
![Coverage](https://img.shields.io/badge/Coverage-23.0%25-red)
![Coverage](https://img.shields.io/badge/Coverage-73.2%25-brightgreen)

![Fern](https://github.com/guidewire/fern-reporter/raw/main/docs/images/logo-no-background.png)

Expand Down
51 changes: 50 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,22 @@ import (
"github.com/guidewire/fern-reporter/config"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/mock"
"os"
)

var _ = Describe("Config", func() {
// Mock the file reading function
type MockFileReader struct {
mock.Mock
}

func (m *MockFileReader) ReadFile(filename string) ([]byte, error) {
args := m.Called(filename)
return args.Get(0).([]byte), args.Error(1)
}

var _ = Describe("When LoadConfig is invoked", func() {

Context("LoadConfig", func() {
It("should load the configuration from a file", func() {

Expand All @@ -25,6 +38,42 @@ var _ = Describe("Config", func() {
Expect(appConfig.Db.MaxIdleConns).To(Equal(10))
})

It("should get non-nil DB", func() {

_, err := config.LoadConfig()
Expect(err).NotTo(HaveOccurred())

Expect(config.GetDb()).ToNot(BeNil())
})

It("should get non-nil Server", func() {

_, err := config.LoadConfig()
Expect(err).NotTo(HaveOccurred())

Expect(config.GetServer()).ToNot(BeNil())
})

})

It("should override configuration with environment variables", func() {

os.Setenv("FERN_USERNAME", "fern")
os.Setenv("FERN_PASSWORD", "fern")
os.Setenv("FERN_HOST", "localhost")
os.Setenv("FERN_PORT", "5432")
os.Setenv("FERN_DATABASE", "fern")

//v := viper.New()
result, err := config.LoadConfig()

Expect(err).To(BeNil())
Expect(result).ToNot(BeNil())
Expect(result.Db.Username).To(Equal("fern"))
Expect(result.Db.Password).To(Equal("fern"))
Expect(result.Db.Host).To(Equal("localhost"))
Expect(result.Db.Port).To(Equal("5432"))
Expect(result.Db.Database).To(Equal("fern"))
})

})
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/onsi/ginkgo/v2 v2.13.2
github.com/onsi/gomega v1.30.0
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.8.4
gorm.io/driver/postgres v1.5.4
gorm.io/gorm v1.25.5
)
Expand All @@ -19,6 +20,7 @@ require (
github.com/bytedance/sonic v1.10.2 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
Expand Down Expand Up @@ -49,13 +51,15 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ=
github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
Expand Down
Loading
Loading