@@ -5,33 +5,25 @@ import (
55 "testing"
66)
77
8- type MockContentsProvider struct {
9- CalledWithRootDir string
10- CalledWithTopics []string
8+ func init () {
9+ rootDir = "./"
1110}
1211
13- func (m * MockContentsProvider ) TopicsContents (rootDir string , topics []string ) {
14- m .CalledWithRootDir = rootDir
15- m .CalledWithTopics = topics
16- }
17-
18- func TestTopicsAgrupamentoDeDados (t * testing.T ) {
19- os .Setenv ("GOENV" , "test" )
12+ func TestTopics (t * testing.T ) {
13+ oldStdout := os .Stdout
14+ defer func () { os .Stdout = oldStdout }()
2015
21- rootDir := os .Getenv ("GOENV" )
22-
23- if rootDir != "test" {
24- t .Errorf ("Expected rootDir to be 'test', got '%s'" , rootDir )
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 )
2519 }
20+ defer nullFile .Close ()
2621
27- mockProvider := & MockContentsProvider {}
28- mockProvider .TopicsContents (rootDir , []string {"topic1" , "topic2" })
22+ os .Stdout = nullFile
2923
30- if mockProvider .CalledWithRootDir != rootDir {
31- t .Errorf ("Expected rootDir to be 'test', got '%s'" , mockProvider .CalledWithRootDir )
32- }
24+ Topics ()
3325
34- if len ( mockProvider . CalledWithTopics ) != 2 {
35- t .Errorf ("Expected 2 topics, got %d " , len ( mockProvider . CalledWithTopics ) )
26+ if err != nil {
27+ t .Errorf ("Topics() failed: %v " , err )
3628 }
3729}
0 commit comments