Project

General

Profile

Download (2.91 KB) Statistics
| Branch: | Tag: | Revision:

hammer-cli-csv / test / resources / subnets_test.rb @ a2c97209

1
require './test/csv_test_helper'
2
require './lib/hammer_cli_csv'
3

    
4
module Resources
5
  class TestSubnets < MiniTest::Unit::TestCase
6
    def test_usage
7
      start_vcr
8
      set_user 'admin'
9

    
10
      stdout,stderr = capture {
11
        hammer.run(%W{--reload-cache csv subnets --help})
12
      }
13
      assert_equal '', stderr
14
      assert_equal stdout, <<-HELP
15
**** This command is unsupported and is provided as tech preview. ****
16
Usage:
17
     csv subnets [OPTIONS]
18

19
Options:
20
 --continue-on-error           Continue processing even if individual resource error
21
 --export                      Export current data instead of importing
22
 --file FILE_NAME              CSV file (default to /dev/stdout with --export, otherwise required)
23
 --organization ORGANIZATION   Only process organization matching this name
24
 --search SEARCH               Only export search results
25
 -h, --help                    print help
26
 -v, --verbose                 be verbose
27
HELP
28
      stop_vcr
29
    end
30

    
31
    def test_update_subnets
32
      start_vcr
33
      set_user 'admin'
34

    
35
      name = "settings#{rand(10000)}"
36

    
37
      file = Tempfile.new('settings_test')
38
      # rubocop:disable LineLength
39
      file.write <<-FILE
40
Name,Organizations,Locations,Network,Network Mask,Network Prefix,From,To,Domains,Gateway,DHCP Proxy,TFTP Proxy,DNS Proxy,DNS Primary,DNS Secondary,VLAN ID
41
Test Subnet,Test Corporation,Testing,192.168.100.1,255.255.255.0,,"","",test.com,"","",,"","","",""
42
FILE
43
      file.rewind
44

    
45
      stdout,stderr = capture {
46
        hammer.run(%W{--reload-cache csv subnets --verbose --file #{file.path}})
47
      }
48
      stderr.must_equal ''
49
      lines = stdout.split("\n")
50
      # TODO: Cannot delete the subnet since it is associated with the domain so there is no way
51
      #       to clean up after this test. That means the subnet may already exist so assert
52
      #       w/o the "Creating" or "Updating" start of message
53
      assert_match(/.*subnet 'Test Subnet'...done/, lines[0])
54
      file.unlink
55
      stop_vcr
56
    end
57

    
58
    def test_update_subnets_continue
59
      start_vcr
60
      set_user 'admin'
61

    
62
      name = "settings#{rand(10000)}"
63

    
64
      file = Tempfile.new('settings_test')
65
      # rubocop:disable LineLength
66
      file.write <<-FILE
67
Name,Organizations,Locations,Network,Network Mask,Network Prefix,From,To,Domains,Gateway,DHCP Proxy,TFTP Proxy,DNS Proxy,DNS Primary,DNS Secondary,VLAN ID
68
Bad Subnet,Test Corporation,Testing,192.168.100.1,255.255.255.0,24,bad,,test.com,"","",,"","","",""
69
Test Subnet,Test Corporation,Testing,192.168.100.1,255.255.255.0,24,"","",test.com,"","",,"","","",""
70
FILE
71
      file.rewind
72

    
73
      stdout,stderr = capture {
74
        hammer.run(%W{--reload-cache csv subnets --verbose --continue-on-error --file #{file.path}})
75
      }
76
      lines = stderr.split("\n")
77
      refute lines[0].empty?
78
      lines = stdout.split("\n")
79
      assert_equal "Creating subnet 'Bad Subnet'...Updating subnet 'Test Subnet'...done", lines[0]
80
      file.unlink
81
      stop_vcr
82
    end
83
  end
84
end