Selaa lähdekoodia

improve error message for invalid ndots number

instead of printing the whole option, print the _number_ only,
because that's what the error-message is pointing at;

Before this change:

    invalid number for ndots option ndots:foobar

After this change:

    invalid number for ndots option: foobar

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 7 vuotta sitten
vanhempi
commit
b306706062
2 muutettua tiedostoa jossa 7 lisäystä ja 1 poistoa
  1. 1 1
      libnetwork/sandbox_dns_unix.go
  2. 6 0
      libnetwork/service_common_test.go

+ 1 - 1
libnetwork/sandbox_dns_unix.go

@@ -369,7 +369,7 @@ dnsOpt:
 						return fmt.Errorf("invalid ndots option %v", option)
 					}
 					if num, err := strconv.Atoi(parts[1]); err != nil {
-						return fmt.Errorf("invalid number for ndots option %v", option)
+						return fmt.Errorf("invalid number for ndots option: %v", parts[1])
 					} else if num >= 0 {
 						// if the user sets ndots, use the user setting
 						sb.ndotsSet = true

+ 6 - 0
libnetwork/service_common_test.go

@@ -97,4 +97,10 @@ func TestDNSOptions(t *testing.T) {
 	dnsOptionsList = resolvconf.GetOptions(currRC.Content)
 	assert.Equal(t, 1, len(dnsOptionsList))
 	assert.Equal(t, "ndots:0", dnsOptionsList[0])
+
+	sb2.(*sandbox).config.dnsOptionsList = []string{"ndots:foobar"}
+	err = sb2.(*sandbox).setupDNS()
+	require.NoError(t, err)
+	err = sb2.(*sandbox).rebuildDNS()
+	require.EqualError(t, err, "invalid number for ndots option: foobar")
 }