-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathmain_test.go
More file actions
42 lines (34 loc) · 912 Bytes
/
main_test.go
File metadata and controls
42 lines (34 loc) · 912 Bytes
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
package main
import (
"testing"
"rules-cli/cmd"
)
func TestVersionSetting(t *testing.T) {
// Test that the version is passed to the cmd package
originalVersion := Version
originalCmdVersion := cmd.Version
defer func() {
Version = originalVersion
cmd.Version = originalCmdVersion
}()
Version = "test-main-version"
cmd.Version = Version
if cmd.Version != "test-main-version" {
t.Errorf("Expected cmd.Version to be 'test-main-version', got %s", cmd.Version)
}
}
func TestMainFunction(t *testing.T) {
// Test that main function exists and doesn't panic when version is set
defer func() {
if r := recover(); r != nil {
t.Errorf("main() related functions panicked: %v", r)
}
}()
// Test that Version variable exists and can be set
originalVersion := Version
Version = "test"
if Version != "test" {
t.Error("Version variable should be settable")
}
Version = originalVersion
}