Skip to content

Commit

Permalink
cli/compose/convert: result 1 (error) is always nil (unparam)
Browse files Browse the repository at this point in the history
cli/compose/convert/service.go:592:76: convertDNSConfig - result 1 (error) is always nil (unparam)
cli/compose/convert/service.go:538:110: convertEndpointSpec - result 1 (error) is always nil (unparam)

Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
silvin-lubecki authored and thaJeztah committed Oct 31, 2019
1 parent 47741f8 commit d640f44
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
21 changes: 7 additions & 14 deletions cli/compose/convert/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ func Service(
configs []*swarm.ConfigReference,
) (swarm.ServiceSpec, error) {
name := namespace.Scope(service.Name)

endpoint, err := convertEndpointSpec(service.Deploy.EndpointMode, service.Ports)
if err != nil {
return swarm.ServiceSpec{}, err
}
endpoint := convertEndpointSpec(service.Deploy.EndpointMode, service.Ports)

mode, err := convertDeployMode(service.Deploy.Mode, service.Deploy.Replicas)
if err != nil {
Expand Down Expand Up @@ -103,10 +99,7 @@ func Service(
return swarm.ServiceSpec{}, err
}

dnsConfig, err := convertDNSConfig(service.DNS, service.DNSSearch)
if err != nil {
return swarm.ServiceSpec{}, err
}
dnsConfig := convertDNSConfig(service.DNS, service.DNSSearch)

var privileges swarm.Privileges
privileges.CredentialSpec, err = convertCredentialSpec(
Expand Down Expand Up @@ -575,7 +568,7 @@ func convertResources(source composetypes.Resources) (*swarm.ResourceRequirement
return resources, nil
}

func convertEndpointSpec(endpointMode string, source []composetypes.ServicePortConfig) (*swarm.EndpointSpec, error) {
func convertEndpointSpec(endpointMode string, source []composetypes.ServicePortConfig) *swarm.EndpointSpec {
portConfigs := []swarm.PortConfig{}
for _, port := range source {
portConfig := swarm.PortConfig{
Expand All @@ -594,7 +587,7 @@ func convertEndpointSpec(endpointMode string, source []composetypes.ServicePortC
return &swarm.EndpointSpec{
Mode: swarm.ResolutionMode(strings.ToLower(endpointMode)),
Ports: portConfigs,
}, nil
}
}

func convertEnvironment(source map[string]*string) []string {
Expand Down Expand Up @@ -629,14 +622,14 @@ func convertDeployMode(mode string, replicas *uint64) (swarm.ServiceMode, error)
return serviceMode, nil
}

func convertDNSConfig(DNS []string, DNSSearch []string) (*swarm.DNSConfig, error) {
func convertDNSConfig(DNS []string, DNSSearch []string) *swarm.DNSConfig {
if DNS != nil || DNSSearch != nil {
return &swarm.DNSConfig{
Nameservers: DNS,
Search: DNSSearch,
}, nil
}
}
return nil, nil
return nil
}

func convertCredentialSpec(namespace Namespace, spec composetypes.CredentialSpecConfig, refs []*swarm.ConfigReference) (*swarm.CredentialSpec, error) {
Expand Down
16 changes: 5 additions & 11 deletions cli/compose/convert/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func TestConvertEndpointSpec(t *testing.T) {
Published: 80,
},
}
endpoint, err := convertEndpointSpec("vip", source)
endpoint := convertEndpointSpec("vip", source)

expected := swarm.EndpointSpec{
Mode: swarm.ResolutionMode(strings.ToLower("vip")),
Expand All @@ -195,7 +195,6 @@ func TestConvertEndpointSpec(t *testing.T) {
},
}

assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, *endpoint))
}

Expand Down Expand Up @@ -275,9 +274,7 @@ func TestConvertServiceNetworksCustomDefault(t *testing.T) {
}

func TestConvertDNSConfigEmpty(t *testing.T) {
dnsConfig, err := convertDNSConfig(nil, nil)

assert.NilError(t, err)
dnsConfig := convertDNSConfig(nil, nil)
assert.Check(t, is.DeepEqual((*swarm.DNSConfig)(nil), dnsConfig))
}

Expand All @@ -287,26 +284,23 @@ var (
)

func TestConvertDNSConfigAll(t *testing.T) {
dnsConfig, err := convertDNSConfig(nameservers, search)
assert.NilError(t, err)
dnsConfig := convertDNSConfig(nameservers, search)
assert.Check(t, is.DeepEqual(&swarm.DNSConfig{
Nameservers: nameservers,
Search: search,
}, dnsConfig))
}

func TestConvertDNSConfigNameservers(t *testing.T) {
dnsConfig, err := convertDNSConfig(nameservers, nil)
assert.NilError(t, err)
dnsConfig := convertDNSConfig(nameservers, nil)
assert.Check(t, is.DeepEqual(&swarm.DNSConfig{
Nameservers: nameservers,
Search: nil,
}, dnsConfig))
}

func TestConvertDNSConfigSearch(t *testing.T) {
dnsConfig, err := convertDNSConfig(nil, search)
assert.NilError(t, err)
dnsConfig := convertDNSConfig(nil, search)
assert.Check(t, is.DeepEqual(&swarm.DNSConfig{
Nameservers: nil,
Search: search,
Expand Down

0 comments on commit d640f44

Please sign in to comment.