Term: fair-weather friend
Example: i had thought ted would stand by me when i was accused of theft, but it turned out he was only a fair-weather friend
Definition: a friend who is only a friend when circumstances are pleasant or profitable