generated from cloudbees-io/sample-go-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
49 lines (43 loc) · 1.12 KB
/
main_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
package main
import (
"io/ioutil"
"os"
"testing"
)
func TestGetCommitSha(t *testing.T) {
sha := "abcd1234"
ioutil.WriteFile("sha.txt", []byte(sha), 0644)
defer os.Remove("sha.txt")
result := getCommitSha()
if result != sha {
t.Errorf("getCommitSha() = %s; want %s", result, sha)
}
}
func TestGetColor(t *testing.T) {
sha := "abcd1234"
expectedColor := "#e9cee7"
if result := getColor(sha); result != expectedColor {
t.Errorf("getColor() = %s; want %s", result, expectedColor)
}
}
func TestGetTextColor(t *testing.T) {
tests := []struct {
backgroundColor string
expectedColor string
}{
{"#FFFFFF", "#000000"},
{"#000000", "#FFFFFF"},
}
for _, test := range tests {
if result := getTextColor(test.backgroundColor); result != test.expectedColor {
t.Errorf("getTextColor(%s) = %s; want %s", test.backgroundColor, result, test.expectedColor)
}
}
}
func TestGetEnvironment(t *testing.T) {
os.Setenv("ENVIRONMENT", "production")
expectedEnvironment := "production"
if result := getEnvironment(); result != expectedEnvironment {
t.Errorf("getEnvironment() = %s; want %s", result, expectedEnvironment)
}
}