-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrest2command_test.go
74 lines (60 loc) · 1.78 KB
/
rest2command_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
package main
import (
log "github.com/Sirupsen/logrus"
"github.com/stretchr/testify/assert"
"os"
"testing"
)
func TestGetAPIVersion(t *testing.T) {
assert.Equal(t, "1", getAPIVersion("1.0.0"), "getting version")
assert.Equal(t, "0", getAPIVersion("1.0"), "getting version")
}
func TestBuildCommands(t *testing.T) {
var configurations = []Configuration{
{
Url: "/v1/command1",
Command: "/opt/command1",
Args: "arg1 arg2",
},
{
Url: "/v1/command2",
Command: "/opt/command2",
},
}
var commands = map[string]Command{
"/v1/command1": {Command: "/opt/command1", Args: "arg1 arg2"},
"/v1/command2": {Command: "/opt/command2", Args: ""},
}
//
commandsResult := buildCommands(configurations)
assert.Equal(t, commands, commandsResult, "build command")
}
func TestSetUp(t *testing.T) {
setUp()
assert.Equal(t, ":9999", Port, "default port")
assert.Equal(t, "/etc/rest2command/configuration.json", ConfigurationFile, "default configuration file")
assert.Equal(t, "./credentials.json", CredentialsFile, "default credentials")
os.Setenv("PORT", "123")
os.Setenv("FILE_CONFIGURATION", "./configuration.json")
os.Setenv("FILE_CREDENTIALS", "/etc/rest2command/credentials.json")
setUp()
assert.Equal(t, ":123", Port, "Setting port")
assert.Equal(t, "./configuration.json", ConfigurationFile, "Setting configuration file")
assert.Equal(t, "/etc/rest2command/credentials.json", CredentialsFile, "Setting credentials")
}
func TestSetUpLog(t *testing.T) {
levels := map[string]string{
"info": "info",
"debug": "debug",
"panic": "panic",
"error": "error",
"warn": "warning",
"fatal": "fatal",
"": "info",
}
for key, value := range levels {
os.Setenv("LOG_LEVEL", key)
setUpLog()
assert.Equal(t, log.GetLevel().String(), value, key+"OK")
}
}