Feature: API selftest

Initial work for https://cfengine.com/dev/issues/3469