Skip to content

Commit 5e03381

Browse files
committed
tests(style): add syntax checking in make test-style
1 parent b67c29a commit 5e03381

8 files changed

Lines changed: 65 additions & 54 deletions

File tree

Makefile

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,27 @@ build:
66
installer:
77
rm -rf dist && mkdir -p dist
88
godep go build -a -o dist/deisctl .
9-
command -v upx >/dev/null 2>&1 && upx --best --ultra-brute -q dist/deisctl
10-
makeself.sh --current --nox11 dist \
9+
makeself.sh --bzip2 --current --nox11 dist \
1110
dist/deisctl-`cat deis-version`-`go env GOOS`-`go env GOARCH`.run \
1211
"Deis Control CLI" "./deisctl refresh-units"
1312

1413
install:
1514
godep go install -v ./...
1615

17-
test:
18-
godep go test -v ./...
16+
setup-root-gotools:
17+
sudo GOPATH=/tmp/tmpGOPATH go get -u -v code.google.com/p/go.tools/cmd/cover
18+
sudo GOPATH=/tmp/tmpGOPATH go get -u -v code.google.com/p/go.tools/cmd/vet
19+
sudo rm -rf /tmp/tmpGOPATH
20+
21+
setup-gotools:
22+
go get -v github.com/golang/lint/golint
23+
24+
test-style:
25+
go vet -x ./...
26+
-golint *.go client/ cmd/ config/ constant/ hooks/ lock/ systemd/ units/ update/ utils/
27+
28+
test: test-style
29+
godep go test -v -cover ./...
1930

2031
package:
2132
rm -f package

client/registry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func getRegistryClient() (client.API, error) {
107107
// fmt.Fprint(os.Stderr, msg)
108108
// }
109109

110-
return &client.RegistryClient{reg}, nil
110+
return &client.RegistryClient{Registry: reg}, nil
111111
}
112112

113113
// checkVersion makes a best-effort attempt to verify that fleetctl is at least as new as the

client/unit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
// path hierarchy for finding systemd service templates
1717
var rootPaths = []string{"/var/lib/deis/units", "~/.deisctl/units"}
1818

