-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathmain_test.go
More file actions
42 lines (34 loc) · 876 Bytes
/
main_test.go
File metadata and controls
42 lines (34 loc) · 876 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 (
"os"
"testing"
)
func TestReadConfig(t *testing.T) {
err := readConfig()
if err != nil {
t.Errorf("Cannot read config file. Error: %v", err)
}
}
func TestCorrectToken(t *testing.T) {
token := "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
if err := os.Setenv("TEST_TOKEN", token); err != nil {
t.Fatalf("Failed to set env variable: %v", err)
}
v, err := getToken("TEST_TOKEN")
if err != nil {
t.Errorf("Incorrect token. Error: %v", err)
}
if v != token {
t.Errorf("Incorrect token. Expected: %v, Have: %v", token, v)
}
}
func TestIncorrectToken(t *testing.T) {
token := "a123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
if err := os.Setenv("TEST_TOKEN", token); err != nil {
t.Fatalf("Failed to set env variable: %v", err)
}
v, _ := getToken("TEST_TOKEN")
if v != "" {
t.Errorf(`Case failed. Expected "", Have: %v`, v)
}
}