flare-up 0.9 → 0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MWI2ZDkyYjVjOTBlMWMyYjI2NzM3NjNhNThkYzFlM2Q5OWYxNDQyNw==
5
- data.tar.gz: !binary |-
6
- OTU0NTBiOGExMTA4MjhjOWViNzllMjUwMWU3YjU5NTcyODVlMmFhZA==
2
+ SHA1:
3
+ metadata.gz: ebf7bb2fe2846e38d84a508ef89c83fc180977e8
4
+ data.tar.gz: 6878d96fdb6b2e87c5df4e31c29a8d9e892a6fad
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MTM0MDVlMzAxOGUxOGQzNTRkNTQwMDBmNTQ4ZmU2MjY0OTRmZTI5YjY3OTZi
10
- ZTBiYTUxNjk5YjZiYTI5ZDRkYjI5NDljOWY0YmI2NjBkYmZiMjFkZDgyZWVl
11
- YmNmMjZjOWM0OWZmNmE0ZjZjN2E4OTlhZTNkOGFjY2E3MDY5MWY=
12
- data.tar.gz: !binary |-
13
- OWJkODg5ZmMyOGRjNDljZGIwNmE3MDdlMWMyMjUzZTBhY2Q5YjQ4MDNiN2Iw
14
- MTUxZWVjZTE4YmIyZDY4ZjU1ZGQ2ZjEzZTgzMGFlYmU4OTY3NmIyZGVhNWNj
15
- YmNkMDlhZmNhMzAzMzg1NmZjZjM4MWIyOGI1OTk1MDY1MGFmMDE=
6
+ metadata.gz: fadaa219c2b923ac356995d3f18aff7954fd2951774065adf1d5a9ea7c18319d3d675651fd363ce20d8ab05b7b8865ff9f9f64a8fb17616e809b9122f4b60c62
7
+ data.tar.gz: 059e64ac2fb287c514a13dae3ff8af2894dc7ae677bffe9c5845a893067bf3d697bdf6f900fd161492ca8d0667aa99d99427eba32395579f693348804e7168b6
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  pkg/
2
+ .idea/
2
3
  .DS_Store
3
4
  .env
4
5
  makefile
@@ -1 +1 @@
1
- 1.9.3-p547
1
+ 2.0
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
3
  - 2.0.0
5
4
  - 2.1.1
6
5
  - jruby-19mode
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- flare-up (0.9)
4
+ flare-up (0.10)
5
5
  pg (~> 0.17)
6
6
  thor (~> 0.19)
7
7
 
@@ -36,3 +36,6 @@ DEPENDENCIES
36
36
  rake (~> 10.0)
37
37
  rspec (~> 3.0)
38
38
  rspec-its (~> 1.0)
39
+
40
+ BUNDLED WITH
41
+ 1.10.6
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Sharethrough
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -34,6 +34,7 @@ Options:
34
34
  [--aws-secret-key=AWS_SECRET_KEY] # Required unless ENV['AWS_SECRET_ACCESS_KEY'] is set.
35
35
  [--redshift-username=REDSHIFT_USERNAME] # Required unless ENV['REDSHIFT_USERNAME'] is set.
36
36
  [--redshift-password=REDSHIFT_PASSWORD] # Required unless ENV['REDSHIFT_PASSWORD'] is set.
37
+ [--redshift-port=REDSHIFT_PORT] # Optional (defaults to 5439)
37
38
  [--column-list=one two three] # A space-separated list of columns, should your DATA_SOURCE require it
38
39
  [--copy-options=COPY_OPTIONS] # Appended to the end of the COPY command; enclose "IN QUOTES"
39
40
  [--colorize-output], [--no-colorize-output] # Should Flare-up colorize its output?
@@ -50,6 +51,7 @@ Options:
50
51
  [--column-list=COLUMN_LIST] # Required. A space-separated list of columns with their data-types, enclose "IN QUOTES"
51
52
  [--redshift-username=REDSHIFT_USERNAME] # Required unless ENV['REDSHIFT_USERNAME'] is set.
52
53
  [--redshift-password=REDSHIFT_PASSWORD] # Required unless ENV['REDSHIFT_PASSWORD'] is set.
54
+ [--redshift-port=REDSHIFT_PORT] # Optional (defaults to 5439)
53
55
  [--colorize-output], [--no-colorize-output] # Should Flare-up colorize its output?
54
56
  # Default: true
