]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
added basic config test for consts, depend on knot >= 2.4, cleanup
authorMarek Vavruša <mvavrusa@cloudflare.com>
Thu, 23 Nov 2017 08:59:31 +0000 (00:59 -0800)
committerMarek Vavruša <mvavrusa@cloudflare.com>
Fri, 24 Nov 2017 07:33:25 +0000 (23:33 -0800)
The library now depends on libknot >= 2.4.0 (in Debian stable),
this allows us to remove a dead code and sed-ing of the kres.lua

Added a basic config tests to check that constants still work,
and basic interface to rrsets still works after the change.

Makefile
daemon/daemon.mk
daemon/lua/kres.lua [moved from daemon/lua/kres.lua.in with 90% similarity]
doc/build.rst
tests/config/basic/test.cfg [new file with mode: 0644]
tests/config/test_config.mk

index 58093eb87d65e74e92146d54abb3316488f0a25d..8d9644cae64b82e719ef6571c3d70700608cf353 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@ BUILD_CFLAGS += --coverage
 endif
 
 # Dependencies
-KNOT_MINVER := 2.3.1
+KNOT_MINVER := 2.4.0
 $(eval $(call find_lib,libknot,$(KNOT_MINVER),yes))
 $(eval $(call find_lib,libdnssec,$(KNOT_MINVER),yes))
 $(eval $(call find_lib,libzscanner,$(KNOT_MINVER),yes))
index 516cb40ee76f77655c5eb84b2214f4aaeb8f25fc..09717d22b7301c64007bc41ce7b74cffe80169af 100644 (file)
@@ -60,14 +60,9 @@ ifneq ($(SED),)
        $(INSTALL) -m 0644 doc/kresd.8 $(DESTDIR)$(MANDIR)/man8/
 endif
 daemon-clean: kresd-clean
-       @$(RM) daemon/lua/*.inc daemon/lua/kres.lua daemon/lua/trust_anchors.lua \
+       @$(RM) daemon/lua/*.inc daemon/lua/trust_anchors.lua \
                daemon/lua/zonefile.lua
 
-KNOT_RRSET_TXT_DUMP := \
-       $(shell pkg-config libknot --atleast-version=2.4.0 && echo true || echo false)
-daemon/lua/kres.lua: daemon/lua/kres.lua.in
-       @$(call quiet,SED,$<) -e "s|@KNOT_RRSET_TXT_DUMP@|$(KNOT_RRSET_TXT_DUMP)|g" $< > $@
-
 daemon/lua/trust_anchors.lua: daemon/lua/trust_anchors.lua.in
        @$(call quiet,SED,$<) -e "s|@ETCDIR@|$(ETCDIR)|g" $< > $@
 
similarity index 90%
rename from daemon/lua/kres.lua.in
rename to daemon/lua/kres.lua
index d45e9dc1f2f95f537ad4bbff94196d50981fa391..7ea3d1b3496006ccb98b0d1518183a41992af703 100644 (file)
@@ -175,37 +175,19 @@ ffi.metatype( knot_rrset_t, {
 
                -- Dump the rrset in presentation format (dig-like).
                txt_dump = function(rr, style)
-                       if @KNOT_RRSET_TXT_DUMP@ then
-                               local bufsize = 1024
-                               local dump = ffi.new('char *[1]', C.malloc(bufsize))
-                                       -- ^ one pointer to a string
-                               local size = ffi.new('size_t[1]', { bufsize }) -- one size_t = bufsize
+                       local bufsize = 1024
+                       local dump = ffi.new('char *[1]', C.malloc(bufsize))
+                               -- ^ one pointer to a string
+                       local size = ffi.new('size_t[1]', { bufsize }) -- one size_t = bufsize
 
-                               local ret = knot.knot_rrset_txt_dump(rr, dump, size,
-                                                               style or knot.KNOT_DUMP_STYLE_DEFAULT)
-                               local result = nil
-                               if ret >= 0 then
-                                       result = ffi.string(dump[0], ret)
-                               end
-                               C.free(dump[0])
-                               return result
-                       else
-                               -- different _txt_dump ABI -> use old "binary" method
-                               local function hex_encode(str)
-                                       return (str:gsub('.', function (c)
-                                               return string.format('%02X', string.byte(c))
-                                       end))
-                               end
-                               local result = ''
-                               local i
-                               for i = 0, rr.rrs.rr_count - 1 do
-                                       local rr1 = rr:get(i)
-                                       local rdata = hex_encode(rr1.rdata)
-                                       result = result .. string.format('%s %d IN TYPE%d \\# %d %s\n',
-                                               kres.dname2str(rr1.owner), rr1.ttl, rr1.type, #rr1.rdata, rdata)
-                               end
-                               return result
+                       local ret = knot.knot_rrset_txt_dump(rr, dump, size,
+                                                       style or knot.KNOT_DUMP_STYLE_DEFAULT)
+                       local result = nil
+                       if ret >= 0 then
+                               result = ffi.string(dump[0], ret)
                        end
+                       C.free(dump[0])
+                       return result
                end,
        },
 })
index e9dde53819af857b5c4a9ae4f858d93cf9eef363..d67766c4d38033e9edf7e1612a2b1526aeeda162 100644 (file)
@@ -39,7 +39,7 @@ The following is a list of software required to build Knot DNS Resolver from sou
    "C compiler", "*all*", "*(build only)* [#]_"
    "`pkg-config`_", "*all*", "*(build only)* [#]_"
    "hexdump or xxd", "``daemon``", "*(build only)*"
-   "libknot_ 2.3.1+", "*all*", "Knot DNS library (requires autotools, GnuTLS and Jansson)."
+   "libknot_ 2.4.0+", "*all*", "Knot DNS library (requires autotools, GnuTLS and Jansson)."
    "LuaJIT_ 2.0+", "``daemon``", "Embedded scripting language."
    "libuv_ 1.7+", "``daemon``", "Multiplatform I/O and services (libuv_ 1.0 with limitations [#]_)."
 
diff --git a/tests/config/basic/test.cfg b/tests/config/basic/test.cfg
new file mode 100644 (file)
index 0000000..19f21d1
--- /dev/null
@@ -0,0 +1,26 @@
+dofile('./test_utils.lua') -- load test utilities
+
+-- test if constants work properly
+function test_constants()
+       assert.same(1, kres.class.IN)
+       assert.same(1, kres.class['IN'])
+       assert.same(2, kres.type.NS)
+       assert.same(2, kres.type.TYPE2)
+       assert.same(nil, kres.type.BADTYPE)
+       assert.same(2, kres.rcode.SERVFAIL)
+end
+
+-- test if rrsets interfaces work
+function test_rrsets()
+       local rr = {owner = '\3com', ttl = 1, type = kres.type.TXT, rdata = '\5hello'}
+       local rr_text = tostring(kres.rr2str(rr))
+       assert.same('com. 1 TXT "hello"', rr_text:gsub('%s+', ' '))
+end
+
+-- run test after processed config file
+-- default config will be used and we can test it.
+event.after(0, function (ev) 
+       test(test_constants)
+       test(test_rrsets)
+       quit()
+end)
index 4f26dc982687785fe3896ea940419e0417876d50..8d9f1e03f29dddf43cf8a5145e17742ce100746c 100644 (file)
@@ -6,6 +6,7 @@
 # Check return code of kresd. Passed test have to call quit().
 
 tests_config := \
+       basic \
        hints \
        predict