1
|
require './test/csv_test_helper'
|
2
|
require './lib/hammer_cli_csv'
|
3
|
|
4
|
module Resources
|
5
|
class TestProducts < 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 products --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 products [OPTIONS]
|
18
|
|
19
|
Options:
|
20
|
--[no-]sync Sync product repositories (default true)
|
21
|
Default: true
|
22
|
--continue-on-error Continue processing even if individual resource error
|
23
|
--export Export current data instead of importing
|
24
|
--file FILE_NAME CSV file (default to /dev/stdout with --export, otherwise required)
|
25
|
--organization ORGANIZATION Only process organization matching this name
|
26
|
-h, --help print help
|
27
|
-v, --verbose be verbose
|
28
|
HELP
|
29
|
stop_vcr
|
30
|
end
|
31
|
|
32
|
def test_create_rpm
|
33
|
start_vcr
|
34
|
set_user 'admin'
|
35
|
name = "product create_rpm"
|
36
|
|
37
|
file = Tempfile.new('products_test')
|
38
|
|
39
|
file.write <<-FILE
|
40
|
Name,Label,Organization,Description,Repository,Repository Type,Content Set,Release,Repository Url
|
41
|
#{name},#{name},Test Corporation,,Zoo,Custom Yum,,,https://repos.fedorapeople.org/repos/pulp/pulp/demo_repos/zoo/
|
42
|
FILE
|
43
|
file.rewind
|
44
|
|
45
|
stdout,stderr = capture {
|
46
|
hammer.run(%W{--reload-cache csv products --no-sync --verbose --file #{file.path}})
|
47
|
}
|
48
|
stderr.must_equal ''
|
49
|
lines = stdout.split("\n")
|
50
|
assert_equal "Creating product '#{name}'...Creating repository 'Zoo'...done", lines[0]
|
51
|
file.unlink
|
52
|
|
53
|
product_delete(name)
|
54
|
stop_vcr
|
55
|
end
|
56
|
|
57
|
def test_update_rpm
|
58
|
start_vcr
|
59
|
set_user 'admin'
|
60
|
name = "product update_rpm"
|
61
|
|
62
|
file = Tempfile.new('products_test')
|
63
|
|
64
|
file.write <<-FILE
|
65
|
Name,Label,Organization,Description,Repository,Repository Type,Content Set,Release,Repository Url
|
66
|
#{name},#{name},Test Corporation,,Zoo,Custom Yum,,,https://repos.fedorapeople.org/repos/pulp/pulp/demo_repos/zoo/
|
67
|
FILE
|
68
|
file.rewind
|
69
|
|
70
|
stdout,stderr = capture {
|
71
|
hammer.run(%W{--reload-cache csv products --no-sync --verbose --file #{file.path}})
|
72
|
}
|
73
|
stderr.must_equal ''
|
74
|
lines = stdout.split("\n")
|
75
|
assert_equal "Creating product '#{name}'...Creating repository 'Zoo'...done", lines[0]
|
76
|
|
77
|
file.rewind
|
78
|
stdout,stderr = capture {
|
79
|
hammer.run(%W{--reload-cache csv products --no-sync --verbose --file #{file.path}})
|
80
|
}
|
81
|
stderr.must_equal ''
|
82
|
lines = stdout.split("\n")
|
83
|
assert_equal "Updating product '#{name}'...Updating repository 'Zoo'...done", lines[0]
|
84
|
|
85
|
file.unlink
|
86
|
|
87
|
product_delete(name)
|
88
|
stop_vcr
|
89
|
end
|
90
|
|
91
|
def test_create_update_rpm_docker
|
92
|
start_vcr
|
93
|
set_user 'admin'
|
94
|
name = "product create_update_rpm_docker"
|
95
|
|
96
|
file = Tempfile.new('products_test')
|
97
|
|
98
|
file.write <<-FILE
|
99
|
Name,Label,Organization,Description,Repository,Repository Type,Content Set,Release,Repository Url,Verify SSL,Publish via HTTP,Mirror on Sync,Download Policy,Username,Password
|
100
|
#{name},#{name}label,Test Corporation,Yum Product,Zoo,Custom Yum,,,https://repos.fedorapeople.org/repos/pulp/pulp/demo_repos/zoo/,No,No,No,on_demand,,
|
101
|
#{name},#{name}label,Test Corporation,Docker Product,thomasmckay/hammer,Custom Docker,thomasmckay/hammer,,https://registry-1.docker.io/,Yes,Yes,Yes,"",,
|
102
|
FILE
|
103
|
file.rewind
|
104
|
|
105
|
stdout,stderr = capture {
|
106
|
hammer.run(%W{--reload-cache csv products --no-sync --verbose --file #{file.path}})
|
107
|
}
|
108
|
stderr.must_equal ''
|
109
|
lines = stdout.split("\n")
|
110
|
assert_equal "Creating product '#{name}'...Creating repository 'Zoo'...done", lines[0]
|
111
|
assert_equal "Updating product '#{name}'...Creating repository 'thomasmckay/hammer'...done", lines[1]
|
112
|
|
113
|
file.rewind
|
114
|
stdout,stderr = capture {
|
115
|
hammer.run(%W{--reload-cache csv products --no-sync --verbose --file #{file.path}})
|
116
|
}
|
117
|
stderr.must_equal ''
|
118
|
lines = stdout.split("\n")
|
119
|
assert_equal "Updating product '#{name}'...Updating repository 'Zoo'...done", lines[0]
|
120
|
assert_equal "Updating product '#{name}'...Updating repository 'thomasmckay/hammer'...done", lines[1]
|
121
|
|
122
|
file.unlink
|
123
|
|
124
|
product_delete(name)
|
125
|
stop_vcr
|
126
|
end
|
127
|
|
128
|
def product_delete(name)
|
129
|
stdout,stderr = capture {
|
130
|
hammer.run(%W(product list --organization Test\ Corporation --search #{name}))
|
131
|
}
|
132
|
lines = stdout.split("\n")
|
133
|
if lines.length == 5
|
134
|
id = stdout.split("\n")[3].split(" ")[0]
|
135
|
stdout,stderr = capture {
|
136
|
hammer.run(%W(product delete --organization Test\ Corporation --id #{id}))
|
137
|
}
|
138
|
end
|
139
|
end
|
140
|
end
|
141
|
end
|