Skip to content

Commit 973d176

Browse files
committed
Renamed interfaces to drop the I prefix and updated mocks accordingly. Added tests for alert, ristretto, socket, and document. Added Windows TPM support and a test helper script.
1 parent 20fb651 commit 973d176

125 files changed

Lines changed: 2870 additions & 3180 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.mockery.yaml‎

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,142 +4,142 @@ issue-845-fix: True
44
packages:
55
github.com/AmadlaOrg/LibraryUtils/configuration:
66
interfaces:
7-
IConfiguration:
7+
Configuration:
88
config:
99
dir: "{{.InterfaceDir}}"
1010
mockName: "MockConfiguration"
1111
inpackage: True
12-
IViper:
12+
Viper:
1313
config:
1414
dir: "{{.InterfaceDir}}"
1515
mockName: "MockViper"
1616
inpackage: True
1717
github.com/AmadlaOrg/LibraryUtils/database/sqlite3:
1818
interfaces:
19-
IDatabase:
19+
Database:
2020
config:
2121
dir: "{{.InterfaceDir}}"
2222
mockName: "MockCacheDatabase"
2323
inpackage: True
24-
IDatabaseSqlNullString:
24+
NullString:
2525
config:
2626
dir: "{{.InterfaceDir}}"
27-
mockName: MockIDatabaseSqlNullString
28-
IDatabaseSqlNullInt64:
27+
mockName: MockNullString
28+
NullInt64:
2929
config:
3030
dir: "{{.InterfaceDir}}"
31-
mockName: MockIDatabaseSqlNullInt64
32-
IDatabaseSqlNullInt32:
31+
mockName: MockNullInt64
32+
NullInt32:
3333
config:
3434
dir: "{{.InterfaceDir}}"
35-
mockName: MockIDatabaseSqlNullInt32
36-
IDatabaseSqlNullInt16:
35+
mockName: MockNullInt32
36+
NullInt16:
3737
config:
3838
dir: "{{.InterfaceDir}}"
39-
mockName: MockIDatabaseSqlNullInt16
40-
IDatabaseSqlNullByte:
39+
mockName: MockNullInt16
40+
NullByte:
4141
config:
4242
dir: "{{.InterfaceDir}}"
43-
mockName: MockIDatabaseSqlNullByte
44-
IDatabaseSqlNullFloat64:
43+
mockName: MockNullByte
44+
NullFloat64:
4545
config:
4646
dir: "{{.InterfaceDir}}"
47-
mockName: MockIDatabaseSqlNullFloat64
48-
IDatabaseSqlNullBool:
47+
mockName: MockNullFloat64
48+
NullBool:
4949
config:
5050
dir: "{{.InterfaceDir}}"
51-
mockName: MockIDatabaseSqlNullBool
52-
IDatabaseSqlNullTime:
51+
mockName: MockNullBool
52+
NullTime:
5353
config:
5454
dir: "{{.InterfaceDir}}"
55-
mockName: MockIDatabaseSqlNullTime
56-
IDatabaseSqlNull:
55+
mockName: MockNullTime
56+
Null:
5757
config:
5858
dir: "{{.InterfaceDir}}"
59-
mockName: MockIDatabaseSqlNull
60-
IDatabaseSqlDriverStmt:
59+
mockName: MockNull
60+
DriverStmt:
6161
config:
6262
dir: "{{.InterfaceDir}}"
63-
mockName: MockIDatabaseSqlDriverStmt
64-
IDatabaseSqlDsnConnector:
63+
mockName: MockDriverStmt
64+
DsnConnector:
6565
config:
6666
dir: "{{.InterfaceDir}}"
67-
mockName: MockIDatabaseSqlDsnConnector
68-
IDatabaseSqlDB:
67+
mockName: MockDsnConnector
68+
DB:
6969
config:
7070
dir: "{{.InterfaceDir}}"
71-
mockName: MockIDatabaseSqlDB
72-
IDatabaseSqlConn:
71+
mockName: MockDB
72+
Conn:
7373
config:
7474
dir: "{{.InterfaceDir}}"
75-
mockName: MockIDatabaseSqlConn
76-
IDatabaseSqlTx:
75+
mockName: MockConn
76+
Tx:
7777
config:
7878
dir: "{{.InterfaceDir}}"
79-
mockName: MockIDatabaseSqlTx
80-
IDatabaseSqlStmt:
79+
mockName: MockTx
80+
Stmt:
8181
config:
8282
dir: "{{.InterfaceDir}}"
83-
mockName: MockIDatabaseSqlStmt
84-
IDatabaseSqlRows:
83+
mockName: MockStmt
84+
Rows:
8585
config:
8686
dir: "{{.InterfaceDir}}"
87-
mockName: MockIDatabaseSqlRows
88-
IDatabaseSqlColumnType:
87+
mockName: MockRows
88+
ColumnType:
8989
config:
9090
dir: "{{.InterfaceDir}}"
91-
mockName: MockIDatabaseSqlColumnType
92-
IDatabaseSqlRow:
91+
mockName: MockColumnType
92+
Row:
9393
config:
9494
dir: "{{.InterfaceDir}}"
95-
mockName: MockIDatabaseSqlRow
96-
IDatabaseSqlConnRequestSet:
95+
mockName: MockRow
96+
ConnRequestSet:
9797
config:
9898
dir: "{{.InterfaceDir}}"
99-
mockName: MockIDatabaseSqlConnRequestSet
100-
IGoSqlite3SQLiteConn:
99+
mockName: MockConnRequestSet
100+
SQLiteConn:
101101
config:
102102
dir: "{{.InterfaceDir}}"
103-
mockName: MockIGoSqlite3SQLiteConn
103+
mockName: MockSQLiteConn
104104
github.com/AmadlaOrg/LibraryUtils/file:
105105
interfaces:
106-
IFile:
106+
File:
107107
config:
108108
dir: "{{.InterfaceDir}}"
109109
mockName: MockFile
110110
inpackage: True
111111
github.com/AmadlaOrg/LibraryUtils/git:
112112
interfaces:
113-
IGit:
113+
Git:
114114
config:
115115
dir: "{{.InterfaceDir}}"
116116
mockName: "MockUtilGit"
117117
inpackage: True
118-
IGoGitRepository:
118+
GoGitRepository:
119119
config:
120120
dir: "{{.InterfaceDir}}"
121121
mockName: "MockGoGitRepository"
122122
inpackage: True
123-
IGoGitWorktree:
123+
GoGitWorktree:
124124
config:
125125
dir: "{{.InterfaceDir}}"
126126
mockName: "MockGoGitWorktree"
127127
inpackage: True
128128
github.com/AmadlaOrg/LibraryUtils/git/remote:
129129
interfaces:
130-
IRemote:
130+
Remote:
131131
config:
132132
dir: "{{.InterfaceDir}}"
133133
mockName: "MockUtilGitRemote"
134134
inpackage: True
135-
IGoGitRemote:
135+
GoGitRemote:
136136
config:
137137
dir: "{{.InterfaceDir}}"
138138
mockName: "MockGoGitRemote"
139139
inpackage: True
140140
github.com/AmadlaOrg/LibraryUtils/location:
141141
interfaces:
142-
ILocation:
142+
Location:
143143
config:
144144
dir: "{{.InterfaceDir}}"
145145
mockName: "MockLocation"
@@ -153,7 +153,7 @@ packages:
153153
inpackage: True
154154
github.com/AmadlaOrg/LibraryUtils/packaging/document:
155155
interfaces:
156-
IDocument:
156+
Document:
157157
config:
158158
dir: "{{.InterfaceDir}}"
159159
mockName: MockPackagingDocument

