Beispiel #1
0
void
test_build_http_headers_empty_user_error(void **state) {

	/* setup mock data and expectations */
	PxfInputData *input = (PxfInputData *) palloc0(sizeof(PxfInputData));
	CHURL_HEADERS headers = (CHURL_HEADERS) palloc0(sizeof(CHURL_HEADERS));
	GPHDUri *gphd_uri = (GPHDUri *) palloc0(sizeof(GPHDUri));
	Relation rel = (Relation) palloc0(sizeof(RelationData));

	ExtTableEntry ext_tbl;
	struct tupleDesc tuple;

	input->headers = headers;
	input->gphduri = gphd_uri;
	input->rel = NULL;

	gphd_uri->uri = "testuri";

	expect_any(external_set_env_vars, extvar);
	expect_string(external_set_env_vars, uri, gphd_uri->uri);
	expect_value(external_set_env_vars, csv, false);
	expect_value(external_set_env_vars, escape, NULL);
	expect_value(external_set_env_vars, quote, NULL);
	expect_value(external_set_env_vars, header, false);
	expect_value(external_set_env_vars, scancounter, 0);

	struct extvar_t mock_extvar;
	mock_extvar.GP_USER = "";
	snprintf(mock_extvar.GP_SEGMENT_ID, sizeof(mock_extvar.GP_SEGMENT_ID), "SegId");
	snprintf(mock_extvar.GP_SEGMENT_COUNT, sizeof(mock_extvar.GP_SEGMENT_COUNT), "10");
	snprintf(mock_extvar.GP_XID, sizeof(mock_extvar.GP_XID), "20");
	will_assign_memory(external_set_env_vars, extvar, &mock_extvar, sizeof(extvar_t));
	will_be_called(external_set_env_vars);

	MemoryContext old_context = CurrentMemoryContext;
	PG_TRY();
	{
		build_http_headers(input);
		assert_false("Expected Exception");
	}
	PG_CATCH();
	{
		MemoryContextSwitchTo(old_context);
		ErrorData  *edata = CopyErrorData();

		assert_true(edata->elevel == ERROR);
		char	   *expected_message = pstrdup("User identity is unknown");

		assert_string_equal(edata->message, expected_message);
		pfree(expected_message);
	}
	PG_END_TRY();
}
void expect_external_vars()
{
	expect_any(external_set_env_vars, extvar);
	expect_string(external_set_env_vars, uri, gphd_uri->uri);
	expect_value(external_set_env_vars, csv, false);
	expect_value(external_set_env_vars, escape, NULL);
	expect_value(external_set_env_vars, quote, NULL);
	expect_value(external_set_env_vars, header, false);
	expect_value(external_set_env_vars, scancounter, 0);
	will_assign_memory(external_set_env_vars, extvar, mock_extvar, sizeof(extvar_t));
	will_be_called(external_set_env_vars);
}
Beispiel #3
0
void
test_build_http_headers(void **state)
{

	/* setup mock data and expectations */
	PxfInputData *input = (PxfInputData *) palloc0(sizeof(PxfInputData));
	CHURL_HEADERS headers = (CHURL_HEADERS) palloc0(sizeof(CHURL_HEADERS));
	GPHDUri    *gphd_uri = (GPHDUri *) palloc0(sizeof(GPHDUri));
	Relation	rel = (Relation) palloc0(sizeof(RelationData));

	ExtTableEntry ext_tbl;
	struct tupleDesc tuple;

	input->headers = headers;
	input->gphduri = gphd_uri;
	input->rel = rel;

	gphd_uri->host = "testhost";
	gphd_uri->port = "101";
	gphd_uri->data = "this is test data";
	gphd_uri->uri = "testuri";

	OptionData *option_data1 = (OptionData *) palloc0(sizeof(OptionData));

	option_data1->key = "option1-key";
	option_data1->value = "option1-value";
	OptionData *option_data2 = (OptionData *) palloc0(sizeof(OptionData));

	option_data2->key = "option2-key";
	option_data2->value = "option2-value";
	gphd_uri->options = list_make2(option_data1, option_data2);

	tuple.natts = 0;
	ext_tbl.fmtcode = 'c';
	rel->rd_id = 56;
	rel->rd_att = &tuple;

	expect_value(GetExtTableEntry, relid, rel->rd_id);
	will_return(GetExtTableEntry, &ext_tbl);
	expect_headers_append(headers, "X-GP-FORMAT", TextFormatName);
	expect_headers_append(headers, "X-GP-ATTRS", "0");

	expect_any(external_set_env_vars, extvar);
	expect_string(external_set_env_vars, uri, gphd_uri->uri);
	expect_value(external_set_env_vars, csv, false);
	expect_value(external_set_env_vars, escape, NULL);
	expect_value(external_set_env_vars, quote, NULL);
	expect_value(external_set_env_vars, header, false);
	expect_value(external_set_env_vars, scancounter, 0);

	struct extvar_t mock_extvar;
	mock_extvar.GP_USER = "******";
	snprintf(mock_extvar.GP_SEGMENT_ID, sizeof(mock_extvar.GP_SEGMENT_ID), "SegId");
	snprintf(mock_extvar.GP_SEGMENT_COUNT, sizeof(mock_extvar.GP_SEGMENT_COUNT), "10");
	snprintf(mock_extvar.GP_XID, sizeof(mock_extvar.GP_XID), "20");
	will_assign_memory(external_set_env_vars, extvar, &mock_extvar, sizeof(extvar_t));
	will_be_called(external_set_env_vars);

	expect_headers_append(headers, "X-GP-USER", "user");
	expect_headers_append(headers, "X-GP-SEGMENT-ID", "SegId");
	expect_headers_append(headers, "X-GP-SEGMENT-COUNT", "10");
	expect_headers_append(headers, "X-GP-XID", "20");

	char		alignment[3];

	pg_ltoa(sizeof(char *), alignment);
	expect_headers_append(headers, "X-GP-ALIGNMENT", alignment);
	expect_headers_append(headers, "X-GP-URL-HOST", gphd_uri->host);
	expect_headers_append(headers, "X-GP-URL-PORT", gphd_uri->port);
	expect_headers_append(headers, "X-GP-DATA-DIR", gphd_uri->data);


	expect_string(normalize_key_name, key, "option1-key");
	will_return(normalize_key_name, pstrdup("X-GP-OPTION1-KEY"));
	expect_headers_append(headers, "X-GP-OPTION1-KEY", "option1-value");

	expect_string(normalize_key_name, key, "option2-key");
	will_return(normalize_key_name, pstrdup("X-GP-OPTION2-KEY"));
	expect_headers_append(headers, "X-GP-OPTION2-KEY", "option2-value");

	expect_headers_append(headers, "X-GP-URI", gphd_uri->uri);
	expect_headers_append(headers, "X-GP-HAS-FILTER", "0");

	/* call function under test */
	build_http_headers(input);

	/* no asserts as the function just calls to set headers */

	/* cleanup */
	pfree(rel);
	pfree(gphd_uri);
	pfree(headers);
	pfree(input);
}