How could the Buddha know that he had attained enlightenment when he didn't know what it was?
In the third watch of the night He had the knowledge of the exhaustion of cankers, knowing that He had eradicated all defilements and made an end of ill.


The Three Supreme Knowledges of Lord Buddha

So the Buddha knew he had overcome defilements and was enlightened due to knowledge of the exhaustion of cankers.

Also with the arising of knowledge of the exhaustion of cankers the Buddha knew what enlightenment was.