Using PostgreSQL 9.4.3 on Debian Jessie 64.
question.sql :
\set client_min_messages = debug
BEGIN;
SELECT * from no_plan();
SELECT Dugong.Users_Add('Sarit','thisispassword','programmer');
SELECT is(Dugong.Users_isExist('Sarit'),'t', 'Test Question_isExist() should return true' );
PREPARE A AS SELECT Username, Password, Privilege FROM Dugong.Users;
SELECT results_eq('A',$$VALUES ('sarit','thisispassword','programmer') $$,'Test wtf');
SELECT results_eq('A',$$VALUES ('Sarit','thisispassword','programmer') $$,'Test wtf');
SELECT * FROM finish();
ROLLBACK;
Output:
postgres@jaikra:/home/sarit/4alls/anemonesfish/pgtap$ pg_prove -v -d skorplusdb question.sql
question.sql ..
Sarit
ok 1 - Test Question_isExist() should return true
not ok 2 - Test wtf
# Failed test 2: "Test wtf"
# Number of columns or their types differ between the queries:
# have: (Sarit,thisispassword,programmer)
# want: (sarit,thisispassword,programmer)
not ok 3 - Test wtf
# Failed test 3: "Test wtf"
# Number of columns or their types differ between the queries
1..3
# Looks like you failed 2 tests of 3
Failed 2/3 subtests
Test Summary Report
-------------------
question.sql (Wstat: 0 Tests: 3 Failed: 2)
Failed tests: 2-3
Files=1, Tests=3, 0 wallclock secs ( 0.02 usr 0.00 sys + 0.03 cusr 0.00 csys = 0.05 CPU)
Result: FAIL
Table:
CREATE TABLE Dugong.Users
( Username varchar(255),
Password varchar(255) NOT NULL,
Privilege varchar(255),
FirstName varchar(255),
MiddleName varchar(255),
LastName varchar(255),
StreetAddr varchar(255),
Subdistrict varchar(255),
District varchar(255),
Province varchar(255),
Country varchar(255),
Zipcode varchar(255),
Email varchar(255),
PhoneCountryCode varchar(10),
PhoneAreaCode varchar(255),
PhoneNum varchar(255),
FaxCountryCode varchar(255),
FaxAreaCode varchar(255),
FaxNum varchar(255),
LastModified timestamp with time zone default current_timestamp,
PRIMARY KEY(UserName)
);
Goal: To test my Users_Add function. Is it hold all the values I gave.
Expect: Table Users has 1 record with 3 values.
My attempt:
On 2nd error. It shows me 3 columns. That is a good response. Since I intentionaly make it wrong. So in the near future I will let it be a correct one.
However, 3rd error is strange. I copy and change 2nd case to be what I want, let it be uppercase on 'S'. Then prepared query has 3 columns and I check 3 values.
I have another overload function that INSERT INTO all 20 columns. Right now I want only 3. After got the error I go back to document.
Refer to document error, it says query and values have different column count. But it is not my case.
Problem:
My query has 3 columns and I let pgtap
check only 3 columns, but 3rd case raises that I am letting it check unequal columns size of record.
Any information about my installation please ask. I will provide them to you as fast as I can.
Probably the number of columns is not a problem, but rather their types. Try this:
SELECT results_eq('A',
$$VALUES (
'sarit'::varchar(255),
'thisispassword'::varchar(255),
'programmer'::varchar(255)) $$,
'Test wtf');
SELECT results_eq('A',
$$VALUES (
'Sarit'::varchar(255),
'thisispassword'::varchar(255),
'programmer'::varchar(255)) $$,
'Test wtf');
The problem stems from the fact that the default type for a string (like 'sarit'
) istext
. Generally, using varchar(n)
is rather inconvenient when compared to text
.
More on this topic can be found here: Any downsides of using data type "text" for storing strings? and PostgreSQL: Difference between text and varchar (character varying).