19-
// getUnits returns a list of units filtered by target
19+
// Units returns a list of units filtered by target
2020
func (c *FleetClient) Units(target string) (units []string, err error) {
2121
allUnits, err := c.Fleet.Units()
2222
if err != nil {

cmd/cmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ func RefreshUnits() error {
268268
}
269269

270270
// download and save the unit files to $HOME/.deisctl
271-
rootUrl := "https://raw.githubusercontent.com/deis/deisctl/"
271+
rootURL := "https://raw.githubusercontent.com/deis/deisctl/"
272272
branch := "master"
273273
units := []string{
274274
"deis-builder.service",
@@ -284,7 +284,7 @@ func RefreshUnits() error {
284284
"deis-router.service",
285285
}
286286
for _, unit := range units {
287-
src := rootUrl + branch + "/units/" + unit
287+
src := rootURL + branch + "/units/" + unit
288288
dest := filepath.Join(dir, unit)
289289
res, err := http.Get(src)
290290
if err != nil {

constant/constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const (
66
UnitsDir = "/var/lib/deis/units/"
77
HooksDir = "/var/lib/deis/hooks/"
88
Version = "/etc/deis-version"
9-
MachineId = "/etc/machine-id"
9+
MachineID = "/etc/machine-id"
1010
UpdatekeyDir = "/deis/update/"
1111
InitialInterval = time.Second * 10
1212
MaxInterval = time.Minute * 7

update/client.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,28 @@ import (
2121
)
2222

2323
type Client struct {
24-
Id string
25-
SessionId string
24+
ID string
25+
SessionID string
2626
Version string
27-
AppId string
27+
AppID string
2828
Track string
2929
config *serverConfig
3030
errorRate int
3131
pingsRemaining int
3232
lock *lock.Lock
3333
}
3434

35-
func (c *Client) Log(format string, v ...interface{}) {
36-
format = c.Id + ": " + format
37-
fmt.Printf(format, v...)
35+
func (c *Client) Logf(format string, args ...interface{}) {
36+
format = c.ID + ": " + format
37+
fmt.Printf(format, args...)
3838
}
3939

4040
func (c *Client) failed(tag string, err error) {
41-
c.Log("%s %v\n", tag, err)
41+
c.Logf("%s %v\n", tag, err)
4242
c.MakeRequest("3", "0", false, false)
4343
}
4444

45-
func (c *Client) getCodebaseUrl(uc *omaha.UpdateCheck) string {
45+
func (c *Client) getCodebaseURL(uc *omaha.UpdateCheck) string {
4646
return uc.Urls.Urls[0].CodeBase + uc.Manifest.Packages.Packages[0].Name
4747
}
4848

@@ -61,9 +61,9 @@ func (c *Client) RequestLock() {
6161

6262
func (c *Client) OmahaRequest(otype, result string, updateCheck, isPing bool) *omaha.Request {
6363
req := omaha.NewRequest("lsb", "CoreOS", "", "")
64-
app := req.AddApp(c.AppId, c.Version)
65-
app.MachineID = c.Id
66-
app.BootId = c.SessionId
64+
app := req.AddApp(c.AppID, c.Version)
65+
app.MachineID = c.ID
66+
app.BootId = c.SessionID
6767
app.Track = c.Track
6868
app.OEM = Flags.OEM
6969

@@ -113,15 +113,15 @@ func (c *Client) MakeRequest(otype, result string, updateCheck, isPing bool) (*o
113113

114114
if Flags.verbose {
115115
raw, _ := xml.MarshalIndent(req, "", " ")
116-
c.Log("request: %s\n", string(raw))
116+
c.Logf("request: %s\n", string(raw))
117117
raw, _ = xml.MarshalIndent(oresp, "", " ")
118-
c.Log("response: %s\n", string(raw))
118+
c.Logf("response: %s\n", string(raw))
119119
}
120120

121121
return oresp, nil
122122
}
123123

124-
// Sleep between n and m seconds
124+
// Loop between n and m seconds
125125
func (c *Client) Loop(n, m int) {
126126
interval := constant.InitialInterval
127127
for {
@@ -133,15 +133,15 @@ func (c *Client) Loop(n, m int) {
133133
}
134134
uc := resp.Apps[0].UpdateCheck
135135
if uc.Status != "ok" {
136-
c.Log("update check status: %s\n", uc.Status)
136+
c.Logf("update check status: %s\n", uc.Status)
137137
} else {
138-
url := c.getCodebaseUrl(uc)
138+
url := c.getCodebaseURL(uc)
139139
if !strings.Contains(url, "deis") {
140140
c.failed("Wrong Url", err)
141141
continue
142142
}
143143
c.MakeRequest("13", "1", false, false)
144-
err = c.downloadFromUrl(url, "/tmp/deis.tar.gz")
144+
err = c.downloadFromURL(url, "/tmp/deis.tar.gz")
145145
if err != nil {
146146
c.failed("Download failed", err)
147147
continue
@@ -181,7 +181,7 @@ func (c *Client) SetVersion(resp *omaha.Response) {
181181
// A field can potentially be nil.
182182
defer func() {
183183
if err := recover(); err != nil {
184-
c.Log("%s: error setting version: %v", c.Id, err)
184+
c.Logf("%s: error setting version: %v", c.ID, err)
185185
}
186186
}()
187187
uc := resp.Apps[0].UpdateCheck
@@ -191,9 +191,9 @@ func (c *Client) SetVersion(resp *omaha.Response) {
191191
c.failed("update failed", err)
192192
return
193193
}
194-
c.Log("Installation done ")
194+
c.Logf("Installation done ")
195195
c.MakeRequest("2", "1", false, false)
196-
c.Log("Update done ")
196+
c.Logf("Update done ")
197197
c.MakeRequest("3", "1", false, false)
198198
// installed
199199

@@ -204,7 +204,7 @@ func (c *Client) SetVersion(resp *omaha.Response) {
204204
time.Sleep(1 * time.Second)
205205
}
206206

207-
c.Log("updated from %s to %s\n", c.Version, uc.Manifest.Version)
207+
c.Logf("updated from %s to %s\n", c.Version, uc.Manifest.Version)
208208

209209
c.Version = uc.Manifest.Version
210210
utils.PutVersion(c.Version)
@@ -214,7 +214,7 @@ func (c *Client) SetVersion(resp *omaha.Response) {
214214
log.Println(err)
215215
}
216216

217-
c.SessionId = uuid.New()
217+
c.SessionID = uuid.New()
218218
}
219219

220220
func (c *Client) Update() (err error) {
@@ -250,7 +250,7 @@ func (c *Client) Update() (err error) {
250250
return nil
251251
}
252252

253-
func (c *Client) downloadFromUrl(url, filePath string) (err error) {
253+
func (c *Client) downloadFromURL(url, filePath string) (err error) {
254254
fmt.Printf("Downloading %s to %s\n", url, filePath)
255255

256256
output, err := os.Create(filePath)

update/update.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ const (
1818
DefaultOmahaServer = "https://opdemand.update.core-os.net"
1919
// DefaultOEM string to report to Omaha Server
2020
DefaultOEM = "deisctl"
21-
// DefaultAppId used for Omaha protocol
22-
DefaultAppId = "0ccac0df-ca24-4f2b-bb7b-4a265bd0eb33"
23-
// DefaultGroupId used for Omaha protocol
24-
DefaultGroupId = "2e87b742-68c9-4d08-8f37-5cb7bb2c9d3a"
21+
// DefaultAppID used for Omaha protocol
22+
DefaultAppID = "0ccac0df-ca24-4f2b-bb7b-4a265bd0eb33"
23+
// DefaultGroupID used for Omaha protocol
24+
DefaultGroupID = "2e87b742-68c9-4d08-8f37-5cb7bb2c9d3a"
2525
)
2626

2727
// Flags for update package
2828
var Flags struct {
2929
Server string
30-
groupId string
31-
appId string
30+
groupID string
31+
appID string
3232
start int64
3333
end int64
3434
verbose bool
@@ -51,22 +51,22 @@ func parseInt(arg string) (i int, err error) {
5151

5252
func setUpdateFlags(args map[string]interface{}) error {
5353

54-
appId := utils.GetKey(constant.UpdatekeyDir, "app-id", "DEISCTL_APP_ID")
54+
appID := utils.GetKey(constant.UpdatekeyDir, "app-id", "DEISCTL_APP_ID")
5555
if args["--app-id"] != nil {
56-
Flags.appId = args["--app-id"].(string)
57-
} else if appId != "" {
58-
Flags.appId = appId
56+
Flags.appID = args["--app-id"].(string)
57+
} else if appID != "" {
58+
Flags.appID = appID
5959
} else {
60-
Flags.appId = DefaultAppId
60+
Flags.appID = DefaultAppID
6161
}
6262

63-
groupId := utils.GetKey(constant.UpdatekeyDir, "group-id", "DEISCTL_GROUP_ID")
63+
groupID := utils.GetKey(constant.UpdatekeyDir, "group-id", "DEISCTL_GROUP_ID")
6464
if args["--group-id"] != nil {
65-
Flags.groupId = args["--group-id"].(string)
66-
} else if groupId != "" {
67-
Flags.groupId = groupId
65+
Flags.groupID = args["--group-id"].(string)
66+
} else if groupID != "" {
67+
Flags.groupID = groupID
6868
} else {
69-
Flags.groupId = DefaultGroupId
69+
Flags.groupID = DefaultGroupID
7070
}
7171

7272
// read version from /etc/deis-version
@@ -150,11 +150,11 @@ func doUpdate() error {
150150
server: Flags.Server,
151151
}
152152
c := &Client{
153-
Id: utils.GetClientID(),
154-
SessionId: uuid.New(),
153+
ID: utils.GetClientID(),
154+
SessionID: uuid.New(),
155155
Version: Flags.version,
156-
AppId: Flags.appId,
157-
Track: Flags.groupId,
156+
AppID: Flags.appID,
157+
Track: Flags.groupID,
158158
config: conf,
159159
}
160160
go c.Loop(Flags.minSleep, Flags.maxSleep)

utils/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func PullImage(args string) error {
6565
return nil
6666
}
6767

68-
// getClientID returns the CoreOS Machine ID or an unknown UUID string
68+
// GetClientID returns the CoreOS Machine ID or an unknown UUID string
6969
func GetClientID() string {
7070
machineID := GetMachineID("/")
7171
if machineID == "" {
@@ -75,7 +75,7 @@ func GetClientID() string {
7575
}
7676

7777
func GetMachineID(root string) string {
78-
fullPath := filepath.Join(root, constant.MachineId)
78+
fullPath := filepath.Join(root, constant.MachineID)
7979
id, err := ioutil.ReadFile(fullPath)
8080
if err != nil {
8181
return ""

0 commit comments

Comments
 (0)