Skip to content

Commit

Permalink
Gofmt static analysis linter
Browse files Browse the repository at this point in the history
The following changes introduce the gofmt linter. Most of the code
changes are the consequence of getting the linter to pass. Using the
`make simplify` command does this automatically for you.
  • Loading branch information
SimonRichardson committed Jun 7, 2018
1 parent 0879177 commit 3342827
Show file tree
Hide file tree
Showing 181 changed files with 1,078 additions and 1,079 deletions.
4 changes: 2 additions & 2 deletions api/application/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (s *applicationSuite) TestDeploy(c *gc.C) {
c.Assert(app.Constraints, gc.DeepEquals, constraints.MustParse("mem=4G"))
c.Assert(app.Placement, gc.DeepEquals, []*instance.Placement{{"scope", "directive"}})
c.Assert(app.EndpointBindings, gc.DeepEquals, map[string]string{"foo": "bar"})
c.Assert(app.Storage, gc.DeepEquals, map[string]storage.Constraints{"data": storage.Constraints{Pool: "pool"}})
c.Assert(app.Storage, gc.DeepEquals, map[string]storage.Constraints{"data": {Pool: "pool"}})
c.Assert(app.AttachStorage, gc.DeepEquals, []string{"storage-data-0"})
c.Assert(app.Resources, gc.DeepEquals, map[string]string{"foo": "bar"})

Expand All @@ -119,7 +119,7 @@ func (s *applicationSuite) TestDeploy(c *gc.C) {
Config: map[string]string{"foo": "bar"},
Cons: constraints.MustParse("mem=4G"),
Placement: []*instance.Placement{{"scope", "directive"}},
Storage: map[string]storage.Constraints{"data": storage.Constraints{Pool: "pool"}},
Storage: map[string]storage.Constraints{"data": {Pool: "pool"}},
AttachStorage: []string{"data/0"},
Resources: map[string]string{"foo": "bar"},
EndpointBindings: map[string]string{"foo": "bar"},
Expand Down
8 changes: 4 additions & 4 deletions api/common/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ func (s *NetworkSuite) TestGetObservedNetworkConfigLoopbackInfrerred(c *gc.C) {
func (s *NetworkSuite) TestGetObservedNetworkConfigVLANInfrerred(c *gc.C) {
s.stubConfigSource.interfaces = exampleObservedInterfaces[6:7] // only eth0.100
s.stubConfigSource.interfaceAddrs = map[string][]net.Addr{
"eth0.100": []net.Addr{
"eth0.100": {
fakeAddr("fe80::5054:ff:fedd:eef0:100/64"),
fakeAddr("10.100.19.123/24"),
},
Expand Down Expand Up @@ -1108,7 +1108,7 @@ func (s *NetworkSuite) TestGetObservedNetworkConfigAddressNotInCIDRFormat(c *gc.
// Simulate running on Windows, where net.InterfaceAddrs() returns
// non-CIDR-formatted addresses.
s.stubConfigSource.interfaceAddrs = map[string][]net.Addr{
"eth0": []net.Addr{fakeAddr("10.20.19.42")},
"eth0": {fakeAddr("10.20.19.42")},
}

observedConfig, err := common.GetObservedNetworkConfig(s.stubConfigSource)
Expand All @@ -1131,7 +1131,7 @@ func (s *NetworkSuite) TestGetObservedNetworkConfigEmptyAddressValue(c *gc.C) {
s.stubConfigSource.interfaces = exampleObservedInterfaces[1:2] // only eth0
s.stubConfigSource.makeSysClassNetInterfacePath(c, "eth0", "")
s.stubConfigSource.interfaceAddrs = map[string][]net.Addr{
"eth0": []net.Addr{fakeAddr("")},
"eth0": {fakeAddr("")},
}

observedConfig, err := common.GetObservedNetworkConfig(s.stubConfigSource)
Expand All @@ -1153,7 +1153,7 @@ func (s *NetworkSuite) TestGetObservedNetworkConfigInvalidAddressValue(c *gc.C)
s.stubConfigSource.interfaces = exampleObservedInterfaces[1:2] // only eth0
s.stubConfigSource.makeSysClassNetInterfacePath(c, "eth0", "")
s.stubConfigSource.interfaceAddrs = map[string][]net.Addr{
"eth0": []net.Addr{fakeAddr("invalid")},
"eth0": {fakeAddr("invalid")},
}

observedConfig, err := common.GetObservedNetworkConfig(s.stubConfigSource)
Expand Down
4 changes: 2 additions & 2 deletions api/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (s *Suite) TestModelStatus(c *gc.C) {

out := result.(*params.ModelStatusResults)
out.Results = []params.ModelStatus{
params.ModelStatus{
{
ModelTag: coretesting.ModelTag.String(),
OwnerTag: "user-glenda",
ApplicationCount: 3,
Expand All @@ -319,7 +319,7 @@ func (s *Suite) TestModelStatus(c *gc.C) {
Status: "pending",
}},
},
params.ModelStatus{Error: common.ServerError(errors.New("model error"))},
{Error: common.ServerError(errors.New("model error"))},
}
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion api/firewaller/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (s *machineSuite) TestOpenedPorts(c *gc.C) {
ports, err = s.apiMachine.OpenedPorts(names.SubnetTag{})
c.Assert(err, jc.ErrorIsNil)
c.Assert(ports, jc.DeepEquals, map[network.PortRange]names.UnitTag{
network.PortRange{FromPort: 1234, ToPort: 1234, Protocol: "tcp"}: unitTag,
{FromPort: 1234, ToPort: 1234, Protocol: "tcp"}: unitTag,
})
}

Expand Down
4 changes: 2 additions & 2 deletions api/imagemetadatamanager/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s *imagemetadataSuite) TestList(c *gc.C) {

if results, k := result.(*params.ListCloudImageMetadataResult); k {
instances := []params.CloudImageMetadata{
params.CloudImageMetadata{
{
ImageId: imageId,
Stream: args.Stream,
Region: args.Region,
Expand Down Expand Up @@ -85,7 +85,7 @@ func (s *imagemetadataSuite) TestList(c *gc.C) {

c.Assert(called, jc.IsTrue)
expected := []params.CloudImageMetadata{
params.CloudImageMetadata{
{
ImageId: imageId,
Stream: stream,
Region: region,
Expand Down
4 changes: 2 additions & 2 deletions api/migrationmaster/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (s *ClientSuite) TestExport(c *gc.C) {
Username: "xena",
},
UnitRevisions: map[string]params.SerializedModelResourceRevision{
"fooapp/0": params.SerializedModelResourceRevision{
"fooapp/0": {
Revision: 1,
Type: "file",
Path: "blink.tar.gz",
Expand Down Expand Up @@ -323,7 +323,7 @@ func (s *ClientSuite) TestExport(c *gc.C) {
Username: "xena",
},
UnitRevisions: map[string]resource.Resource{
"fooapp/0": resource.Resource{
"fooapp/0": {
Resource: charmresource.Resource{
Meta: charmresource.Meta{
Name: "bin",
Expand Down
4 changes: 2 additions & 2 deletions api/modelmanager/modelmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func (s *modelmanagerSuite) TestModelStatus(c *gc.C) {

out := result.(*params.ModelStatusResults)
out.Results = []params.ModelStatus{
params.ModelStatus{
{
ModelTag: coretesting.ModelTag.String(),
OwnerTag: "user-glenda",
ApplicationCount: 3,
Expand All @@ -364,7 +364,7 @@ func (s *modelmanagerSuite) TestModelStatus(c *gc.C) {
Status: "pending",
}},
},
params.ModelStatus{Error: common.ServerError(errors.New("model error"))},
{Error: common.ServerError(errors.New("model error"))},
}
return nil
},
Expand Down
16 changes: 8 additions & 8 deletions api/provisioner/provisioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ func (s *provisionerSuite) TestDistributionGroupByMachineId(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)
c.Assert(len(results), gc.Equals, 1)
c.Assert(results, gc.DeepEquals, []provisioner.DistributionGroupResult{
provisioner.DistributionGroupResult{MachineIds: nil, Err: nil},
{MachineIds: nil, Err: nil},
})

machine1, err := s.State.AddMachine("quantal", state.JobHostUnits)
Expand All @@ -455,8 +455,8 @@ func (s *provisionerSuite) TestDistributionGroupByMachineId(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)
c.Assert(len(results), gc.Equals, 2)
c.Assert(results, gc.DeepEquals, []provisioner.DistributionGroupResult{
provisioner.DistributionGroupResult{MachineIds: nil, Err: nil},
provisioner.DistributionGroupResult{MachineIds: nil, Err: nil},
{MachineIds: nil, Err: nil},
{MachineIds: nil, Err: nil},
})

machine2, err := s.State.AddMachine("quantal", state.JobHostUnits)
Expand All @@ -474,9 +474,9 @@ func (s *provisionerSuite) TestDistributionGroupByMachineId(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)
c.Assert(len(results), gc.Equals, 3)
c.Assert(results, gc.DeepEquals, []provisioner.DistributionGroupResult{
provisioner.DistributionGroupResult{MachineIds: nil, Err: nil},
provisioner.DistributionGroupResult{MachineIds: []string{"2"}, Err: nil},
provisioner.DistributionGroupResult{MachineIds: []string{"1"}, Err: nil},
{MachineIds: nil, Err: nil},
{MachineIds: []string{"2"}, Err: nil},
{MachineIds: []string{"1"}, Err: nil},
})
}

Expand Down Expand Up @@ -527,8 +527,8 @@ func (s *provisionerSuite) TestProvisioningInfo(c *gc.C) {
c.Assert(provisioningInfo.Placement, gc.Equals, template.Placement)
c.Assert(provisioningInfo.Constraints, jc.DeepEquals, template.Constraints)
c.Assert(provisioningInfo.SubnetsToZones, jc.DeepEquals, map[string][]string{
"subnet-2": []string{"zone2"},
"subnet-3": []string{"zone3"},
"subnet-2": {"zone2"},
"subnet-3": {"zone3"},
})
}

Expand Down
2 changes: 1 addition & 1 deletion api/proxyupdater/proxyupdater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (s *ProxyUpdaterSuite) TestNilTagFails(c *gc.C) {

func (s *ProxyUpdaterSuite) TestWatchForProxyConfigAndAPIHostPortChanges(c *gc.C) {
res := params.NotifyWatchResults{
Results: []params.NotifyWatchResult{params.NotifyWatchResult{
Results: []params.NotifyWatchResult{{
NotifyWatcherId: "4242",
}},
}
Expand Down
2 changes: 1 addition & 1 deletion api/spaces/spaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func makeArgs(name string, subnets []string) (string, []string, apitesting.APICa

expectArgs := params.CreateSpacesParams{
Spaces: []params.CreateSpaceParams{
params.CreateSpaceParams{
{
SpaceTag: spaceTag,
SubnetTags: subnetTags,
Public: true,
Expand Down
22 changes: 11 additions & 11 deletions api/storage/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ func (s *storageMockSuite) TestStorageDetails(c *gc.C) {

if results, k := result.(*params.StorageDetailsResults); k {
instances := []params.StorageDetailsResult{
params.StorageDetailsResult{
{
Result: &params.StorageDetails{StorageTag: oneTag.String()},
},
params.StorageDetailsResult{
{
Result: &params.StorageDetails{
StorageTag: twoTag.String(),
Status: params.EntityStatus{
Expand All @@ -62,7 +62,7 @@ func (s *storageMockSuite) TestStorageDetails(c *gc.C) {
Persistent: true,
},
},
params.StorageDetailsResult{
{
Error: common.ServerError(errors.New(msg)),
},
}
Expand Down Expand Up @@ -172,9 +172,9 @@ func (s *storageMockSuite) TestListStorageDetailsFacadeCallError(c *gc.C) {

func (s *storageMockSuite) TestListPools(c *gc.C) {
expected := []params.StoragePool{
params.StoragePool{Name: "name0", Provider: "type0"},
params.StoragePool{Name: "name1", Provider: "type1"},
params.StoragePool{Name: "name2", Provider: "type2"},
{Name: "name0", Provider: "type0"},
{Name: "name1", Provider: "type1"},
{Name: "name2", Provider: "type2"},
}
want := len(expected)

Expand Down Expand Up @@ -408,7 +408,7 @@ func (s *storageMockSuite) TestListFilesystems(c *gc.C) {
Status: "attached",
},
MachineAttachments: map[string]params.FilesystemAttachmentDetails{
"0": params.FilesystemAttachmentDetails{
"0": {
FilesystemAttachmentInfo: params.FilesystemAttachmentInfo{
MountPoint: "/mnt/kinabalu",
ReadOnly: false,
Expand Down Expand Up @@ -510,9 +510,9 @@ func (s *storageMockSuite) TestAddToUnit(c *gc.C) {

errOut := "error"
unitStorages := []params.StorageAddParams{
params.StorageAddParams{UnitTag: "u-a", StorageName: "one", Constraints: cons},
params.StorageAddParams{UnitTag: "u-b", StorageName: errOut, Constraints: cons},
params.StorageAddParams{UnitTag: "u-b", StorageName: "nil-constraints"},
{UnitTag: "u-a", StorageName: "one", Constraints: cons},
{UnitTag: "u-b", StorageName: errOut, Constraints: cons},
{UnitTag: "u-b", StorageName: "nil-constraints"},
}

storageN := 3
Expand Down Expand Up @@ -567,7 +567,7 @@ func (s *storageMockSuite) TestAddToUnit(c *gc.C) {

func (s *storageMockSuite) TestAddToUnitFacadeCallError(c *gc.C) {
unitStorages := []params.StorageAddParams{
params.StorageAddParams{UnitTag: "u-a", StorageName: "one"},
{UnitTag: "u-a", StorageName: "one"},
}

msg := "facade failure"
Expand Down
4 changes: 2 additions & 2 deletions api/uniter/goal-state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (s *goalStateSuite) TestGoalStateTwoRelatedUnits(c *gc.C) {
"mysql/0": paramsBaseGoalStateStatus,
},
Relations: map[string]params.UnitsGoalState{
"db": params.UnitsGoalState{
"db": {
"wordpress/0": paramsBaseGoalStateStatus,
},
},
Expand All @@ -77,7 +77,7 @@ func (s *goalStateSuite) TestGoalStateTwoRelatedUnits(c *gc.C) {
"mysql/0": apiBaseGoalStateStatus,
},
Relations: map[string]application.UnitsGoalState{
"db": application.UnitsGoalState{
"db": {
"wordpress/0": apiBaseGoalStateStatus,
},
},
Expand Down
8 changes: 4 additions & 4 deletions api/uniter/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ func (s *stateSuite) TestAllMachinePorts(c *gc.C) {
portsMap, err := s.uniter.AllMachinePorts(s.wordpressMachine.Tag().(names.MachineTag))
c.Assert(err, jc.ErrorIsNil)
c.Assert(portsMap, jc.DeepEquals, map[network.PortRange]params.RelationUnit{
network.PortRange{100, 200, "tcp"}: {Unit: s.wordpressUnit.Tag().String()},
network.PortRange{10, 20, "udp"}: {Unit: s.wordpressUnit.Tag().String()},
network.PortRange{201, 250, "tcp"}: {Unit: wordpressUnit1.Tag().String()},
network.PortRange{1, 8, "udp"}: {Unit: wordpressUnit1.Tag().String()},
{100, 200, "tcp"}: {Unit: s.wordpressUnit.Tag().String()},
{10, 20, "udp"}: {Unit: s.wordpressUnit.Tag().String()},
{201, 250, "tcp"}: {Unit: wordpressUnit1.Tag().String()},
{1, 8, "udp"}: {Unit: wordpressUnit1.Tag().String()},
})
}
6 changes: 3 additions & 3 deletions api/uniter/unitstorage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func (s *unitStorageSuite) createTestUnit(c *gc.C, t string, apiCaller basetesti
func (s *unitStorageSuite) TestAddUnitStorage(c *gc.C) {
count := uint64(1)
args := map[string][]params.StorageConstraints{
"data": []params.StorageConstraints{
params.StorageConstraints{Count: &count}},
"data": {
{Count: &count}},
}

expected := params.StoragesAddParams{
Expand Down Expand Up @@ -64,7 +64,7 @@ func (s *unitStorageSuite) TestAddUnitStorage(c *gc.C) {
func (s *unitStorageSuite) TestAddUnitStorageError(c *gc.C) {
count := uint64(1)
args := map[string][]params.StorageConstraints{
"data": []params.StorageConstraints{params.StorageConstraints{Count: &count}},
"data": {{Count: &count}},
}

expected := params.StoragesAddParams{
Expand Down
12 changes: 6 additions & 6 deletions apiserver/common/modelstatus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (s *modelStatusSuite) TestModelStatus(c *gc.C) {
Mem: &mem,
}
c.Assert(results.Results, jc.DeepEquals, []params.ModelStatus{
params.ModelStatus{
{
ModelTag: controllerModelTag,
HostedMachineCount: 1,
ApplicationCount: 1,
Expand All @@ -204,7 +204,7 @@ func (s *modelStatusSuite) TestModelStatus(c *gc.C) {
Id: "1/1", Status: "pending", Detachable: false,
}},
},
params.ModelStatus{
{
ModelTag: hostedModelTag,
HostedMachineCount: 2,
ApplicationCount: 1,
Expand Down Expand Up @@ -248,14 +248,14 @@ func (s *modelStatusSuite) TestModelStatusCAAS(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)

c.Assert(results.Results, jc.DeepEquals, []params.ModelStatus{
params.ModelStatus{
{
ModelTag: controllerModelTag,
HostedMachineCount: 0,
ApplicationCount: 0,
OwnerTag: s.Owner.String(),
Life: params.Alive,
},
params.ModelStatus{
{
ModelTag: hostedModelTag,
HostedMachineCount: 0,
ApplicationCount: 1,
Expand All @@ -274,9 +274,9 @@ func (s *modelStatusSuite) TestModelStatusRunsForAllModels(c *gc.C) {
}
expected := params.ModelStatusResults{
Results: []params.ModelStatus{
params.ModelStatus{
{
Error: common.ServerError(errors.New(`"fail.me" is not a valid tag`))},
params.ModelStatus{
{
ModelTag: s.IAASModel.ModelTag().String(),
Life: params.Life(s.IAASModel.Life().String()),
OwnerTag: s.IAASModel.Owner().String(),
Expand Down
2 changes: 1 addition & 1 deletion apiserver/common/networkingcommon/subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (cache *addSubnetsCache) cacheSubnets(ctx context.ProviderCallContext) erro
cache.providerIdsByCIDR = make(map[string]set.Strings)
cache.subnetsByProviderId = make(map[string]*network.SubnetInfo)

for i, _ := range subnetInfo {
for i := range subnetInfo {
subnet := subnetInfo[i]
cidr := subnet.CIDR
providerId := string(subnet.ProviderId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,4 @@ func (mock *mockBackend) ConvertActions(ar state.ActionReceiver, fn common.GetAc
return actions, nil
}

var actions = []params.ActionResult{params.ActionResult{Action: &params.Action{Name: "foo"}}}
var actions = []params.ActionResult{{Action: &params.Action{Name: "foo"}}}
2 changes: 1 addition & 1 deletion apiserver/facades/agent/metricsender/metricsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func SendMetrics(st ModelBackend, sender MetricSender, clock clock.Clock, batchS
}

func setHeldBatchUnitMeterStatus(st ModelBackend, units map[string]bool) {
for unitID, _ := range units {
for unitID := range units {
unit, err := st.Unit(unitID)
if err != nil {
logger.Warningf("failed to get unit for setting held batch meter status: %v", err)
Expand Down
Loading

0 comments on commit 3342827

Please sign in to comment.