-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_test.go
82 lines (68 loc) · 1.92 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
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
package concourse_tfe_resource
import (
"bytes"
"encoding/json"
"os"
"path"
"strings"
"testing"
)
func TestStartup(t *testing.T) {
input := inputJSON{
Source: sourceJSON{},
Params: paramsJSON{},
Version: version{},
}
err := startup(input)
if err == nil || !strings.Contains(err.Error(), "creating tfe client") {
t.Errorf("no/bad error creating client with empty config: %s", err)
}
input.Source.Token = os.Getenv("ATLAS_TOKEN")
err = startup(input)
if err == nil || !strings.Contains(err.Error(), "getting workspace") {
t.Errorf("no/bad error without org/workspace set: %s", err)
}
input.Source.Workspace = os.Getenv("TFE_WORKSPACE")
input.Source.Organization = os.Getenv("TFE_ORGANIZATION")
err = startup(input)
if err != nil {
t.Errorf("startup failed with valid config: %s", err)
}
}
func TestRealMain(t *testing.T) {
input := inputJSON{
Source: sourceJSON{
Workspace: os.Getenv("TFE_WORKSPACE"),
Organization: os.Getenv("TFE_ORGANIZATION"),
Token: os.Getenv("ATLAS_TOKEN"),
Address: os.Getenv("TFE_ADDRESS"),
},
Params: paramsJSON{
PollingPeriod: 5,
},
}
args := []string{"check"}
byteInput, _ := json.Marshal(input)
output, err := realMain(args, bytes.NewReader(byteInput))
if err != nil {
t.Errorf("check failed: %s", err)
}
wd, _ := os.Getwd()
_ = os.Mkdir(path.Join(wd, "test_output", "test_main_in"), os.FileMode(0755))
run := make([]version, 1)
_ = json.Unmarshal(output, &run)
args = []string{"in", path.Join("test_output", "test_main_in")}
input.Version = version{Ref: run[0].Ref}
byteInput, _ = json.Marshal(input)
_, err = realMain(args, bytes.NewReader(byteInput))
if err != nil {
t.Errorf("in on checked run failed: %s", err)
}
args[0] = "out"
input.Params.Message = "TestRealMain out test"
byteInput, _ = json.Marshal(input)
_, err = realMain(args, bytes.NewReader(byteInput))
if err != nil {
t.Errorf("out failed: %s", err)
}
}