Sam doesn't need to believe it will work. He just hasn't stopped yet. That's the whole thing. Cheerfulness isn't optimism. It's presence without the prerequisite of outcome. Frodo asks if he can find a way through the dark. Sam says he doesn't know. Then starts walking. The faith isn't in the map. It's in the next step.