55
57
  ```
@@ -63,6 +65,21 @@ Usage:
63
65
  Options:
64
66
  [--redshift-username=REDSHIFT_USERNAME] # Required unless ENV['REDSHIFT_USERNAME'] is set.
65
67
  [--redshift-password=REDSHIFT_PASSWORD] # Required unless ENV['REDSHIFT_PASSWORD'] is set.
68
+ [--redshift-port=REDSHIFT_PORT] # Optional (defaults to 5439)
69
+ [--colorize-output], [--no-colorize-output] # Should Flare-up colorize its output?
70
+ # Default: true
71
+ ```
72
+
73
+ ### TRUNCATE
74
+
75
+ ```
76
+ Usage:
77
+ flare-up truncate REDSHIFT_ENDPOINT DATABASE TABLE
78
+
79
+ Options:
80
+ [--redshift-username=REDSHIFT_USERNAME] # Required unless ENV['REDSHIFT_USERNAME'] is set.
81
+ [--redshift-password=REDSHIFT_PASSWORD] # Required unless ENV['REDSHIFT_PASSWORD'] is set.
82
+ [--redshift-port=REDSHIFT_PORT] # Optional (defaults to 5439)
66
83
  [--colorize-output], [--no-colorize-output] # Should Flare-up colorize its output?
67
84
  # Default: true
68
85
  ```
@@ -106,3 +123,17 @@ Note that these examples assume you have credentials set as environment variable
106
123
  dev \
107
124
  hearthstone_cards
