Skip to content

Commit e4c2b51

Browse files
committed
fix(lint): fixed linter issues & optimized test structure
1 parent 2f2f840 commit e4c2b51

File tree

2 files changed

+7
-26
lines changed

2 files changed

+7
-26
lines changed

internal/usage/db_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import (
1313

1414
var _ = Describe("Database Module", func() {
1515
BeforeEach(func() {
16-
os.Setenv("USAGE_DB_PATH", "")
16+
err := os.Setenv("USAGE_DB_PATH", "")
17+
Ω(err).Should(Succeed())
1718
})
1819
Context("When getting the Database", func() {
1920
It("should return a database entity", func() {
@@ -43,7 +44,7 @@ var _ = Describe("Database Module", func() {
4344
err = rows.Scan(&tableName)
4445
Ω(err).Should(Succeed())
4546

46-
Ω(len(expectedTables)).ShouldNot(Equal(0))
47+
Ω(len(expectedTables)).ShouldNot(BeEmpty())
4748
expectedTables = slices.DeleteFunc(expectedTables, func(expected string) bool {
4849
return expected == tableName
4950
})

internal/usage/helper_test.go

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package usage
22

33
import (
4-
"fmt"
54
"time"
65

76
. "github.com/onsi/ginkgo/v2"
@@ -22,35 +21,16 @@ var _ = Describe("Helper Module", func() {
2221

2322
result := calculateUsage(start, end)
2423

25-
Ω(len(result)).Should(Equal(8))
24+
Ω(result).Should(HaveLen(8))
2625

27-
Ω(result[0].date.Equal(endDate)).Should(Equal(true), "first date must equal end date")
26+
Ω(result[0].date.Equal(endDate)).Should(BeTrue(), "first date must equal end date")
2827
Ω(result[0].duration).Should(Equal(firstDayDuration), "first day must have the right duration")
2928
for _, usage := range result[1:] {
3029
Ω(usage.duration).Should(Equal(24 * time.Hour))
3130
}
32-
})
33-
34-
It("reversed: should calculate the usage for a 1 week span", func() {
35-
firstDayDuration := 23*time.Hour + 59*time.Minute + 59*time.Second
36-
37-
end := time.Now().UTC()
38-
endDate := end.Truncate(24 * time.Hour)
39-
end = endDate.Add(firstDayDuration)
40-
41-
start := end.Add(-7 * 24 * time.Hour)
42-
start = start.Truncate(24 * time.Hour)
43-
44-
result := calculateUsage(end, start)
45-
46-
Ω(len(result)).Should(Equal(8))
4731

48-
Ω(result[0].date.Equal(endDate)).Should(Equal(true), "first date must equal end date")
49-
Ω(result[0].duration).Should(Equal(firstDayDuration), "first day must have the right duration")
50-
for _, usage := range result[1:] {
51-
fmt.Println(usage.date, usage.duration)
52-
Ω(usage.duration).Should(Equal(24 * time.Hour))
53-
}
32+
reversed := calculateUsage(end, start)
33+
Ω(result).Should(Equal(reversed), "the calculation must be reversed the same")
5434
})
5535
})
5636
})

0 commit comments

Comments
 (0)