-
Notifications
You must be signed in to change notification settings - Fork 0
/
go.go
65 lines (48 loc) · 956 Bytes
/
go.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
package main
import (
"io/ioutil"
"os"
)
const (
_mainTemplate = `package main
import "fmt"
func result() string {
return "foo"
}
func main() {
fmt.Printf("Result is: %s", result())
}
`
_testTemplate = `package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestResult(t *testing.T) {
t.Skip()
assert.False(t, true)
}
`
)
func bootstrap_go(name string) error {
if err := os.Setenv("GO111MODULE", "on"); err != nil {
return err
}
gotool("mod", "init", "github.com/aignas/katas/"+name)
if err := writeGoFile("main.go", _mainTemplate); err != nil {
return err
}
if err := writeGoFile("main_test.go", _testTemplate); err != nil {
return err
}
return gotool("test", "./...")
}
func writeGoFile(name, text string) error {
if err := ioutil.WriteFile(name, []byte(text), 0755); err != nil {
return err
}
return gotool("fmt", name)
}
func gotool(args ...string) error {
return sh("go", args...)
}