#!/bin/sh

set -e

cd $AUTOPKGTEST_TMP

cat <<EOF > main.c
#include <tachi/cloudflare-ddns.h>
#include <assert.h>

int main(void) {
	int error;

	char local_ip[TACHI_IP_ADDRESS_MAX_LENGTH];
	error = tachi_get_local_ip(sizeof local_ip, local_ip);

	assert(error == 0);

	char record_ip[TACHI_IP_ADDRESS_MAX_LENGTH];
	char record_id[TACHI_RECORD_ID_LENGTH + 1];
	error = tachi_get_record(
		"test_api_token",
		"test_zone_id",
		"test_record_name",
		sizeof record_ip, record_ip,
		sizeof record_id, record_id
	);

	assert(error == 0);

	error = tachi_update_record(
		"test_api_token",
		"test_zone_id",
		"record_id",
		local_ip,
		sizeof record_ip, record_ip
	);

	assert(error == 0);

	return 0;
}
EOF

cc main.c -Wall -Wextra -Wpedantic -Werror $(pkg-config --cflags --libs cloudflare-ddns)
