*: fix warnings from go vet

This commit is contained in:
Alex Crawford 2014-10-23 11:46:08 -07:00
parent 562c474275
commit 8be307de49
16 changed files with 74 additions and 56 deletions

View File

@ -38,7 +38,7 @@ func TestIsZero(t *testing.T) {
{struct{ A int }{A: 1}, false}, {struct{ A int }{A: 1}, false},
} { } {
if empty := IsZero(tt.c); tt.empty != empty { if empty := IsZero(tt.c); tt.empty != empty {
t.Errorf("bad result (%q): want %q, got %q", tt.c, tt.empty, empty) t.Errorf("bad result (%q): want %t, got %t", tt.c, tt.empty, empty)
} }
} }
} }
@ -373,7 +373,7 @@ users:
} }
if len(cfg.Users) != 1 { if len(cfg.Users) != 1 {
t.Fatalf("Parsed %d users, expected 1", cfg.Users) t.Fatalf("Parsed %d users, expected 1", len(cfg.Users))
} }
user := cfg.Users[0] user := cfg.Users[0]
@ -448,7 +448,7 @@ users:
} }
if len(cfg.Users) != 1 { if len(cfg.Users) != 1 {
t.Fatalf("Parsed %d users, expected 1", cfg.Users) t.Fatalf("Parsed %d users, expected 1", len(cfg.Users))
} }
user := cfg.Users[0] user := cfg.Users[0]
@ -474,7 +474,7 @@ users:
} }
if len(cfg.Users) != 1 { if len(cfg.Users) != 1 {
t.Fatalf("Parsed %d users, expected 1", cfg.Users) t.Fatalf("Parsed %d users, expected 1", len(cfg.Users))
} }
user := cfg.Users[0] user := cfg.Users[0]

View File

