Best Rr_ruby code snippet using RR.any
tc_update.rb
Source:tc_update.rb
1# --2# Copyright 2007 Nominet UK3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15# ++16require_relative 'spec_helper'17class TestUpdate < Minitest::Test18 include Dnsruby19 def is_empty(string)20 return true if string == nil || string.length == 021 return (string == "; no data" || string == "; rdlength = 0");22 end23 def test_update24 # ------------------------------------------------------------------------------25 # Canned data.26 # ------------------------------------------------------------------------------27 zone = "example.com";28 name = "foo.example.com";29 klass = Classes.CLASS32;30 klass2 = Classes.CH;31 type = Types.A;32 ttl = 43200;33 rdata = "10.1.2.3";34 rr = nil;35 # ------------------------------------------------------------------------------36 # Packet creation.37 # ------------------------------------------------------------------------------38 update = Dnsruby::Update.new(zone, klass);39 z = (update.zone)[0];40 assert(update, 'new() returned packet'); #241 assert_equal(update.header.opcode, OpCode.UPDATE, 'header opcode correct'); #342 assert_equal(z.zname.to_s, zone, 'zname correct'); #443 assert_equal(z.zclass.to_s, klass.to_s, 'zclass correct'); #544 assert_equal(z.ztype, Types.SOA, 'ztype correct'); #645 # ------------------------------------------------------------------------------46 # RRset exists (value-independent).47 # ------------------------------------------------------------------------------48 rr = update.present(name, type);49 assert(rr, 'yxrrset() returned RR'); #750 assert_equal(name, rr.name.to_s, 'yxrrset - right name'); #851 assert_equal(0, rr.ttl, 'yxrrset - right TTL'); #952 assert_equal('ANY', rr.klass.string, 'yxrrset - right class'); #1053 assert_equal(type, rr.type, 'yxrrset - right type'); #1154 assert(is_empty(rr.rdata), "yxrrset - data empty (#{rr.rdata})"); #1255 rr = nil56 # ------------------------------------------------------------------------------57 # RRset exists (value-dependent).58 # ------------------------------------------------------------------------------59 rr = update.present(name, type, rdata, klass);60 assert(rr, 'yxrrset() returned RR'); #1361 assert_equal(name, rr.name.to_s, 'yxrrset - right name'); #1462 assert_equal(0, rr.ttl, 'yxrrset - right TTL'); #1563 assert_equal(klass, rr.klass.string, 'yxrrset - right class'); #1664 assert_equal(type, rr.type, 'yxrrset - right type'); #1765 assert_equal(rdata, rr.rdata, 'yxrrset - right data'); #1866 rr=nil67 # ------------------------------------------------------------------------------68 # RRset does not exist.69 # ------------------------------------------------------------------------------70 rr = update.absent(name, type);71 assert(rr, 'nxrrset() returned RR'); #1972 assert_equal(name, rr.name.to_s, 'nxrrset - right name'); #2073 assert_equal(0, rr.ttl, 'nxrrset - right ttl'); #2174 assert_equal('NONE', rr.klass.string, 'nxrrset - right class'); #2275 assert_equal(type, rr.type, 'nxrrset - right type'); #2376 assert(is_empty(rr.rdata), 'nxrrset - data empty'); #2477 rr = nil78 # ------------------------------------------------------------------------------79 # Name is in use.80 # ------------------------------------------------------------------------------81 rr = update.present(name);82 assert(rr, 'yxdomain() returned RR'); #2583 assert_equal(rr.name.to_s, name, 'yxdomain - right name'); #2684 assert_equal(rr.ttl, 0, 'yxdomain - right ttl'); #2785 assert_equal(rr.klass.string, 'ANY', 'yxdomain - right class'); #2886 assert_equal(rr.type.string, 'ANY', 'yxdomain - right type'); #2987 assert(is_empty(rr.rdata), 'yxdomain - data empty'); #3088 rr = nil89 # ------------------------------------------------------------------------------90 # Name is not in use. (No Class)91 # ------------------------------------------------------------------------------92 rr = update.absent(name);93 assert(rr, 'nxdomain() returned RR'); #3194 assert_equal(rr.name.to_s, name, 'nxdomain - right name'); #3295 assert_equal(rr.ttl, 0, 'nxdomain - right ttl'); #3396 assert_equal(rr.klass.string, 'NONE', 'nxdomain - right class'); #3497 assert_equal(rr.type.string, 'ANY', 'nxdomain - right type'); #3598 assert(is_empty(rr.rdata), 'nxdomain - data empty'); #3699 rr = nil100 # ------------------------------------------------------------------------------101 # Add to an RRset.102 # ------------------------------------------------------------------------------103 rr = update.add(name, type, ttl, rdata);104 assert(rr, 'rr_add() returned RR'); #37105 assert_equal(rr.name.to_s, name, 'rr_add - right name'); #38106 assert_equal(rr.ttl, ttl, 'rr_add - right ttl'); #39107 assert_equal(rr.klass, klass, 'rr_add - right class'); #40108 assert_equal(rr.type, type, 'rr_add - right type'); #41109 assert_equal(rr.rdata, rdata, 'rr_add - right data'); #42110 rr = nil111 # ------------------------------------------------------------------------------112 # Delete an RRset.113 # ------------------------------------------------------------------------------114 rr = update.delete(name, type);115 assert(rr, 'rr_del() returned RR'); #43116 assert_equal(name, rr.name.to_s, 'rr_del - right name'); #44117 assert_equal(0, rr.ttl, 'rr_del - right ttl'); #45118 assert_equal('ANY', rr.klass.string, 'rr_del - right class'); #46119 assert_equal(type, rr.type, 'rr_del - right type'); #47120 assert(is_empty(rr.rdata), 'rr_del - data empty'); #48121 rr = nil122 # ------------------------------------------------------------------------------123 # Delete All RRsets From A Name.124 # ------------------------------------------------------------------------------125 rr = update.delete(name);126 assert(rr, 'rr_del() returned RR'); #49127 assert_equal(name, rr.name.to_s, 'rr_del - right name'); #50128 assert_equal(0, rr.ttl, 'rr_del - right ttl'); #51129 assert_equal(Classes.ANY, rr.klass, 'rr_del - right class'); #52130 assert_equal(Classes.ANY, rr.type, 'rr_del - right type'); #53131 assert(is_empty(rr.rdata), 'rr_del - data empty'); #54132 rr = nil133 # ------------------------------------------------------------------------------134 # Delete An RR From An RRset.135 # ------------------------------------------------------------------------------136 rr = update.delete(name, type, rdata);137 assert(rr, 'rr_del() returned RR'); #55138 assert_equal(name, rr.name.to_s, 'rr_del - right name'); #56139 assert_equal(0, rr.ttl, 'rr_del - right ttl'); #57140 assert_equal('NONE', rr.klass.string, 'rr_del - right class'); #58141 assert_equal(type, rr.type, 'rr_del - right type'); #59142 assert_equal(rdata, rr.rdata, 'rr_del - right data'); #60143 rr = nil144 data = update.encode145 header = Header.new_from_data(data)146 assert(header.opcode == OpCode.Update)147 new_update = Message.decode(data)148 assert(new_update.header.opcode == OpCode.Update)149 # ------------------------------------------------------------------------------150 # Make sure RRs in an update packet have the same class as the zone, unless151 # the class is NONE or ANY.152 # ------------------------------------------------------------------------------153 update = Dnsruby::Update.new(zone, klass);154 assert(update, 'packet created'); #61155 update.present(name, type, rdata);156 update.present(name, type, rdata);157 update.present(name, type);158 update.absent(name, type);159 pre = update.pre;160 assert_equal(3, pre.size, 'pushed inserted correctly'); #62161 assert_equal(klass, pre[0].klass.string, 'first class right'); #63162 assert_equal(Classes.ANY, pre[1].klass, 'third class right'); #65163 assert_equal(Classes.NONE, pre[2].klass, 'forth class right'); #66164 end165 def test_absent_cname166 update = Update.new()167 rr = update.absent("target_name", "CNAME")168 assert(rr, 'nxdomain() returned RR');169 assert_equal(rr.name.to_s, "target_name", 'nxdomain - right name');170 assert_equal(rr.ttl, 0, 'nxdomain - right ttl');171 assert_equal(rr.klass.string, 'NONE', 'nxdomain - right class');172 assert_equal(rr.type.string, 'CNAME', 'nxdomain - right type');173 assert(is_empty(rr.rdata), 'nxdomain - data empty');174 encoded_msg = Message.decode(update.encode)175 rr = encoded_msg.answer.first176 assert(rr, 'nxdomain() returned RR')177 assert_equal(rr.name.to_s, "target_name", 'nxdomain - right name')178 assert_equal(rr.ttl, 0, 'nxdomain - right ttl')179 assert_equal(rr.klass.string, 'NONE', 'nxdomain - right class')180 assert_equal(rr.type.string, 'CNAME', 'nxdomain - right type')181 # assert_nil(rr.rdata, 'nxdomain - data empty')182 assert(is_empty(rr.rdata), 'nxdomain - data empty')183 end184 def test_delete_specific_cname185 update = Update.new 'example.com'186 update.delete 'test.example.com', 'CNAME', 'target.example.com'187 encoded_msg = Message.decode update.encode188 rr = encoded_msg.authority.first189 assert_equal rr.name.to_s, 'test.example.com', 'delete_cname - right name'190 assert_equal 0, rr.ttl, 'delete_cname - right ttl'191 assert_equal 'NONE', rr.klass.string, 'delete_cname - right class'192 assert_equal 'CNAME', rr.type.string, 'delete_cname - right type'193 assert_equal 'target.example.com', rr.rdata.to_s, 'delete_cname - right target'194 end195 def test_delete_cname196 update = Update.new 'example.com'197 update.delete 'test.example.com', 'CNAME'198 encoded_msg = Message.decode update.encode199 rr = encoded_msg.authority.first200 assert_equal rr.name.to_s, 'test.example.com', 'delete_cname - right name'201 assert_equal 0, rr.ttl, 'delete_cname - right ttl'202 assert_equal 'ANY', rr.klass.string, 'delete_cname - right class'203 assert_equal 'CNAME', rr.type.string, 'delete_cname - right type'204 assert(is_empty(rr.rdata), 'delete_cname - right rdata')205 end206 def test_txt207 update = Update.new()208 update.add("target_name", "TXT", 100, "test signed update")209 assert(update.to_s.index("test signed update"))210 end211 def test_delete_txt212 update = Update.new 'example.com'213 update.delete 'test.example.com', 'TXT', 'foo bar'214 encoded_msg = Message.decode update.encode215 rr = encoded_msg.authority.first216 assert_equal rr.name.to_s, 'test.example.com', 'delete_txt - right name'217 assert_equal 0, rr.ttl, 'delete_txt - right ttl'218 assert_equal 'TXT', rr.type.string, 'delete_txt - right type'219 assert_equal ['foo bar'], rr.rdata, 'delete_txt - right rdata'220 end221 def test_array222 update = Update.new223 update.add("target_name", "TXT", 100, ['"test signed update"', 'item#2'])224 assert(update.to_s.index("item"))225 end226end...
any
Using AI Code Generation
1require File.dirname(__FILE__) + '/../config/environment'2require File.dirname(__FILE__) + '/../config/environment'3require File.dirname(__FILE__) + '/../config/environment'4require File.dirname(__FILE__) + '/../config/environment'5require File.dirname(__FILE__) + '/../config/environment'
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!