‎.script/test.sh‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
output_dir=".reports"
6+
cov_unfiltered_out_file="${output_dir}/coverage.unfiltered.out"
7+
cov_out_file="${output_dir}/coverage.out"
8+
cov_out_xml_file="${output_dir}/coverage.xml"
9+
report_file="${output_dir}/coverage_summary.txt"
10+
11+
rm -rf ${output_dir}
12+
mkdir -p ${output_dir}
13+
echo "" > ${report_file}
14+
15+
echo "---> Testing code..."
16+
17+
go test -count=1 -tags=integration -coverpkg=./... -covermode=count -coverprofile ${cov_unfiltered_out_file} ./... | tee ${output_dir}/std.out
18+
grep -v -E -f .covignore ${cov_unfiltered_out_file} > ${cov_out_file}
19+
20+
total="$(go tool cover -func ${cov_out_file} | tail -n 1 | grep -Eo '[0-9]+\.[0-9]+')"
21+
subtotals+="\t${total}%"
22+
23+
echo -e "Total coverage:\t${total}%" | tee -a $report_file
24+
25+
# shellcheck disable=SC2002
26+
cat ${output_dir}/std.out | go-junit-report > ${output_dir}/reports.xml
27+
gocover-cobertura < ${cov_out_file} > ${cov_out_xml_file} --ignore-gen-files
28+
gcov2lcov -infile=${cov_out_file} -outfile=${output_dir}/lcov.info

