I’m working on creating a custom n8n node for connecting to PostgreSQL database and I keep getting an error message saying there’s no testing function for my credentials.
I set up my credentials without putting the test logic directly in the credentials file because I want to handle the testing in my main node file instead. But when I try to test everything, it says it can’t find the test function.
Here’s how I configured my credentials in the node file:
credentials: [
{
name: 'postgresConnection',
required: true,
testedBy: 'validateConnection'
}
],
And I put the actual test function in my methods section:
methods = {
loadOptions: {
getDatabases
},
// credential testing function goes here:
credentialTest: {
validateConnection /** imported from external file */
}
};
The validateConnection function implements the proper ICredentialsTestFunction interface that expects this signature: (this: ICredentialTestFunctions, credential: ICredentialsDecrypted) => Promise<INodeCredentialTestResult>
I looked at how other database nodes like PostgreSQL and MongoDB handle this and my setup looks identical to theirs, but mine still doesn’t work. Any ideas what might be causing this issue?
Had this exact issue when building a custom Slack node. The problem was I was defining the credentialTest function wrong. Don’t import an external function - define the test function inline within the credentialTest object instead. Your methods section should look like this: javascript methods = { loadOptions: { getDatabases }, credentialTest: { validateConnection(this: ICredentialTestFunctions, credential: ICredentialsDecrypted): Promise<INodeCredentialTestResult> { // Put your PostgreSQL connection test logic here const { host, port, database, username, password } = credential.data; // Test connection and return result } } }; The function needs to be a method property, not a reference to an imported function. Also double-check your credentials file has the right name property that matches what you’re using in the testedBy field.
I hit this exact same issue building my first custom node. The problem’s probably how you’re structuring the credentialTest object. Don’t use the imported function directly - wrap it in an async function that matches n8n’s expected format. Change your methods section to: javascript methods = { loadOptions: { getDatabases }, credentialTest: { validateConnection: async function(this: ICredentialTestFunctions, credential: ICredentialsDecrypted): Promise<INodeCredentialTestResult> { // Your actual validation logic here return { status: 'OK', message: 'Connection successful' }; } } }; Also check that your node’s execute method is properly exported and the credentials schema matches what you’re referencing in the testedBy field. This error usually happens when there’s a mismatch between the credential definition and the actual test implementation.
double-check the validateConnection export from the external file. make sure the name in testedBy matches exactly in credentialTest—case sensitivity can mess things up.