from __future__ import absolute_import

# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest

# Import Salt libs
import salt.utils.platform


@skipIf(not salt.utils.platform.is_windows(), 'windows test only')
class WinDNSTest(ModuleCase):
    '''
    Test for salt.modules.win_dns_client
    '''
    @destructiveTest
    def test_add_remove_dns(self):
        '''
        Test add and removing a dns server
        '''
        dns = '8.8.8.8'
        interface = 'Ethernet'
        # add dns server
        self.assertTrue(self.run_function('win_dns_client.add_dns', [dns, interface], index=42))

        srvs = self.run_function('win_dns_client.get_dns_servers', interface=interface)
        self.assertIn(dns, srvs)

        # remove dns server
        self.assertTrue(self.run_function('win_dns_client.rm_dns', [dns], interface=interface))

        srvs = self.run_function('win_dns_client.get_dns_servers', interface=interface)
        self.assertNotIn(dns, srvs)

from __future__ import absolute_import

# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest

# Import Salt libs
import salt.utils.platform


@skipIf(not salt.utils.platform.is_windows(), 'windows test only')
class WinDNSTest(ModuleCase):
    '''
    Test for salt.modules.win_dns_client
    '''
    @destructiveTest
    def test_add_remove_dns(self):
        '''
        Test add and removing a dns server
        '''
        # Get a list of interfaces on the system
        interfaces = self.run_function('network.interfaces_names')
        skipIf(interfaces.count == 0, 'This test requires a network interface')

        interface = interfaces[0]
        dns = '8.8.8.8'
        # add dns server
        self.assertTrue(self.run_function('win_dns_client.add_dns', [dns, interface], index=42))

        srvs = self.run_function('win_dns_client.get_dns_servers', interface=interface)
        self.assertIn(dns, srvs)

        # remove dns server
        self.assertTrue(self.run_function('win_dns_client.rm_dns', [dns], interface=interface))

        srvs = self.run_function('win_dns_client.get_dns_servers', interface=interface)
        self.assertNotIn(dns, srvs)

Fix the failing dns test on Windows
Fix the failing dns test on Windows

Gets the name of the first interface on the system. Windows network
interfaces don't have the same name across Window systems. YOu can even
go as far as naming them whatever you want. The test was failing because
the interface name was hard-coded as 'Ethernet'.

  from __future__ import absolute_import
  
  # Import Salt Testing libs
  from tests.support.case import ModuleCase
  from tests.support.unit import skipIf
  from tests.support.helpers import destructiveTest
  
  # Import Salt libs
  import salt.utils.platform
  
  
  @skipIf(not salt.utils.platform.is_windows(), 'windows test only')
  class WinDNSTest(ModuleCase):
      '''
      Test for salt.modules.win_dns_client
      '''
      @destructiveTest
      def test_add_remove_dns(self):
          '''
          Test add and removing a dns server
          '''
+         # Get a list of interfaces on the system
+         interfaces = self.run_function('network.interfaces_names')
+         skipIf(interfaces.count == 0, 'This test requires a network interface')
+ 
+         interface = interfaces[0]
          dns = '8.8.8.8'
-         interface = 'Ethernet'
          # add dns server
          self.assertTrue(self.run_function('win_dns_client.add_dns', [dns, interface], index=42))
  
          srvs = self.run_function('win_dns_client.get_dns_servers', interface=interface)
          self.assertIn(dns, srvs)
  
          # remove dns server
          self.assertTrue(self.run_function('win_dns_client.rm_dns', [dns], interface=interface))
  
          srvs = self.run_function('win_dns_client.get_dns_servers', interface=interface)
          self.assertNotIn(dns, srvs)
  
Fix the failing dns test on Windows
## Code Before:
from __future__ import absolute_import

# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest

# Import Salt libs
import salt.utils.platform


@skipIf(not salt.utils.platform.is_windows(), 'windows test only')
class WinDNSTest(ModuleCase):
    '''
    Test for salt.modules.win_dns_client
    '''
    @destructiveTest
    def test_add_remove_dns(self):
        '''
        Test add and removing a dns server
        '''
        dns = '8.8.8.8'
        interface = 'Ethernet'
        # add dns server
        self.assertTrue(self.run_function('win_dns_client.add_dns', [dns, interface], index=42))

        srvs = self.run_function('win_dns_client.get_dns_servers', interface=interface)
        self.assertIn(dns, srvs)

        # remove dns server
        self.assertTrue(self.run_function('win_dns_client.rm_dns', [dns], interface=interface))

        srvs = self.run_function('win_dns_client.get_dns_servers', interface=interface)
        self.assertNotIn(dns, srvs)

## Instruction:
Fix the failing dns test on Windows
## Code After:
from __future__ import absolute_import

# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
from tests.support.helpers import destructiveTest

# Import Salt libs
import salt.utils.platform


@skipIf(not salt.utils.platform.is_windows(), 'windows test only')
class WinDNSTest(ModuleCase):
    '''
    Test for salt.modules.win_dns_client
    '''
    @destructiveTest
    def test_add_remove_dns(self):
        '''
        Test add and removing a dns server
        '''
        # Get a list of interfaces on the system
        interfaces = self.run_function('network.interfaces_names')
        skipIf(interfaces.count == 0, 'This test requires a network interface')

        interface = interfaces[0]
        dns = '8.8.8.8'
        # add dns server
        self.assertTrue(self.run_function('win_dns_client.add_dns', [dns, interface], index=42))

        srvs = self.run_function('win_dns_client.get_dns_servers', interface=interface)
        self.assertIn(dns, srvs)

        # remove dns server
        self.assertTrue(self.run_function('win_dns_client.rm_dns', [dns], interface=interface))

        srvs = self.run_function('win_dns_client.get_dns_servers', interface=interface)
        self.assertNotIn(dns, srvs)
