github.com/phuslu/fastdns@v0.8.3-0.20240310041952-69506fc67dd1/types_test.go (about)

     1  package fastdns
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestRcode(t *testing.T) {
     8  	var cases = []struct {
     9  		Rcode  Rcode
    10  		String string
    11  	}{
    12  		{RcodeNoError, "NoError"},
    13  		{RcodeFormErr, "FormErr"},
    14  		{RcodeServFail, "ServFail"},
    15  		{RcodeNXDomain, "NXDomain"},
    16  		{RcodeNotImp, "NotImp"},
    17  		{RcodeRefused, "Refused"},
    18  		{RcodeYXDomain, "YXDomain"},
    19  		{RcodeYXRRSet, "YXRRSet"},
    20  		{RcodeNXRRSet, "NXRRSet"},
    21  		{RcodeNotAuth, "NotAuth"},
    22  		{RcodeNotZone, "NotZone"},
    23  		{RcodeBADSIG, "BadSig/BadVers"},
    24  		{RcodeBADVERS, "BadSig/BadVers"},
    25  		{RcodeBADKEY, "BadKey"},
    26  		{RcodeBADTIME, "BadTime"},
    27  		{RcodeBADMODE, "BadMode"},
    28  		{RcodeBADNAME, "BadName"},
    29  		{RcodeBADALG, "BadAlg"},
    30  		{RcodeBADTRUNC, "BadTrunc"},
    31  		{RcodeBADCOOKIE, "BadCookie"},
    32  		{Rcode(253), ""},
    33  	}
    34  
    35  	for _, c := range cases {
    36  		if got, want := c.Rcode.String(), c.String; got != want {
    37  			t.Errorf("Rcode.String(%v) error got=%s want=%s", c.Rcode, got, want)
    38  		}
    39  	}
    40  }
    41  
    42  func TestOpcode(t *testing.T) {
    43  	var cases = []struct {
    44  		Opcode Opcode
    45  		String string
    46  	}{
    47  		{OpcodeQuery, "Query"},
    48  		{OpcodeIQuery, "IQuery"},
    49  		{OpcodeStatus, "Status"},
    50  		{OpcodeNotify, "Notify"},
    51  		{OpcodeUpdate, "Update"},
    52  		{Opcode(255), ""},
    53  	}
    54  
    55  	for _, c := range cases {
    56  		if got, want := c.Opcode.String(), c.String; got != want {
    57  			t.Errorf("Opcode.String(%v) error got=%s want=%s", c.Opcode, got, want)
    58  		}
    59  	}
    60  }
    61  
    62  func TestClass(t *testing.T) {
    63  	var cases = []struct {
    64  		Class  Class
    65  		String string
    66  	}{
    67  		{ClassINET, "IN"},
    68  		{ClassCSNET, "CS"},
    69  		{ClassCHAOS, "CH"},
    70  		{ClassHESIOD, "HS"},
    71  		{ClassNONE, "NONE"},
    72  		{ClassANY, "ANY"},
    73  		{Class(253), ""},
    74  	}
    75  
    76  	for _, c := range cases {
    77  		if got, want := c.Class.String(), c.String; got != want {
    78  			t.Errorf("Class.String(%v) error got=%s want=%s", c.Class, got, want)
    79  		}
    80  	}
    81  }
    82  
    83  func TestType(t *testing.T) {
    84  	var cases = []struct {
    85  		Type   Type
    86  		String string
    87  	}{
    88  		{TypeNone, "None"},
    89  		{TypeA, "A"},
    90  		{TypeNS, "NS"},
    91  		{TypeMD, "MD"},
    92  		{TypeMF, "MF"},
    93  		{TypeCNAME, "CNAME"},
    94  		{TypeSOA, "SOA"},
    95  		{TypeMB, "MB"},
    96  		{TypeMG, "MG"},
    97  		{TypeMR, "MR"},
    98  		{TypeNULL, "NULL"},
    99  		{TypePTR, "PTR"},
   100  		{TypeHINFO, "HINFO"},
   101  		{TypeMINFO, "MINFO"},
   102  		{TypeMX, "MX"},
   103  		{TypeTXT, "TXT"},
   104  		{TypeRP, "RP"},
   105  		{TypeAFSDB, "AFSDB"},
   106  		{TypeX25, "X25"},
   107  		{TypeISDN, "ISDN"},
   108  		{TypeRT, "RT"},
   109  		{TypeNSAPPTR, "NSAPPTR"},
   110  		{TypeSIG, "SIG"},
   111  		{TypeKEY, "KEY"},
   112  		{TypePX, "PX"},
   113  		{TypeGPOS, "GPOS"},
   114  		{TypeAAAA, "AAAA"},
   115  		{TypeLOC, "LOC"},
   116  		{TypeNXT, "NXT"},
   117  		{TypeEID, "EID"},
   118  		{TypeNIMLOC, "NIMLOC"},
   119  		{TypeSRV, "SRV"},
   120  		{TypeATMA, "ATMA"},
   121  		{TypeNAPTR, "NAPTR"},
   122  		{TypeKX, "KX"},
   123  		{TypeCERT, "CERT"},
   124  		{TypeDNAME, "DNAME"},
   125  		{TypeOPT, "OPT"},
   126  		{TypeAPL, "APL"},
   127  		{TypeDS, "DS"},
   128  		{TypeSSHFP, "SSHFP"},
   129  		{TypeRRSIG, "RRSIG"},
   130  		{TypeNSEC, "NSEC"},
   131  		{TypeDNSKEY, "DNSKEY"},
   132  		{TypeDHCID, "DHCID"},
   133  		{TypeNSEC3, "NSEC3"},
   134  		{TypeNSEC3PARAM, "NSEC3PARAM"},
   135  		{TypeTLSA, "TLSA"},
   136  		{TypeSMIMEA, "SMIMEA"},
   137  		{TypeHIP, "HIP"},
   138  		{TypeNINFO, "NINFO"},
   139  		{TypeRKEY, "RKEY"},
   140  		{TypeTALINK, "TALINK"},
   141  		{TypeCDS, "CDS"},
   142  		{TypeCDNSKEY, "CDNSKEY"},
   143  		{TypeOPENPGPKEY, "OPENPGPKEY"},
   144  		{TypeCSYNC, "CSYNC"},
   145  		{TypeZONEMD, "ZONEMD"},
   146  		{TypeSVCB, "SVCB"},
   147  		{TypeHTTPS, "HTTPS"},
   148  		{TypeSPF, "SPF"},
   149  		{TypeUINFO, "UINFO"},
   150  		{TypeUID, "UID"},
   151  		{TypeGID, "GID"},
   152  		{TypeUNSPEC, "UNSPEC"},
   153  		{TypeNID, "NID"},
   154  		{TypeL32, "L32"},
   155  		{TypeL64, "L64"},
   156  		{TypeLP, "LP"},
   157  		{TypeEUI48, "EUI48"},
   158  		{TypeEUI64, "EUI64"},
   159  		{TypeURI, "URI"},
   160  		{TypeCAA, "CAA"},
   161  		{TypeAVC, "AVC"},
   162  		{TypeTKEY, "TKEY"},
   163  		{TypeTSIG, "TSIG"},
   164  		{TypeIXFR, "IXFR"},
   165  		{TypeAXFR, "AXFR"},
   166  		{TypeMAILB, "MAILB"},
   167  		{TypeMAILA, "MAILA"},
   168  		{TypeANY, "ANY"},
   169  		{TypeTA, "TA"},
   170  		{TypeDLV, "DLV"},
   171  		{TypeReserved, "Reserved"},
   172  		{Type(65534), ""},
   173  	}
   174  
   175  	for _, c := range cases {
   176  		if got, want := c.Type.String(), c.String; got != want {
   177  			t.Errorf("Type.String(%v) error got=%s want=%s", c.Type, got, want)
   178  		}
   179  	}
   180  }