‎alert/errors_test.go‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package alert
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestErrorNotFound(t *testing.T) {
10+
assert.EqualError(t, ErrorNotFound, "not found")
11+
}
12+
13+
func TestErrorMultipleFound(t *testing.T) {
14+
assert.EqualError(t, ErrorMultipleFound, "multiple found")
15+
}
16+
17+
func TestErrorsAreDistinct(t *testing.T) {
18+
assert.NotEqual(t, ErrorNotFound, ErrorMultipleFound)
19+
}

‎cache/cache.go‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
package cache
22

3-
import "time"
3+
import (
4+
"time"
45

5-
type ICache interface {
6+
"github.com/AmadlaOrg/LibraryUtils/database/sqlite"
7+
)
8+
9+
type Cache interface {
610
Open() error
711
Close() error
812
Insert(entry *map[string]string, ttl time.Duration) error
913
Select() (*map[string]string, error)
1014
Delete(entry string) error
1115
}
1216

13-
type SCache struct {
14-
database database.IDatabase
17+
type cacheImpl struct {
18+
database sqlite.Database
1519
}
1620

1721
// Open is for opening a connection with the cache storage (e.g.: SQLite3 database, Ristretto memory-bound Go cache)
18-
func (service *SCache) Open() error {
19-
22+
func (service *cacheImpl) Open() error {
23+
return nil
2024
}

‎cache/cache_test.go‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
11
package cache
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestCacheImpl_Open(t *testing.T) {
10+
svc := &cacheImpl{}
11+
err := svc.Open()
12+
assert.NoError(t, err)
13+
}

‎configuration/configuration.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ package configuration
22

33
import "github.com/spf13/viper"
44

5-
// IConfiguration 🧩 Is the interface for the NewConfigurationService.
6-
type IConfiguration interface {
5+
// Configuration 🧩 Is the interface for the NewConfigurationService.
6+
type Configuration interface {
77
Instance() *viper.Viper
88
}
99

10-
// SConfiguration 🏛️ Is the main structure for the NewConfigurationService.
11-
type SConfiguration struct {
10+
// configImpl 🏛️ Is the main structure for the NewConfigurationService.
11+
type configImpl struct {
1212
// 🐍 viperInstance - Is an instance of Viper
1313
viperInstance *viper.Viper
1414
}
1515

1616
// Instance 🗿 of Viper with all the settings set up in the new service.
17-
func (s *SConfiguration) Instance() *viper.Viper {
17+
func (s *configImpl) Instance() *viper.Viper {
1818
return s.viperInstance
1919
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
11
package configuration
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestInstance(t *testing.T) {
10+
svc := New("testapp", "/tmp/config")
11+
instance := svc.Instance()
12+
13+
assert.NotNil(t, instance)
14+
15+
// Same instance returned each time
16+
assert.Same(t, instance, svc.Instance())
17+
}

‎configuration/interface.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
"github.com/spf13/pflag"
1313
)
1414

15-
// IViper 🐍 is the interface for Viper methods.
16-
type IViper interface {
15+
// Viper 🐍 is the interface for Viper methods.
16+
type Viper interface {
1717
OnConfigChange(run func(in fsnotify.Event))
1818
WatchConfig()
1919
SetConfigFile(in string)

‎configuration/mock_IConfiguration.go‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎configuration/mock_IViper.go‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)