github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/modules/dns-helper/errors.go (about) 1 package dns_helper 2 3 import "fmt" 4 5 // NoResolversError is an error that occurs if no resolvers have been set for DNSLookupE 6 type NoResolversError struct{} 7 8 func (err NoResolversError) Error() string { 9 return fmt.Sprintf("No resolvers set for DNSLookupE call") 10 } 11 12 // QueryTypeError is an error that occurs if the DNS query type is not supported 13 type QueryTypeError struct { 14 Type string 15 } 16 17 func (err QueryTypeError) Error() string { 18 return fmt.Sprintf("Wrong DNS query type: %s", err.Type) 19 } 20 21 // NotFoundError is an error that occurs if no answer found 22 type NotFoundError struct { 23 Query DNSQuery 24 Nameserver string 25 } 26 27 func (err NotFoundError) Error() string { 28 return fmt.Sprintf("No %s record found for %s querying nameserver %s", err.Query.Type, err.Query.Name, err.Nameserver) 29 } 30 31 // InconsistentAuthoritativeError is an error that occurs if an authoritative answer is different from another 32 type InconsistentAuthoritativeError struct { 33 Query DNSQuery 34 Answers DNSAnswers 35 Nameserver string 36 PreviousAnswers DNSAnswers 37 } 38 39 func (err InconsistentAuthoritativeError) Error() string { 40 return fmt.Sprintf("Inconsistent authoritative answer from %s to DNS query %s. Got: %s Previous: %s", err.Nameserver, err.Query, err.Answers, err.PreviousAnswers) 41 } 42 43 // NSNotFoundError is an error that occurs if no NS records found 44 type NSNotFoundError struct { 45 FQDN string 46 Nameserver string 47 } 48 49 func (err NSNotFoundError) Error() string { 50 return fmt.Sprintf("No NS record found for %s up to apex domain %s", err.FQDN, err.Nameserver) 51 } 52 53 // MaxRetriesExceeded is an error that occurs when the maximum amount of retries is exceeded. 54 type MaxRetriesExceeded struct { 55 Description string 56 MaxRetries int 57 } 58 59 func (err MaxRetriesExceeded) Error() string { 60 return fmt.Sprintf("'%s' unsuccessful after %d retries", err.Description, err.MaxRetries) 61 } 62 63 // ValidationError is an error that occurs when answers validation fails 64 type ValidationError struct { 65 Query DNSQuery 66 Answers DNSAnswers 67 ExpectedAnswers DNSAnswers 68 } 69 70 func (err ValidationError) Error() string { 71 return fmt.Sprintf("Unexpected answer to DNS query %s. Got: %s Expected: %s", err.Query, err.Answers, err.ExpectedAnswers) 72 }