/
main_test.go
111 lines (85 loc) · 2.29 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
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
109
110
111
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path"
"testing"
//"github.com/stretchr/testify/assert"
"github.com/hoisie/mustache"
"gopkg.in/yaml.v2"
)
type BuildFile struct {
Language string `yaml:"language"`
BeforeInstall []string `yaml:"before_install"`
Install []string `yaml:"install"`
BeforeScript []string `yaml:"before_script"`
Script []string `yaml:"script"`
AfterScript []string `yaml:"after_script"`
AfterSuccess []string `yaml:"after_success"`
AfterFailure []string `yaml:"after_failure"`
BeforeDeploy []string `yaml:"before_deploy"`
Deploy []string `yaml:"deploy"`
AfterDeploy []string `yaml:"after_deploy"`
}
type GithubRepository struct {
Url string `json:"url"`
}
type GithubPushEvent struct {
Repository GithubRepository `json:"repository"`
}
func TestParsingGithubPayload(t *testing.T) {
var event GithubPushEvent
data, err := ioutil.ReadFile("./sample-github-webhook.payload")
if err != nil {
panic(err)
}
json.Unmarshal(data, &event)
fmt.Println(fmt.Sprintf("%v", event))
}
func TestParsingTravisFile(t *testing.T) {
var buildFile BuildFile
data, err := ioutil.ReadFile("./example.travis.yml")
if err != nil {
panic(err)
}
yaml.Unmarshal(data, &buildFile)
fmt.Println(fmt.Sprintf("%v", buildFile))
}
func TestRenderingABuildFile(t *testing.T) {
var buildFile BuildFile
travisData, err := ioutil.ReadFile("./example.travis.yml")
if err != nil {
panic(err)
}
yaml.Unmarshal(travisData, &buildFile)
fmt.Println(fmt.Sprintf("%v", buildFile))
buildTemplate, err := ioutil.ReadFile("./template-build.sh")
if err != nil {
panic(err)
}
data := mustache.Render(string(buildTemplate), buildFile)
println(data)
}
func TestCreatingTempDirectoryStructure(t *testing.T) {
fmt.Println(os.TempDir())
rootPath := path.Join(os.TempDir(),"jarvis")
os.MkdirAll(rootPath,0777)
tempDir, err := ioutil.TempDir(rootPath, "")
if err != nil {
panic(err)
}
outputPath := path.Join(tempDir, "/output")
buildPath := path.Join(tempDir, "/build")
os.MkdirAll(outputPath,0777)
os.MkdirAll(buildPath,0777)
fmt.Println(outputPath)
fmt.Println(buildPath)
fmt.Println(tempDir)
}
func TestInitiateABuild(t *testing.T){
testServer := CreateRequestRecordingServer(TestPort)
testServer.Start()
testServer.Stop()
}