Skip to content

Commit e4165d4

Browse files
Merge pull request #91 from fabianoflorentino/development
Development to Main
2 parents d07a911 + 8db8532 commit e4165d4

File tree

12 files changed

+439
-133
lines changed

12 files changed

+439
-133
lines changed

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
golang 1.24.1
1+
golang 1.24.3

build/Dockerfile.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:alpine3.20 AS builder
1+
FROM golang:alpine3.21 AS builder
22

33
WORKDIR /aprendago
44

build/Dockerfile.prod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
FROM golang:alpine3.20 AS builder
1+
FROM golang:alpine3.21 AS builder
22

33
WORKDIR /aprendago
44

55
COPY . .
66

77
RUN go build -o /go/bin/aprendago cmd/aprendago/main.go
88

9-
FROM alpine:3.20 as aprendago
9+
FROM alpine:3.21 as aprendago
1010

1111
COPY --from=builder /go/bin/aprendago /go/bin/aprendago
1212

internal/agrupamento_de_dados/menu_test.go

Lines changed: 17 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"os"
55
"testing"
66

7-
base "github.com/fabianoflorentino/aprendago/pkg/base_content"
7+
"github.com/fabianoflorentino/aprendago/pkg/format"
88
)
99

1010
func TestMenu(t *testing.T) {
@@ -23,38 +23,16 @@ func TestMenu(t *testing.T) {
2323

2424
t.Run("TestMenuOptionsLengthAndContent", func(t *testing.T) {
2525
// Create a slice of MenuOptions.
26-
menuOptions := Menu(
27-
[]string{
28-
flagArray,
29-
flagSliceLiteralComposta,
30-
flagSliceForRange,
31-
flagSliceFatiandoOuDeletando,
32-
flagSliceAnexando,
33-
flagSliceMake,
34-
flagSliceMultiDimensional,
35-
flagSliceSurpresaArraySubjacente,
36-
flagMapsIntroducao,
37-
})
26+
mo := menuOptions(topics)
3827

3928
// Check if the menuOptions slice has the expected length.
40-
if len(menuOptions) != 10 {
41-
t.Errorf("Expected menuOptions length of 10, got %v", len(menuOptions))
29+
if len(mo) != 10 {
30+
t.Errorf("Expected menuOptions length of 10, got %v", len(mo))
4231
}
4332
})
4433

4534
t.Run("TestMenuOptionsContent", func(t *testing.T) {
46-
menuOptions := Menu(
47-
[]string{
48-
flagArray,
49-
flagSliceLiteralComposta,
50-
flagSliceForRange,
51-
flagSliceFatiandoOuDeletando,
52-
flagSliceAnexando,
53-
flagSliceMake,
54-
flagSliceMultiDimensional,
55-
flagSliceSurpresaArraySubjacente,
56-
flagMapsIntroducao,
57-
})
35+
mo := menuOptions(topics)
5836

5937
expectedOptions := []string{
6038
"--array",
@@ -69,54 +47,28 @@ func TestMenu(t *testing.T) {
6947
"--maps-range-e-deletando",
7048
}
7149

72-
for i, option := range menuOptions {
50+
for i, option := range mo {
7351
if option.Options != expectedOptions[i] {
7452
t.Errorf("Expected option %v to be %v, got %v", i, expectedOptions[i], option.Options)
7553
}
7654
}
7755
})
7856

79-
t.Run("TestMenuOptionsExecutionFunctions", func(t *testing.T) {
80-
menuOptions := Menu(
81-
[]string{
82-
flagArray,
83-
flagSliceLiteralComposta,
84-
flagSliceForRange,
85-
flagSliceFatiandoOuDeletando,
86-
flagSliceAnexando,
87-
flagSliceMake,
88-
flagSliceMultiDimensional,
89-
flagSliceSurpresaArraySubjacente,
90-
flagMapsIntroducao,
91-
})
57+
t.Run("TestMenuOptionsExecFunc", func(t *testing.T) {
58+
mo := menuOptions(topics)
9259

93-
for i, option := range menuOptions {
94-
if option.ExecFunc == nil {
95-
t.Errorf("Expected option %v to have a non-nil execution function", i)
96-
}
97-
}
98-
99-
m := base.New()
100-
newExecFunc := []func(){
101-
func() { m.SectionFormat(array, m.SectionFactory(rootDir)) },
102-
func() { m.SectionFormat(sliceLiteralComposta, m.SectionFactory(rootDir)) },
103-
func() { m.SectionFormat(sliceForRange, m.SectionFactory(rootDir)) },
104-
func() { m.SectionFormat(sliceFatiandoOuDeletando, m.SectionFactory(rootDir)) },
105-
func() { m.SectionFormat(sliceAnexando, m.SectionFactory(rootDir)) },
106-
func() { m.SectionFormat(sliceMake, m.SectionFactory(rootDir)) },
107-
func() { m.SectionFormat(sliceMultiDimensional, m.SectionFactory(rootDir)) },
108-
func() { m.SectionFormat(sliceSurpresaArraySubjacente, m.SectionFactory(rootDir)) },
109-
func() { m.SectionFormat(mapsIntroducao, m.SectionFactory(rootDir)) },
110-
func() { m.SectionFormat(mapsRangeEDeletando, m.SectionFactory(rootDir)) },
60+
if len(mo) != 10 {
61+
t.Fatalf("Expected menuOptions length of 10, got %v", len(mo))
11162
}
11263

113-
for i, execFunc := range newExecFunc {
114-
if menuOptions[i].ExecFunc == nil || execFunc == nil {
115-
t.Errorf("Execution function for option %v is nil", i)
116-
} else {
117-
menuOptions[i].ExecFunc()
118-
execFunc()
64+
for i, option := range mo {
65+
if option.ExecFunc == nil {
66+
t.Errorf("Expected ExecFunc for option %v to be non-nil", i)
11967
}
12068
}
12169
})
12270
}
71+
72+
func menuOptions(listMenu []string) []format.MenuOptions {
73+
return Menu(listMenu)
74+
}

internal/agrupamento_de_dados/topic_test.go

Lines changed: 76 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,88 @@ package agrupamento_de_dados
33
import (
44
"os"
55
"testing"
6-
)
76

8-
func init() {
9-
rootDir = "./"
10-
}
7+
"github.com/fabianoflorentino/aprendago/pkg/topic"
8+
)
119

1210
func TestTopics(t *testing.T) {
13-
oldStdout := os.Stdout
14-
defer func() { os.Stdout = oldStdout }()
11+
os.Setenv("GOENV", "test")
1512

16-
nullFile, err := os.OpenFile(os.DevNull, os.O_WRONLY, 0)
17-
if err != nil {
18-
t.Fatalf("failed to open null device: %v", err)
13+
tt := topic.New()
14+
15+
list := []string{
16+
sliceLiteralComposta,
17+
sliceForRange,
18+
sliceFatiandoOuDeletando,
19+
sliceAnexando,
20+
sliceMake,
21+
sliceMultiDimensional,
22+
sliceSurpresaArraySubjacente,
23+
mapsIntroducao,
24+
mapsRangeEDeletando,
1925
}
20-
defer nullFile.Close()
2126

22-
os.Stdout = nullFile
27+
t.Run("TestRootDirValidation", func(t *testing.T) {
28+
if rootDir != "internal/agrupamento_de_dados" {
29+
t.Errorf("Expected rootDir to be 'internal/agrupamento_de_dados', got '%s'", rootDir)
30+
}
31+
})
2332

24-
Topics()
33+
t.Run("TestListOfTopicsWithValidInput", func(t *testing.T) {
34+
expectedLength := 9
35+
topics := tt.ListOfTopics(list, expectedLength)
36+
if len(topics) != expectedLength {
37+
t.Errorf("Expected %d topics, got %d", expectedLength, len(topics))
38+
}
2539

26-
if err != nil {
27-
t.Errorf("Topics() failed: %v", err)
28-
}
40+
expectedTopics := []string{
41+
sliceLiteralComposta,
42+
sliceForRange,
43+
sliceFatiandoOuDeletando,
44+
sliceAnexando,
45+
sliceMake,
46+
sliceMultiDimensional,
47+
sliceSurpresaArraySubjacente,
48+
mapsIntroducao,
49+
mapsRangeEDeletando,
50+
}
51+
52+
for i, topic := range expectedTopics {
53+
if topics[i] != topic {
54+
t.Errorf("Expected topic at index %d to be %s, got %s", i, topic, topics[i])
55+
}
56+
}
57+
})
58+
59+
t.Run("TestListOfTopicsWithLimitGreaterThanListSize", func(t *testing.T) {
60+
limit := 10
61+
topics := tt.ListOfTopics(list, limit)
62+
if len(topics) != len(list) {
63+
t.Errorf("Expected %d topics, got %d", len(list), len(topics))
64+
}
65+
})
66+
67+
t.Run("TestListOfTopicsWithZeroLimit", func(t *testing.T) {
68+
limit := 0
69+
topics := tt.ListOfTopics(list, limit)
70+
if len(topics) != 0 {
71+
t.Errorf("Expected 0 topics, got %d", len(topics))
72+
}
73+
})
74+
75+
t.Run("TestListOfTopicsWithNegativeLimit", func(t *testing.T) {
76+
limit := -5
77+
topics := tt.ListOfTopics(list, limit)
78+
if len(topics) != 0 {
79+
t.Errorf("Expected 0 topics, got %d", len(topics))
80+
}
81+
})
82+
83+
t.Run("TestListOfTopicsWithEmptyList", func(t *testing.T) {
84+
emptyList := []string{}
85+
topics := tt.ListOfTopics(emptyList, 5)
86+
if len(topics) != 0 {
87+
t.Errorf("Expected 0 topics for empty list, got %d", len(topics))
88+
}
89+
})
2990
}

internal/aplicacoes/help_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package aplicacoes
2+
3+
import (
4+
"os"
5+
"testing"
6+
)
7+
8+
func TestHelp(t *testing.T) {
9+
var err error
10+
11+
oldStdout := os.Stdout
12+
defer func() { os.Stdout = oldStdout }()
13+
14+
nullFile, err := os.OpenFile(os.DevNull, os.O_WRONLY, 0)
15+
if err != nil {
16+
t.Fatalf("failed to open null device: %v", err)
17+
}
18+
defer nullFile.Close()
19+
20+
os.Stdout = nullFile
21+
22+
Help()
23+
24+
if err != nil {
25+
t.Errorf("Help() failed: %v", err)
26+
}
27+
}

0 commit comments

Comments
 (0)