-
Notifications
You must be signed in to change notification settings - Fork 3
Add some basic specs #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| users: { | ||
| name: -> { "Jimbo #{SecureRandom.hex(8)}" } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| foo: { | ||
| bar: "baz" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| -- | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just a very basic dump file created for this purpose may be desirable in the future to also test
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, I haven't looked at the test jet, but I started to use the gem (thanks for creating it), and I had an error (extra data after last expected column) that may be related to having the delimiter inside text columns. I'll read more to confirm if this is a bug unless someone has experienced it before and reply with some advice. |
||
| -- PostgreSQL database dump | ||
| -- | ||
|
|
||
| -- Dumped from database version 11.18 | ||
| -- Dumped by pg_dump version 14.6 (Homebrew) | ||
|
|
||
| SET statement_timeout = 0; | ||
| SET lock_timeout = 0; | ||
| SET idle_in_transaction_session_timeout = 0; | ||
| SET client_encoding = 'UTF8'; | ||
| SET standard_conforming_strings = on; | ||
| SELECT pg_catalog.set_config('search_path', '', false); | ||
| SET check_function_bodies = false; | ||
| SET xmloption = content; | ||
| SET client_min_messages = warning; | ||
| SET row_security = off; | ||
|
|
||
| SET default_tablespace = ''; | ||
|
|
||
| -- | ||
| -- Name: organizations; Type: TABLE; Schema: public; Owner: luke | ||
| -- | ||
|
|
||
| CREATE TABLE public.organizations ( | ||
| id integer NOT NULL, | ||
| name character varying NOT NULL, | ||
| created_at timestamp without time zone | ||
| ); | ||
|
|
||
|
|
||
| ALTER TABLE public.organizations OWNER TO luke; | ||
|
|
||
| -- | ||
| -- Name: organizations_id_seq; Type: SEQUENCE; Schema: public; Owner: luke | ||
| -- | ||
|
|
||
| CREATE SEQUENCE public.organizations_id_seq | ||
| AS integer | ||
| START WITH 1 | ||
| INCREMENT BY 1 | ||
| NO MINVALUE | ||
| NO MAXVALUE | ||
| CACHE 1; | ||
|
|
||
|
|
||
| ALTER TABLE public.organizations_id_seq OWNER TO luke; | ||
|
|
||
| -- | ||
| -- Name: organizations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: luke | ||
| -- | ||
|
|
||
| ALTER SEQUENCE public.organizations_id_seq OWNED BY public.organizations.id; | ||
|
|
||
|
|
||
| -- | ||
| -- Name: users; Type: TABLE; Schema: public; Owner: luke | ||
| -- | ||
|
|
||
| CREATE TABLE public.users ( | ||
| id integer NOT NULL, | ||
| name character varying NOT NULL, | ||
| org_id smallint NOT NULL, | ||
| created_at timestamp without time zone, | ||
| birthdate date | ||
| ); | ||
|
|
||
|
|
||
| ALTER TABLE public.users OWNER TO luke; | ||
|
|
||
| -- | ||
| -- Name: users_id_seq; Type: SEQUENCE; Schema: public; Owner: luke | ||
| -- | ||
|
|
||
| CREATE SEQUENCE public.users_id_seq | ||
| AS integer | ||
| START WITH 1 | ||
| INCREMENT BY 1 | ||
| NO MINVALUE | ||
| NO MAXVALUE | ||
| CACHE 1; | ||
|
|
||
|
|
||
| ALTER TABLE public.users_id_seq OWNER TO luke; | ||
|
|
||
| -- | ||
| -- Name: users_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: luke | ||
| -- | ||
|
|
||
| ALTER SEQUENCE public.users_id_seq OWNED BY public.users.id; | ||
|
|
||
|
|
||
| -- | ||
| -- Name: organizations id; Type: DEFAULT; Schema: public; Owner: luke | ||
| -- | ||
|
|
||
| ALTER TABLE ONLY public.organizations ALTER COLUMN id SET DEFAULT nextval('public.organizations_id_seq'::regclass); | ||
|
|
||
|
|
||
| -- | ||
| -- Name: users id; Type: DEFAULT; Schema: public; Owner: luke | ||
| -- | ||
|
|
||
| ALTER TABLE ONLY public.users ALTER COLUMN id SET DEFAULT nextval('public.users_id_seq'::regclass); | ||
|
|
||
|
|
||
| -- | ||
| -- Data for Name: organizations; Type: TABLE DATA; Schema: public; Owner: luke | ||
| -- | ||
|
|
||
| COPY public.organizations (id, name, created_at) FROM stdin; | ||
| 1 Test org 2023-02-04 16:27:51.797666 | ||
| 2 Test org 2 2023-02-04 16:27:55.293966 | ||
| \. | ||
|
|
||
|
|
||
| -- | ||
| -- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: luke | ||
| -- | ||
|
|
||
| COPY public.users (id, name, org_id, created_at, birthdate) FROM stdin; | ||
| 1 test user 1 1 2023-02-04 16:28:34.391467 1990-01-01 | ||
| 2 test user 2 1 2023-02-04 16:28:44.292242 1989-01-01 | ||
| 3 test user 3 2 2023-02-04 16:28:52.430384 1988-01-01 | ||
| \. | ||
|
|
||
|
|
||
| -- | ||
| -- Name: organizations_id_seq; Type: SEQUENCE SET; Schema: public; Owner: luke | ||
| -- | ||
|
|
||
| SELECT pg_catalog.setval('public.organizations_id_seq', 2, true); | ||
|
|
||
|
|
||
| -- | ||
| -- Name: users_id_seq; Type: SEQUENCE SET; Schema: public; Owner: luke | ||
| -- | ||
|
|
||
| SELECT pg_catalog.setval('public.users_id_seq', 3, true); | ||
|
|
||
|
|
||
| -- | ||
| -- Name: organizations organizations_pkey; Type: CONSTRAINT; Schema: public; Owner: luke | ||
| -- | ||
|
|
||
| ALTER TABLE ONLY public.organizations | ||
| ADD CONSTRAINT organizations_pkey PRIMARY KEY (id); | ||
|
|
||
|
|
||
| -- | ||
| -- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: luke | ||
| -- | ||
|
|
||
| ALTER TABLE ONLY public.users | ||
| ADD CONSTRAINT users_pkey PRIMARY KEY (id); | ||
|
|
||
|
|
||
| -- | ||
| -- Name: users_org_idx; Type: INDEX; Schema: public; Owner: luke | ||
| -- | ||
|
|
||
| CREATE INDEX users_org_idx ON public.users USING btree (org_id); | ||
|
|
||
|
|
||
| -- | ||
| -- Name: users fk_users_organizations; Type: FK CONSTRAINT; Schema: public; Owner: luke | ||
| -- | ||
|
|
||
| ALTER TABLE ONLY public.users | ||
| ADD CONSTRAINT fk_users_organizations FOREIGN KEY (org_id) REFERENCES public.organizations(id); | ||
|
|
||
|
|
||
| -- | ||
| -- PostgreSQL database dump complete | ||
| -- | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| users: { | ||
| name: "Jimbo" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,62 @@ | |
| expect(PgDumpAnonymize::VERSION).not_to be nil | ||
| end | ||
|
|
||
| it "does something useful" do | ||
| expect(false).to eq(true) | ||
| it "can process a file with no transformations, producing an exact copy" do | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. didn't put too much thought into these, definitely not suggesting they come close to exhausting the set of behaviour that would be good to test |
||
| def_file = "spec/fixtures/empty_def_file.rb" | ||
| dump_file = File.open("spec/fixtures/sample_dump.sql") | ||
| out_file = Tempfile.new('foo') | ||
|
|
||
| PgDumpAnonymize.anonymize(def_file, dump_file, out_file) | ||
|
|
||
| dump_file.rewind | ||
| out_file.rewind | ||
| expect(dump_file.read).to eql(out_file.read) | ||
| end | ||
|
|
||
| it "can process a file with a static transformation" do | ||
| def_file = "spec/fixtures/static_def.rb" | ||
| dump_file = File.open("spec/fixtures/sample_dump.sql") | ||
| out_file = Tempfile.new('foo') | ||
|
|
||
| PgDumpAnonymize.anonymize(def_file, dump_file, out_file) | ||
|
|
||
| out_file.rewind | ||
| expect(out_file.grep(/test user/i)).to eql([]) | ||
| out_file.rewind | ||
| expect(out_file.grep(/Jimbo/i).size).to eql(3) | ||
| end | ||
|
|
||
| it "can process a file with a dynamic transformation" do | ||
| def_file = "spec/fixtures/dynamic_definition.rb" | ||
| dump_file = File.open("spec/fixtures/sample_dump.sql") | ||
| out_file = Tempfile.new('foo') | ||
|
|
||
| PgDumpAnonymize.anonymize(def_file, dump_file, out_file) | ||
|
|
||
| out_file.rewind | ||
| expect(out_file.grep(/test user/i)).to eql([]) | ||
| out_file.rewind | ||
| matches = out_file.grep(/Jimbo/i) | ||
| line1, line2, line3 = matches | ||
|
|
||
| jimboA, jimboB, jimboC = matches.map do |line| | ||
| values = line.split("\t") | ||
| values[1] | ||
| end | ||
| expect(jimboA).not_to eql(jimboB) | ||
| expect(jimboA).not_to eql(jimboC) | ||
| expect(jimboB).not_to eql(jimboC) | ||
| end | ||
|
|
||
| it "treats def file table references to absent tables as a noop" do | ||
| def_file = "spec/fixtures/inapplicable_def_file.rb" | ||
| dump_file = File.open("spec/fixtures/sample_dump.sql") | ||
| out_file = Tempfile.new('foo') | ||
|
|
||
| PgDumpAnonymize.anonymize(def_file, dump_file, out_file) | ||
|
|
||
| dump_file.rewind | ||
| out_file.rewind | ||
| expect(dump_file.read).to eql(out_file.read) | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just demonstrating what a "dynamic" definition could look like, could use
fakerinstead if more realistic usage was desirable