@ -57,7 +57,7 @@ func TestFetchMetadata(t *testing.T) {
cd := configDrive{tt.root, tt.files.readFile} cd := configDrive{tt.root, tt.files.readFile}
filename, err := cd.FetchMetadata() filename, err := cd.FetchMetadata()
if err != nil { if err != nil {
t.Fatalf("bad error for %q: want %q, got %q", tt, nil, err) t.Fatalf("bad error for %q: want %v, got %q", tt, nil, err)
} }
if string(filename) != tt.filename { if string(filename) != tt.filename {
t.Fatalf("bad path for %q: want %q, got %q", tt, tt.filename, filename) t.Fatalf("bad path for %q: want %q, got %q", tt, tt.filename, filename)
@ -90,7 +90,7 @@ func TestFetchUserdata(t *testing.T) {
cd := configDrive{tt.root, tt.files.readFile} cd := configDrive{tt.root, tt.files.readFile}
filename, err := cd.FetchUserdata() filename, err := cd.FetchUserdata()
if err != nil { if err != nil {
t.Fatalf("bad error for %q: want %q, got %q", tt, nil, err) t.Fatalf("bad error for %q: want %v, got %q", tt, nil, err)
} }
if string(filename) != tt.filename { if string(filename) != tt.filename {
t.Fatalf("bad path for %q: want %q, got %q", tt, tt.filename, filename) t.Fatalf("bad path for %q: want %q, got %q", tt, tt.filename, filename)

View File

@ -86,14 +86,14 @@ func TestFetchMetadata(t *testing.T) {
expect: []byte(`{"hostname":"","public-ipv4":"192.168.1.2","public-ipv6":"fe00::","public_keys":{"0":"publickey1","1":"publickey2"}}`), expect: []byte(`{"hostname":"","public-ipv4":"192.168.1.2","public-ipv6":"fe00::","public_keys":{"0":"publickey1","1":"publickey2"}}`),
}, },
{ {
clientErr: pkg.ErrTimeout{fmt.Errorf("test error")}, clientErr: pkg.ErrTimeout{Err: fmt.Errorf("test error")},
expectErr: pkg.ErrTimeout{fmt.Errorf("test error")}, expectErr: pkg.ErrTimeout{Err: fmt.Errorf("test error")},
}, },
} { } {
service := &metadataService{ service := &metadataService{
MetadataService: metadata.MetadataService{ MetadataService: metadata.MetadataService{
Root: tt.root, Root: tt.root,
Client: &test.HttpClient{tt.resources, tt.clientErr}, Client: &test.HttpClient{Resources: tt.resources, Err: tt.clientErr},
MetadataPath: tt.metadataPath, MetadataPath: tt.metadataPath,
}, },
} }

View File

@ -74,7 +74,7 @@ func TestFetchAttributes(t *testing.T) {
}, },
} { } {
service := metadataService{metadata.MetadataService{ service := metadataService{metadata.MetadataService{
Client: &test.HttpClient{s.resources, s.err}, Client: &test.HttpClient{Resources: s.resources, Err: s.err},
}} }}
for _, tt := range s.tests { for _, tt := range s.tests {
attrs, err := service.fetchAttributes(tt.path) attrs, err := service.fetchAttributes(tt.path)
@ -128,7 +128,7 @@ func TestFetchAttribute(t *testing.T) {
}, },
} { } {
service := metadataService{metadata.MetadataService{ service := metadataService{metadata.MetadataService{
Client: &test.HttpClient{s.resources, s.err}, Client: &test.HttpClient{Resources: s.resources, Err: s.err},
}} }}
for _, tt := range s.tests { for _, tt := range s.tests {
attr, err := service.fetchAttribute(tt.path) attr, err := service.fetchAttribute(tt.path)
@ -174,13 +174,13 @@ func TestFetchMetadata(t *testing.T) {
expect: []byte(`{"hostname":"host","local-ipv4":"1.2.3.4","network_config":{"content_path":"path"},"public-ipv4":"5.6.7.8","public_keys":{"test1":"key"}}`), expect: []byte(`{"hostname":"host","local-ipv4":"1.2.3.4","network_config":{"content_path":"path"},"public-ipv4":"5.6.7.8","public_keys":{"test1":"key"}}`),
}, },
{ {
clientErr: pkg.ErrTimeout{fmt.Errorf("test error")}, clientErr: pkg.ErrTimeout{Err: fmt.Errorf("test error")},
expectErr: pkg.ErrTimeout{fmt.Errorf("test error")}, expectErr: pkg.ErrTimeout{Err: fmt.Errorf("test error")},
}, },
} { } {
service := &metadataService{metadata.MetadataService{ service := &metadataService{metadata.MetadataService{
Root: tt.root, Root: tt.root,
Client: &test.HttpClient{tt.resources, tt.clientErr}, Client: &test.HttpClient{Resources: tt.resources, Err: tt.clientErr},
MetadataPath: tt.metadataPath, MetadataPath: tt.metadataPath,
}} }}
metadata, err := service.FetchMetadata() metadata, err := service.FetchMetadata()

View File

@ -28,7 +28,7 @@ import (
func TestAvailabilityChanges(t *testing.T) { func TestAvailabilityChanges(t *testing.T) {
want := true want := true
if ac := (MetadataService{}).AvailabilityChanges(); ac != want { if ac := (MetadataService{}).AvailabilityChanges(); ac != want {
t.Fatalf("bad AvailabilityChanges: want %q, got %q", want, ac) t.Fatalf("bad AvailabilityChanges: want %t, got %t", want, ac)
} }
} }
@ -55,11 +55,11 @@ func TestIsAvailable(t *testing.T) {
} { } {
service := &MetadataService{ service := &MetadataService{
Root: tt.root, Root: tt.root,
Client: &test.HttpClient{tt.resources, nil}, Client: &test.HttpClient{Resources: tt.resources, Err: nil},
ApiVersion: tt.apiVersion, ApiVersion: tt.apiVersion,
} }
if a := service.IsAvailable(); a != tt.expect { if a := service.IsAvailable(); a != tt.expect {
t.Fatalf("bad isAvailable (%q): want %q, got %q", tt.resources, tt.expect, a) t.Fatalf("bad isAvailable (%q): want %t, got %t", tt.resources, tt.expect, a)
} }
} }
} }
@ -83,18 +83,18 @@ func TestFetchUserdata(t *testing.T) {
}, },
{ {
root: "/", root: "/",
clientErr: pkg.ErrNotFound{fmt.Errorf("test not found error")}, clientErr: pkg.ErrNotFound{Err: fmt.Errorf("test not found error")},
userdata: []byte{}, userdata: []byte{},
}, },
{ {
root: "/", root: "/",
clientErr: pkg.ErrTimeout{fmt.Errorf("test timeout error")}, clientErr: pkg.ErrTimeout{Err: fmt.Errorf("test timeout error")},
expectErr: pkg.ErrTimeout{fmt.Errorf("test timeout error")}, expectErr: pkg.ErrTimeout{Err: fmt.Errorf("test timeout error")},
}, },
} { } {
service := &MetadataService{ service := &MetadataService{
Root: tt.root, Root: tt.root,
Client: &test.HttpClient{tt.resources, tt.clientErr}, Client: &test.HttpClient{Resources: tt.resources, Err: tt.clientErr},
UserdataPath: tt.userdataPath, UserdataPath: tt.userdataPath,
} }
data, err := service.FetchUserdata() data, err := service.FetchUserdata()

View File

@ -101,7 +101,7 @@ func TestFetchMetadata(t *testing.T) {
a := waagent{tt.root, tt.files.readFile} a := waagent{tt.root, tt.files.readFile}
metadataBytes, err := a.FetchMetadata() metadataBytes, err := a.FetchMetadata()
if err != nil { if err != nil {
t.Fatalf("bad error for %q: want %q, got %q", tt, nil, err) t.Fatalf("bad error for %q: want %v, got %q", tt, nil, err)
} }
var metadata map[string]string var metadata map[string]string
if len(metadataBytes) > 0 { if len(metadataBytes) > 0 {
@ -136,7 +136,7 @@ func TestFetchUserdata(t *testing.T) {
a := waagent{tt.root, tt.files.readFile} a := waagent{tt.root, tt.files.readFile}
_, err := a.FetchUserdata() _, err := a.FetchUserdata()
if err != nil { if err != nil {
t.Fatalf("bad error for %q: want %q, got %q", tt, nil, err) t.Fatalf("bad error for %q: want %v, got %q", tt, nil, err)
} }
} }
} }

View File

@ -106,13 +106,13 @@ func Apply(cfg config.CloudConfig, env *Environment) error {
var writeFiles []system.File var writeFiles []system.File
for _, file := range cfg.WriteFiles { for _, file := range cfg.WriteFiles {
writeFiles = append(writeFiles, system.File{file}) writeFiles = append(writeFiles, system.File{File: file})
} }
for _, ccf := range []CloudConfigFile{ for _, ccf := range []CloudConfigFile{
system.OEM{cfg.Coreos.OEM}, system.OEM{OEM: cfg.Coreos.OEM},
system.Update{cfg.Coreos.Update, system.DefaultReadConfig}, system.Update{Update: cfg.Coreos.Update, ReadConfig: system.DefaultReadConfig},
system.EtcHosts{cfg.ManageEtcHosts}, system.EtcHosts{EtcHosts: cfg.ManageEtcHosts},
} { } {
f, err := ccf.File() f, err := ccf.File()
if err != nil { if err != nil {
@ -125,13 +125,13 @@ func Apply(cfg config.CloudConfig, env *Environment) error {
var units []system.Unit var units []system.Unit
for _, u := range cfg.Coreos.Units { for _, u := range cfg.Coreos.Units {
units = append(units, system.Unit{u}) units = append(units, system.Unit{Unit: u})
} }
for _, ccu := range []CloudConfigUnit{ for _, ccu := range []CloudConfigUnit{
system.Etcd{cfg.Coreos.Etcd}, system.Etcd{Etcd: cfg.Coreos.Etcd},
system.Fleet{cfg.Coreos.Fleet}, system.Fleet{Fleet: cfg.Coreos.Fleet},
system.Update{cfg.Coreos.Update, system.DefaultReadConfig}, system.Update{Update: cfg.Coreos.Update, ReadConfig: system.DefaultReadConfig},
} { } {
units = append(units, ccu.Units()...) units = append(units, ccu.Units()...)
} }

View File

@ -61,7 +61,7 @@ func (tum *TestUnitManager) UnmaskUnit(unit *system.Unit) error {
func TestProcessUnits(t *testing.T) { func TestProcessUnits(t *testing.T) {
tum := &TestUnitManager{} tum := &TestUnitManager{}
units := []system.Unit{ units := []system.Unit{
system.Unit{config.Unit{ system.Unit{Unit: config.Unit{
Name: "foo", Name: "foo",
Mask: true, Mask: true,
}}, }},
@ -75,7 +75,7 @@ func TestProcessUnits(t *testing.T) {
tum = &TestUnitManager{} tum = &TestUnitManager{}
units = []system.Unit{ units = []system.Unit{
system.Unit{config.Unit{ system.Unit{Unit: config.Unit{
Name: "bar.network", Name: "bar.network",
}}, }},
} }
@ -88,7 +88,7 @@ func TestProcessUnits(t *testing.T) {
tum = &TestUnitManager{} tum = &TestUnitManager{}
units = []system.Unit{ units = []system.Unit{
system.Unit{config.Unit{ system.Unit{Unit: config.Unit{
Name: "baz.service", Name: "baz.service",
Content: "[Service]\nExecStart=/bin/true", Content: "[Service]\nExecStart=/bin/true",
}}, }},
@ -102,7 +102,7 @@ func TestProcessUnits(t *testing.T) {
tum = &TestUnitManager{} tum = &TestUnitManager{}
units = []system.Unit{ units = []system.Unit{
system.Unit{config.Unit{ system.Unit{Unit: config.Unit{
Name: "locksmithd.service", Name: "locksmithd.service",
Runtime: true, Runtime: true,
}}, }},
@ -116,7 +116,7 @@ func TestProcessUnits(t *testing.T) {
tum = &TestUnitManager{} tum = &TestUnitManager{}
units = []system.Unit{ units = []system.Unit{
system.Unit{config.Unit{ system.Unit{Unit: config.Unit{
Name: "woof", Name: "woof",
Enable: true, Enable: true,
}}, }},

View File

@ -98,7 +98,7 @@ func (e *Environment) Apply(data string) string {
func (e *Environment) DefaultEnvironmentFile() *system.EnvFile { func (e *Environment) DefaultEnvironmentFile() *system.EnvFile {
ef := system.EnvFile{ ef := system.EnvFile{
File: &system.File{config.File{ File: &system.File{File: config.File{
Path: "/etc/environment", Path: "/etc/environment",
}}, }},
Vars: map[string]string{}, Vars: map[string]string{},

View File

@ -48,7 +48,7 @@ func PersistScriptInWorkspace(script system.Script, workspace string) (string, e
relpath := strings.TrimPrefix(tmp.Name(), workspace) relpath := strings.TrimPrefix(tmp.Name(), workspace)
file := system.File{config.File{ file := system.File{File: config.File{
Path: relpath, Path: relpath,
RawFilePermissions: "0744", RawFilePermissions: "0744",
Content: string(script), Content: string(script),
@ -58,7 +58,7 @@ func PersistScriptInWorkspace(script system.Script, workspace string) (string, e
} }
func PersistUnitNameInWorkspace(name string, workspace string) error { func PersistUnitNameInWorkspace(name string, workspace string) error {
file := system.File{config.File{ file := system.File{File: config.File{
Path: path.Join("scripts", "unit-name"), Path: path.Join("scripts", "unit-name"),
RawFilePermissions: "0644", RawFilePermissions: "0644",
Content: name, Content: name,

View File

@ -49,7 +49,7 @@ func TestProcessDebianNetconf(t *testing.T) {
interfaces, err := ProcessDebianNetconf(tt.in) interfaces, err := ProcessDebianNetconf(tt.in)
failed := err != nil failed := err != nil
if tt.fail != failed { if tt.fail != failed {
t.Fatalf("bad failure state for %q: got %b, want %b", failed, tt.fail) t.Fatalf("bad failure state for %q: got %t, want %t", tt.in, failed, tt.fail)
} }
if tt.n != -1 && tt.n != len(interfaces) { if tt.n != -1 && tt.n != len(interfaces) {
t.Fatalf("bad number of interfaces for %q: got %d, want %q", tt.in, len(interfaces), tt.n) t.Fatalf("bad number of interfaces for %q: got %d, want %q", tt.in, len(interfaces), tt.n)

View File

@ -36,11 +36,11 @@ func TestParseNameservers(t *testing.T) {
nss: []net.IP{}, nss: []net.IP{},
}, },
{ {
dns: digitalocean.DNS{[]string{"1.2.3.4"}}, dns: digitalocean.DNS{Nameservers: []string{"1.2.3.4"}},
nss: []net.IP{net.ParseIP("1.2.3.4")}, nss: []net.IP{net.ParseIP("1.2.3.4")},
}, },
{ {
dns: digitalocean.DNS{[]string{"bad"}}, dns: digitalocean.DNS{Nameservers: []string{"bad"}},
err: errors.New("could not parse \"bad\" as nameserver IP address"), err: errors.New("could not parse \"bad\" as nameserver IP address"),
}, },
} { } {
@ -132,7 +132,10 @@ func TestParseInterface(t *testing.T) {
iface: &logicalInterface{ iface: &logicalInterface{
hwaddr: net.HardwareAddr([]byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab}), hwaddr: net.HardwareAddr([]byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab}),
config: configMethodStatic{ config: configMethodStatic{
addresses: []net.IPNet{net.IPNet{net.ParseIP("1.2.3.4"), net.IPMask(net.ParseIP("255.255.0.0"))}}, addresses: []net.IPNet{net.IPNet{
IP: net.ParseIP("1.2.3.4"),
Mask: net.IPMask(net.ParseIP("255.255.0.0")),
}},
nameservers: []net.IP{}, nameservers: []net.IP{},
routes: []route{}, routes: []route{},
}, },
@ -165,9 +168,15 @@ func TestParseInterface(t *testing.T) {
iface: &logicalInterface{ iface: &logicalInterface{
hwaddr: net.HardwareAddr([]byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab}), hwaddr: net.HardwareAddr([]byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab}),
config: configMethodStatic{ config: configMethodStatic{
addresses: []net.IPNet{net.IPNet{net.ParseIP("1.2.3.4"), net.IPMask(net.ParseIP("255.255.0.0"))}}, addresses: []net.IPNet{net.IPNet{
IP: net.ParseIP("1.2.3.4"),
Mask: net.IPMask(net.ParseIP("255.255.0.0")),
}},
nameservers: []net.IP{}, nameservers: []net.IP{},
routes: []route{route{net.IPNet{net.IPv4zero, net.IPMask(net.IPv4zero)}, net.ParseIP("5.6.7.8")}}, routes: []route{route{
net.IPNet{IP: net.IPv4zero, Mask: net.IPMask(net.IPv4zero)},
net.ParseIP("5.6.7.8"),
}},
}, },
}, },
}, },
@ -195,7 +204,10 @@ func TestParseInterface(t *testing.T) {
iface: &logicalInterface{ iface: &logicalInterface{
hwaddr: net.HardwareAddr([]byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab}), hwaddr: net.HardwareAddr([]byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab}),
config: configMethodStatic{ config: configMethodStatic{
addresses: []net.IPNet{net.IPNet{net.ParseIP("fe00::"), net.IPMask(net.ParseIP("ffff::"))}}, addresses: []net.IPNet{net.IPNet{
IP: net.ParseIP("fe00::"),
Mask: net.IPMask(net.ParseIP("ffff::")),
}},
nameservers: []net.IP{}, nameservers: []net.IP{},
routes: []route{}, routes: []route{},
}, },
@ -228,9 +240,15 @@ func TestParseInterface(t *testing.T) {
iface: &logicalInterface{ iface: &logicalInterface{
hwaddr: net.HardwareAddr([]byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab}), hwaddr: net.HardwareAddr([]byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab}),
config: configMethodStatic{ config: configMethodStatic{
addresses: []net.IPNet{net.IPNet{net.ParseIP("fe00::"), net.IPMask(net.ParseIP("ffff::"))}}, addresses: []net.IPNet{net.IPNet{
IP: net.ParseIP("fe00::"),
Mask: net.IPMask(net.ParseIP("ffff::")),
}},
nameservers: []net.IP{}, nameservers: []net.IP{},
routes: []route{route{net.IPNet{net.IPv6zero, net.IPMask(net.IPv6zero)}, net.ParseIP("fe00:1234::")}}, routes: []route{route{
net.IPNet{IP: net.IPv6zero, Mask: net.IPMask(net.IPv6zero)},
net.ParseIP("fe00:1234::"),
}},
}, },
}, },
}, },

View File

@ -98,7 +98,7 @@ func TestGetURL4xx(t *testing.T) {
} }
if retries > 1 { if retries > 1 {
t.Errorf("Number of retries:\n%d\nExpected number of retries:\n%s", retries, 1) t.Errorf("Number of retries:\n%d\nExpected number of retries:\n%d", retries, 1)
} }
} }

View File

@ -48,7 +48,7 @@ Environment="FLEET_PUBLIC_IP=12.34.56.78"
} { } {
units := Fleet{tt.config}.Units() units := Fleet{tt.config}.Units()
if !reflect.DeepEqual(units, tt.units) { if !reflect.DeepEqual(units, tt.units) {
t.Errorf("bad units (%q): want %q, got %q", tt.config, tt.units, units) t.Errorf("bad units (%q): want %#v, got %#v", tt.config, tt.units, units)
} }
} }
} }

View File

@ -54,7 +54,7 @@ BUG_REPORT_URL="https://github.com/coreos/coreos-overlay"
} { } {
file, err := OEM{tt.config}.File() file, err := OEM{tt.config}.File()
if err != nil { if err != nil {
t.Errorf("bad error (%q): want %q, got %q", tt.config, nil, err) t.Errorf("bad error (%q): want %v, got %q", tt.config, nil, err)
} }
if !reflect.DeepEqual(tt.file, file) { if !reflect.DeepEqual(tt.file, file) {
t.Errorf("bad file (%q): want %#v, got %#v", tt.config, tt.file, file) t.Errorf("bad file (%q): want %#v, got %#v", tt.config, tt.file, file)

View File

@ -187,10 +187,10 @@ func TestMaskUnit(t *testing.T) {
fooPath := path.Join(dir, "etc", "systemd", "system", "foo.service") fooPath := path.Join(dir, "etc", "systemd", "system", "foo.service")
fooTgt, err := os.Readlink(fooPath) fooTgt, err := os.Readlink(fooPath)
if err != nil { if err != nil {
t.Fatalf("Unable to read link", err) t.Fatal("Unable to read link", err)
} }
if fooTgt != "/dev/null" { if fooTgt != "/dev/null" {
t.Fatalf("unit not masked, got unit target", fooTgt) t.Fatal("unit not masked, got unit target", fooTgt)
} }
// Ensure mask works with unit files that already exist // Ensure mask works with unit files that already exist
@ -204,10 +204,10 @@ func TestMaskUnit(t *testing.T) {
} }
barTgt, err := os.Readlink(barPath) barTgt, err := os.Readlink(barPath)
if err != nil { if err != nil {
t.Fatalf("Unable to read link", err) t.Fatal("Unable to read link", err)
} }
if barTgt != "/dev/null" { if barTgt != "/dev/null" {
t.Fatalf("unit not masked, got unit target", barTgt) t.Fatal("unit not masked, got unit target", barTgt)
} }
} }
@ -254,7 +254,7 @@ func TestUnmaskUnit(t *testing.T) {
t.Errorf("unmask of unit returned unexpected error: %v", err) t.Errorf("unmask of unit returned unexpected error: %v", err)
} }
if _, err := os.Stat(dst); !os.IsNotExist(err) { if _, err := os.Stat(dst); !os.IsNotExist(err) {
t.Errorf("expected %s to not exist after unmask, but got err: %s", err) t.Errorf("expected %s to not exist after unmask, but got err: %s", dst, err)
} }
} }