-
Notifications
You must be signed in to change notification settings - Fork 0
/
distribution_test.go
108 lines (94 loc) · 2.11 KB
/
distribution_test.go
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
package solc
import (
"context"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetDistribution(t *testing.T) {
tempDir, err := os.MkdirTemp("", "test")
assert.NoError(t, err)
assert.NotEmpty(t, tempDir)
defer os.RemoveAll(tempDir)
tests := []struct {
name string
goos string
expected Distribution
}{
{
name: "Windows OS",
goos: Windows.String(),
expected: Windows,
},
{
name: "MacOS",
goos: MacOS.String(),
expected: MacOS,
},
{
name: "Linux OS",
goos: Linux.String(),
expected: Linux,
},
{
name: "Unknown OS",
goos: "solaris", // Just an example of an OS that's not in our main switch case
expected: Unknown,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
config, err := NewDefaultConfig()
assert.NoError(t, err)
assert.NotNil(t, config)
err = config.SetReleasesPath(tempDir)
assert.NoError(t, err)
assert.Equal(t, tempDir, config.GetReleasesPath())
s, err := New(context.TODO(), config)
assert.NoError(t, err)
assert.NotNil(t, s)
s.gOOSFunc = func() string { return tt.goos }
assert.Equal(t, tt.expected, s.GetDistribution())
})
}
}
func TestGetDistributionForAsset(t *testing.T) {
tests := []struct {
name string
goos string
expected string
}{
{
name: "Windows OS Asset",
goos: "windows",
expected: "solc-windows",
},
{
name: "MacOS Asset",
goos: "darwin",
expected: "solc-macos",
},
{
name: "Linux OS Asset",
goos: "linux",
expected: "solc-static-linux",
},
{
name: "Unknown OS Asset",
goos: "solaris", // Just an example of an OS that's not in our main switch case
expected: "unknown",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
config, err := NewDefaultConfig()
assert.NoError(t, err)
assert.NotNil(t, config)
s, err := New(context.TODO(), config)
assert.NoError(t, err)
assert.NotNil(t, s)
s.gOOSFunc = func() string { return tt.goos }
assert.Equal(t, tt.expected, s.GetDistributionForAsset())
})
}
}