-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_coverage_test.go
More file actions
130 lines (108 loc) · 2.89 KB
/
main_coverage_test.go
File metadata and controls
130 lines (108 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package main
import (
"flag"
"os"
"path/filepath"
"testing"
log "github.com/sirupsen/logrus"
)
// testSimpleFlagParsing tests simple flag parsing logic
func testSimpleFlagParsing(t *testing.T) {
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
configFilePath = flag.String("c", "", "Configuration file location")
help = flag.Bool("h", false, "Usage information")
os.Args = []string{"bucketsyncd", "-c", "/tmp/config.yaml"}
flag.Parse()
configEmpty := *configFilePath == ""
helpRequested := *help
if configEmpty && !helpRequested {
t.Log("Would show error: -c option is required")
}
if helpRequested || configEmpty {
t.Log("Would show usage information")
}
}
// testSimpleLogging tests simple logging configuration
func testSimpleLogging(_ *testing.T) {
config.LogLevel = debugLevel
config.LogJSON = false
log.SetFormatter(&log.TextFormatter{
DisableColors: true,
FullTimestamp: true,
})
switch config.LogLevel {
case debugLevel:
log.SetLevel(log.DebugLevel)
case infoLevel:
log.SetLevel(log.InfoLevel)
case warnLevel:
log.SetLevel(log.WarnLevel)
}
if config.LogLevel == debugLevel {
log.SetLevel(log.DebugLevel)
}
if config.LogJSON {
log.SetFormatter(&log.JSONFormatter{})
}
}
// testSimpleConfigReading tests simple config file reading
func testSimpleConfigReading(t *testing.T) {
tmpDir := t.TempDir()
configFile := filepath.Join(tmpDir, "simple-test.yaml")
configContent := `
log_level: "info"
log_json: false
outbound: []
inbound: []
remotes: []
`
err := os.WriteFile(configFile, []byte(configContent), 0600)
if err != nil {
t.Fatalf("Failed to create config file: %v", err)
}
err = readConfig(configFile)
if err != nil {
t.Logf("Config reading would cause panic: %v", err)
} else {
t.Log("Config reading successful")
}
}
// testSimpleProcessing tests simple processing loop
func testSimpleProcessing(t *testing.T) {
config = Config{
Outbound: []Outbound{
{Name: "test1", Source: "/tmp/test1/*"},
{Name: "test2", Source: "/tmp/test2/*"},
},
}
processedCount := 0
for i := 0; i < len(config.Outbound); i++ {
o := config.Outbound[i]
processedCount++
t.Logf("Would process outbound: %s", o.Name)
}
if processedCount != 2 {
t.Errorf("Expected 2 outbound processed, got %d", processedCount)
}
}
// TestSimpleMainComponents tests main function components with reduced complexity
func TestSimpleMainComponents(t *testing.T) {
originalArgs := os.Args
originalConfigFilePath := *configFilePath
originalHelp := *help
originalConfig := config
originalLevel := log.GetLevel()
originalFormatter := log.StandardLogger().Formatter
defer func() {
os.Args = originalArgs
*configFilePath = originalConfigFilePath
*help = originalHelp
config = originalConfig
log.SetLevel(originalLevel)
log.SetFormatter(originalFormatter)
}()
testSimpleFlagParsing(t)
testSimpleLogging(t)
testSimpleConfigReading(t)
testSimpleProcessing(t)
}