108
125
  ```
126
+
127
+ ### TRUNCATE
128
+
129
+ ```
130
+ > flare-up \
131
+ truncate \
132
+ flare-up-test.cskjnp4xvaje.us-west-2.redshift.amazonaws.com \
133
+ dev \
134
+ hearthstone_cards
135
+ ```
136
+
137
+ ## License
138
+
139
+ This project is Copyright (c) 2015, Sharethrough and licensed under the [MIT License](LICENSE.md).
@@ -15,6 +15,7 @@ require 'flare_up/command/base'
15
15
  require 'flare_up/command/copy'
16
16
  require 'flare_up/command/create_table'
17
17
  require 'flare_up/command/drop_table'
18
+ require 'flare_up/command/truncate'
18
19
 
19
20
  require 'flare_up/boot'
20
21
  require 'flare_up/cli'
@@ -32,11 +32,13 @@ module FlareUp
32
32
  end
33
33
 
34
34
  def self.create_connection
35
+ puts
35
36
  FlareUp::Connection.new(
36
37
  OptionStore.get(:redshift_endpoint),
37
38
  OptionStore.get(:database),
38
39
  OptionStore.get(:redshift_username),
39
- OptionStore.get(:redshift_password)
40
+ OptionStore.get(:redshift_password),
41
+ OptionStore.get(:redshift_port)
40
42
  )
41
43
  end
42
44
  private_class_method :create_connection
@@ -67,4 +69,4 @@ module FlareUp
67
69
 
68
70
  end
69
71
 
70
- end
72
+ end
@@ -19,6 +19,7 @@ module FlareUp
19
19
  CLI.env_validator(boot_options, :aws_secret_key, 'AWS_SECRET_ACCESS_KEY')
20
20
  CLI.env_validator(boot_options, :redshift_username, 'REDSHIFT_USERNAME')
21
21
  CLI.env_validator(boot_options, :redshift_password, 'REDSHIFT_PASSWORD')
22
+ CLI.env_validator(boot_options, :redshift_port, 'REDSHIFT_PORT', 5439)
22
23
  rescue ArgumentError => e
23
24
  Emitter.error(e.message)
24
25
  CLI.bailout(1)
@@ -37,6 +38,7 @@ module FlareUp
37
38
  all_shared_options = [
38
39
  [:redshift_username, { :type => :string, :desc => "Required unless ENV['REDSHIFT_USERNAME'] is set." }],
39
40
  [:redshift_password, { :type => :string, :desc => "Required unless ENV['REDSHIFT_PASSWORD'] is set." }],
41
+ [:redshift_port, { :type => :numeric, :desc => "Optional (defaults to 5439)" }],
40
42
  [:colorize_output, { :type => :boolean, :desc => 'Should Flare-up colorize its output?', :default => true }]
41
43
  ]
42
44
  copy_options = [
@@ -89,6 +91,17 @@ in DATABASE_NAME at REDSHIFT_ENDPOINT.
89
91
  all_shared_options.each { |shared_options| method_option *shared_options }
90
92
  alias_method :drop_table, :no_datasource_command
91
93
 
94
+ ### truncate command
95
+
96
+ desc 'truncate REDSHIFT_ENDPOINT DATABASE TABLE', 'TRUNCATE DATABASE.TABLE in REDSHIFT_ENDPOINT'
97
+ long_desc <<-LONGDESC
98
+ `flare-up truncate` executes the Redshift TRUNCATE command, deleting all rows the table named TABLE\x5
99
+ in DATABASE_NAME at REDSHIFT_ENDPOINT.
100
+ #{long_desc_footer}
101
+ LONGDESC
102
+ all_shared_options.each { |shared_options| method_option *shared_options }
103
+ alias_method :truncate, :no_datasource_command
104
+
92
105
  # transforms the symbol method names to the corresponding class under
93
106
  # the FlareUp::Command namespace
94
107
  def self.command_formatter(sym)
@@ -97,8 +110,8 @@ in DATABASE_NAME at REDSHIFT_ENDPOINT.
97
110
  "FlareUp::Command::#{name}".split("::").reduce(Object) { |a, e| a.const_get e }
98
111
  end
99
112
 
100
- def self.env_validator(options, option_name, env_variable_name)
101
- options[option_name] ||= ENVWrap.get(env_variable_name)
113
+ def self.env_validator(options, option_name, env_variable_name, default_value=nil)
114
+ options[option_name] ||= (ENVWrap.get(env_variable_name) || default_value)
102
115
  return if options[option_name]
103
116
  raise ArgumentError, "One of either the --#{option_name} option or the ENV['#{env_variable_name}'] must be set"
104
117
  end
@@ -109,4 +122,4 @@ in DATABASE_NAME at REDSHIFT_ENDPOINT.
109
122
 
110
123
  end
111
124
 
112
- end
125
+ end
@@ -17,6 +17,33 @@ module FlareUp
17
17
  def initialize(table_name, *args)
18
18
  @table_name = table_name
19
19
  end
20
+
21
+ # Split CamelCase and UPCASE it for error presentation
22
+ def name
23
+ namespaces = self.class.to_s.split('::')
24
+ namespaces.last.split(/(?=[A-Z])/).map { |w| w.upcase }.join(' ')
25
+ end
26
+
27
+ def execute(connection)
28
+ begin
29
+ connection.execute(get_command)
30
+ []
31
+ rescue PG::InternalError => e
32
+ case e.message
33
+ when /Check 'stl_load_errors' system table for details/
34
+ return STLLoadErrorFetcher.fetch_errors(connection)
35
+ when /The specified S3 prefix '.+' does not exist/
36
+ raise DataSourceError, "A data source with prefix '#{@data_source}' does not exist."
37
+ when /The bucket you are attempting to access must be addressed using the specified endpoint/
38
+ raise OtherZoneBucketError, "Your Redshift instance appears to be in a different zone than your S3 bucket. Specify the \"REGION 'bucket-region'\" option."
39
+ when /PG::SyntaxError/
40
+ matches = /syntax error (.+) \(PG::SyntaxError\)/.match(e.message)
41
+ raise SyntaxError, "Syntax error in the #{name} command: [#{matches[1]}]."
42
+ else
43
+ raise e
44
+ end
45
+ end
46
+ end
20
47
  end
21
48
  end
22
49
  end
@@ -27,27 +27,6 @@ module FlareUp
27
27
  @columns = columns
28
28
  end
29
29
 
30
- def execute(connection)
31
- begin
32
- connection.execute(get_command)
33
- []
34
- rescue PG::InternalError => e
35
- case e.message
36
- when /Check 'stl_load_errors' system table for details/
37
- return STLLoadErrorFetcher.fetch_errors(connection)
38
- when /The specified S3 prefix '.+' does not exist/
39
- raise DataSourceError, "A data source with prefix '#{@data_source}' does not exist."
40
- when /The bucket you are attempting to access must be addressed using the specified endpoint/
41
- raise OtherZoneBucketError, "Your Redshift instance appears to be in a different zone than your S3 bucket. Specify the \"REGION 'bucket-region'\" option."
42
- when /PG::SyntaxError/
43
- matches = /syntax error (.+) \(PG::SyntaxError\)/.match(e.message)
44
- raise SyntaxError, "Syntax error in the COPY command: [#{matches[1]}]."
45
- else
46
- raise e
47
- end
48
- end
49
- end
50
-
51
30
  private
52
31
 
53
32
  def get_columns
@@ -9,7 +9,6 @@ module FlareUp
9
9
  super
10
10
  end
11
11
 
12
-
13
12
  # http://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_TABLE_NEW.html
14
13
  def get_command
15
14
  "CREATE TABLE #{@table_name} #{get_columns} #{@options}"
@@ -29,23 +28,6 @@ module FlareUp
29
28
  @columns = columns_separated
30
29
  end
31
30
 
32
- def execute(connection)
33
- begin
34
- connection.execute(get_command)
35
- []
36
- rescue PG::InternalError => e
37
- case e.message
38
- when /Check 'stl_load_errors' system table for details/
39
- return STLLoadErrorFetcher.fetch_errors(connection)
40
- when /PG::SyntaxError/
41
- matches = /syntax error (.+) \(PG::SyntaxError\)/.match(e.message)
42
- raise SyntaxError, "Syntax error in the CREATE TABLE command: [#{matches[1]}]."
43
- else
44
- raise e
45
- end
46
- end
47
- end
48
-
49
31
  private
50
32
 
51
33
  def get_columns
@@ -6,23 +6,6 @@ module FlareUp
6
6
  def get_command
7
7
  "DROP TABLE #{@table_name} #{@options}"
8
8
  end
9
-
10
- def execute(connection)
11
- begin
12
- connection.execute(get_command)
13
- []
14
- rescue PG::InternalError => e
15
- case e.message
16
- when /Check 'stl_load_errors' system table for details/
17
- return STLLoadErrorFetcher.fetch_errors(connection)
18
- when /PG::SyntaxError/
19
- matches = /syntax error (.+) \(PG::SyntaxError\)/.match(e.message)
20
- raise SyntaxError, "Syntax error in the DROP TABLE command: [#{matches[1]}]."
21
- else
22
- raise e
23
- end
24
- end
25
- end
26
9
  end
27
10
  end
28
11
  end
@@ -0,0 +1,11 @@
1
+ module FlareUp
2
+ module Command
3
+ class Truncate < Command::Base
4
+
5
+ # http://docs.aws.amazon.com/redshift/latest/dg/r_TRUNCATE.html
6
+ def get_command
7
+ "TRUNCATE #{@table_name}"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -22,13 +22,13 @@ module FlareUp
22
22
  attr_accessor :password
23
23
  attr_accessor :connect_timeout
24
24
 
25
- def initialize(host, dbname, user, password)
25
+ def initialize(host, dbname, user, password, port)
26
26
  @host = host
27
27
  @dbname = dbname
28
28
  @user = user
29
29
  @password = password
30
30
 
31
- @port = 5439
31
+ @port = port
32
32
  @connect_timeout = 5
33
33
  end
34
34
 
@@ -54,7 +54,7 @@ module FlareUp
54
54
  when /nodename nor servname provided, or not known/
55
55
  raise HostUnknownOrInaccessibleError, "Host unknown or unreachable: #{@host}"
56
56
  when /timeout expired/
57
- raise TimeoutError, 'Timeout connecting to the database (have you checked your Redshift security groups?)'
57
+ raise TimeoutError, "Timeout connecting to the database (have you checked your Redshift security groups?)"
58
58
  when /database ".+" does not exist/
59
59
  raise NoDatabaseError, "Database #{@dbname} does not exist"
60
60
  when /password authentication failed for user/
@@ -89,4 +89,4 @@ module FlareUp
89
89
 
90
90
  end
91
91
 
92
- end
92
+ end
@@ -1,3 +1,3 @@
1
1
  module FlareUp
2
- VERSION = '0.9'
2
+ VERSION = '0.10'
3
3
  end
@@ -5,7 +5,7 @@ db_name = 'dev'
5
5
  table_name = 'hearthstone_cards'
6
6
  data_source = 's3://slif-redshift/hearthstone_cards_short_list.csv'
7
7
 
8
- conn = FlareUp::Connection.new(host_name, db_name, ENV['REDSHIFT_USERNAME'], ENV['REDSHIFT_PASSWORD'])
8
+ conn = FlareUp::Connection.new(host_name, db_name, ENV['REDSHIFT_USERNAME'], ENV['REDSHIFT_PASSWORD'], ENV['REDSHIFT_PORT'])
9
9
 
10
10
  copy = FlareUp::Command::Copy.new(table_name, data_source, ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY'])
11
11
  copy.columns = %w(name cost attack health description)
@@ -61,4 +61,4 @@ flare-up copy \
61
61
  hearthstone_cards \
62
62
  --column-list name cost attack health description \
63
63
  --copy_options "CSV ;lmlkmlk3"
64
- COMMAND
64
+ COMMAND
@@ -100,7 +100,8 @@ describe FlareUp::Boot do
100
100
  :redshift_endpoint => 'TEST_REDSHIFT_ENDPOINT',
101
101
  :database => 'TEST_DATABASE',
102
102
  :redshift_username => 'TEST_REDSHIFT_USERNAME',
103
- :redshift_password => 'TEST_REDSHIFT_PASSWORD'
103
+ :redshift_password => 'TEST_REDSHIFT_PASSWORD',
104
+ :redshift_port => 5439
104
105
  }
105
106
  )
106
107
  end
@@ -111,6 +112,7 @@ describe FlareUp::Boot do
111
112
  expect(connection.dbname).to eq('TEST_DATABASE')
112
113
  expect(connection.user).to eq('TEST_REDSHIFT_USERNAME')
113
114
  expect(connection.password).to eq('TEST_REDSHIFT_PASSWORD')
115
+ expect(connection.port).to eq(5439)
114
116
  end
115
117
  end
116
118
 
@@ -157,4 +159,4 @@ describe FlareUp::Boot do
157
159
 
158
160
  end
159
161
 
160
- end
162
+ end
@@ -1,7 +1,7 @@
1
1
  describe FlareUp::CLI do
2
2
 
3
3
  let(:required_arguments) { %w(copy TEST_DATA_SOURCE TEST_REDSHIFT_ENDPOINT TEST_DATABASE TEST_TABLE) }
4
- let(:required_options) do
4
+ let(:base_options) do
5
5
  {
6
6
  :data_source => 'TEST_DATA_SOURCE',
7
7
  :redshift_endpoint => 'TEST_REDSHIFT_ENDPOINT',
@@ -9,6 +9,7 @@ describe FlareUp::CLI do
9
9
  :table => 'TEST_TABLE',
10
10
  :redshift_username => 'TEST_REDSHIFT_USERNAME',
11
11
  :redshift_password => 'TEST_REDSHIFT_PASSWORD',
12
+ :redshift_port => 5439,
12
13
  :aws_access_key => 'TEST_AWS_ACCESS_KEY',
13
14
  :aws_secret_key => 'TEST_AWS_SECRET_KEY',
14
15
  :colorize_output => true
@@ -20,6 +21,7 @@ describe FlareUp::CLI do
20
21
  allow(FlareUp::ENVWrap).to receive(:get).with('AWS_SECRET_ACCESS_KEY').and_return('TEST_AWS_SECRET_KEY')
21
22
  allow(FlareUp::ENVWrap).to receive(:get).with('REDSHIFT_USERNAME').and_return('TEST_REDSHIFT_USERNAME')
22
23
  allow(FlareUp::ENVWrap).to receive(:get).with('REDSHIFT_PASSWORD').and_return('TEST_REDSHIFT_PASSWORD')
24
+ allow(FlareUp::ENVWrap).to receive(:get).with('REDSHIFT_PORT').and_return(nil)
23
25
  allow(FlareUp::Boot).to receive(:boot)
24
26
  end
25
27
 
@@ -31,9 +33,9 @@ describe FlareUp::CLI do
31
33
  end
32
34
 
33
35
  context 'when no options are specified' do
34
- it 'should boot with the proper options' do
36
+ it 'should boot with the base options' do
35
37
  FlareUp::CLI.start(required_arguments)
36
- expect(FlareUp::OptionStore.get_options).to eq(required_options)
38
+ expect(FlareUp::OptionStore.get_options).to eq(base_options)
37
39
  end
38
40
  end
39
41
 
@@ -121,6 +123,31 @@ describe FlareUp::CLI do
121
123
  end
122
124
  end
123
125
 
126
+ describe 'port' do
127
+ context 'when it is specified on the CLI' do
128
+ it 'should boot with the proper options' do
129
+ FlareUp::CLI.start(required_arguments + %w(--redshift_port 1234))
130
+ expect(FlareUp::OptionStore.get(:redshift_port)).to eq(1234)
131
+ end
132
+ end
133
+ context 'when it is not specified on the CLI' do
134
+ context 'when it is available via ENV' do
135
+ it 'should boot with the key from the environment' do
136
+ allow(FlareUp::ENVWrap).to receive(:get).with('REDSHIFT_PORT').and_return(5678)
137
+ FlareUp::CLI.start(required_arguments)
138
+ expect(FlareUp::OptionStore.get(:redshift_port)).to eq(5678)
139
+ end
140
+ end
141
+ context 'when it is not available via ENV' do
142
+ it 'should boot with the default value' do
143
+ allow(FlareUp::ENVWrap).to receive(:get).with('REDSHIFT_PORT').and_return(nil)
144
+ FlareUp::CLI.start(required_arguments)
145
+ expect(FlareUp::OptionStore.get(:redshift_port)).to eq(5439)
146
+ end
147
+ end
148
+ end
149
+ end
150
+
124
151
  end
125
152
 
126
153
  describe 'AWS credentials' do
@@ -181,4 +208,4 @@ describe FlareUp::CLI do
181
208
 
182
209
  end
183
210
 
184
- end
211
+ end
@@ -0,0 +1,74 @@
1
+ describe FlareUp::Command::Truncate do
2
+
3
+ subject do
4
+ FlareUp::Command::Truncate.new('TEST_TABLE_NAME', nil, nil, nil)
5
+ end
6
+
7
+ its(:table_name) { should == 'TEST_TABLE_NAME' }
8
+
9
+ describe '#get_command' do
10
+ context 'when no optional fields are provided' do
11
+ it 'should return a basic TRUNCATE command' do
12
+ expect(subject.get_command).to eq("TRUNCATE TEST_TABLE_NAME")
13
+ end
14
+ end
15
+ end
16
+
17
+ describe '#execute' do
18
+
19
+ let(:conn) { instance_double('FlareUp::Connection') }
20
+
21
+ context 'when successful' do
22
+ before do
23
+ expect(conn).to receive(:execute)
24
+ end
25
+ it 'should do something' do
26
+ expect(subject.execute(conn)).to eq([])
27
+ end
28
+ end
29
+
30
+ context 'when unsuccessful' do
31
+
32
+ before do
33
+ expect(conn).to receive(:execute).and_raise(exception, message)
34
+ end
35
+
36
+ context 'when there was an internal error' do
37
+
38
+ let(:exception) { PG::InternalError }
39
+
40
+ context 'when there was an error loading' do
41
+ let(:message) { "Check 'stl_load_errors' system table for details" }
42
+ before do
43
+ allow(FlareUp::STLLoadErrorFetcher).to receive(:fetch_errors).and_return('FOO')
44
+ end
45
+ it 'should respond with a list of errors' do
46
+ expect(subject.execute(conn)).to eq('FOO')
47
+ end
48
+ end
49
+
50
+ context 'when there was another kind of internal error' do
51
+ let(:message) { '_' }
52
+ it 'should respond with a list of errors' do
53
+ expect { subject.execute(conn) }.to raise_error(PG::InternalError, '_')
54
+ end
55
+ end
56
+
57
+ context 'when there is a syntax error in the command' do
58
+ let(:message) { 'ERROR: syntax error at or near "lmlkmlk3" (PG::SyntaxError)' }
59
+ it 'should be error' do
60
+ expect { subject.execute(conn) }.to raise_error(FlareUp::SyntaxError, 'Syntax error in the TRUNCATE command: [at or near "lmlkmlk3"].')
61
+ end
62
+ end
63
+ end
64
+
65
+ context 'when there was another type of error' do
66
+ let(:exception) { PG::ConnectionBad }
67
+ let(:message) { '_' }
68
+ it 'should do something' do
69
+ expect { subject.execute(conn) }.to raise_error(PG::ConnectionBad, '_')
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -1,7 +1,7 @@
1
1
  describe FlareUp::Connection do
2
2
 
3
3
  subject do
4
- FlareUp::Connection.new('TEST_HOST', 'TEST_DB_NAME', 'TEST_USER', 'TEST_PASSWORD')
4
+ FlareUp::Connection.new('TEST_HOST', 'TEST_DB_NAME', 'TEST_USER', 'TEST_PASSWORD', 5439)
5
5
  end
6
6
 
7
7
  let(:mock_pg_connection) { instance_double('PGConn') }
@@ -15,7 +15,7 @@ describe FlareUp::Connection do
15
15
 
16
16
  describe 'Writers' do
17
17
  subject do
18
- FlareUp::Connection.new('', '', '', '').tap do |c|
18
+ FlareUp::Connection.new('', '', '', '', '').tap do |c|
19
19
  c.host = 'TEST_HOST'
20
20
  c.port = 111
21
21
  c.dbname = 'TEST_DB_NAME'
@@ -135,4 +135,4 @@ describe FlareUp::Connection do
135
135
  end
136
136
  end
137
137
 
138
- end
138
+ end
@@ -45,7 +45,8 @@ describe FlareUp::Emitter do
45
45
  :aws_access_key => 'access',
46
46
  :aws_secret_key => 'secret',
47
47
  :redshift_username => 'user',
48
- :redshift_password => 'pass'
48
+ :redshift_password => 'pass',
49
+ :redshift_port => '1234'
49
50
  })
50
51
  end
51
52
  it 'should hide it' do
@@ -55,4 +56,4 @@ describe FlareUp::Emitter do
55
56
 
56
57
  end
57
58
 
58
- end
59
+ end
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flare-up
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.9'
4
+ version: '0.10'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Slifka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-17 00:00:00.000000000 Z
11
+ date: 2015-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.17'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.17'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: thor
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0.19'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.19'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '10.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '3.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec-its
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '1.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.0'
83
83
  description: Flare-up makes Redshift COPY scriptable by providing CLI access to the
@@ -89,13 +89,14 @@ executables:
89
89
  extensions: []
90
90
  extra_rdoc_files: []
91
91
  files:
92
- - .gitignore
93
- - .rspec
94
- - .ruby-gemset
95
- - .ruby-version
96
- - .travis.yml
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".ruby-gemset"
95
+ - ".ruby-version"
96
+ - ".travis.yml"
97
97
  - Gemfile
98
98
  - Gemfile.lock
99
+ - LICENSE.md
99
100
  - README.md
100
101
  - Rakefile
101
102
  - bin/flare-up
@@ -107,6 +108,7 @@ files:
107
108
  - lib/flare_up/command/copy.rb
108
109
  - lib/flare_up/command/create_table.rb
109
110
  - lib/flare_up/command/drop_table.rb
111
+ - lib/flare_up/command/truncate.rb
110
112
  - lib/flare_up/connection.rb
111
113
  - lib/flare_up/emitter.rb
112
114
  - lib/flare_up/env_wrap.rb
@@ -124,6 +126,7 @@ files:
124
126
  - spec/lib/flare_up/command/copy_spec.rb
125
127
  - spec/lib/flare_up/command/create_table_spec.rb
126
128
  - spec/lib/flare_up/command/drop_table_spec.rb
129
+ - spec/lib/flare_up/command/truncate_spec.rb
127
130
  - spec/lib/flare_up/connection_spec.rb
128
131
  - spec/lib/flare_up/emitter_spec.rb
129
132
  - spec/lib/flare_up/option_store_spec.rb
@@ -139,17 +142,17 @@ require_paths:
139
142
  - lib
140
143
  required_ruby_version: !ruby/object:Gem::Requirement
141
144
  requirements:
142
- - - ! '>='
145
+ - - ">="
143
146
  - !ruby/object:Gem::Version
144
147
  version: '0'
145
148
  required_rubygems_version: !ruby/object:Gem::Requirement
146
149
  requirements:
147
- - - ! '>='
150
+ - - ">="
148
151
  - !ruby/object:Gem::Version
149
152
  version: '0'
150
153
  requirements: []
151
154
  rubyforge_project:
152
- rubygems_version: 2.2.2
155
+ rubygems_version: 2.4.8
153
156
  signing_key:
154
157
  specification_version: 4
155
158
  summary: Command-line access to bulk data loading via Redshift's CREATE TABLE, COPY,
@@ -160,6 +163,7 @@ test_files:
160
163
  - spec/lib/flare_up/command/copy_spec.rb
161
164
  - spec/lib/flare_up/command/create_table_spec.rb
162
165
  - spec/lib/flare_up/command/drop_table_spec.rb
166
+ - spec/lib/flare_up/command/truncate_spec.rb
163
167
  - spec/lib/flare_up/connection_spec.rb
164
168
  - spec/lib/flare_up/emitter_spec.rb
165
169
  - spec/lib/flare_up/option_store_spec.rb