1package dns 2 3import "testing" 4 5func TestOPTTtl(t *testing.T) { 6 e := &OPT{} 7 e.Hdr.Name = "." 8 e.Hdr.Rrtype = TypeOPT 9 10 // verify the default setting of DO=0 11 if e.Do() { 12 t.Errorf("DO bit should be zero") 13 } 14 15 // There are 6 possible invocations of SetDo(): 16 // 17 // 1. Starting with DO=0, using SetDo() 18 // 2. Starting with DO=0, using SetDo(true) 19 // 3. Starting with DO=0, using SetDo(false) 20 // 4. Starting with DO=1, using SetDo() 21 // 5. Starting with DO=1, using SetDo(true) 22 // 6. Starting with DO=1, using SetDo(false) 23 24 // verify that invoking SetDo() sets DO=1 (TEST #1) 25 e.SetDo() 26 if !e.Do() { 27 t.Errorf("DO bit should be non-zero") 28 } 29 // verify that using SetDo(true) works when DO=1 (TEST #5) 30 e.SetDo(true) 31 if !e.Do() { 32 t.Errorf("DO bit should still be non-zero") 33 } 34 // verify that we can use SetDo(false) to set DO=0 (TEST #6) 35 e.SetDo(false) 36 if e.Do() { 37 t.Errorf("DO bit should be zero") 38 } 39 // verify that if we call SetDo(false) when DO=0 that it is unchanged (TEST #3) 40 e.SetDo(false) 41 if e.Do() { 42 t.Errorf("DO bit should still be zero") 43 } 44 // verify that using SetDo(true) works for DO=0 (TEST #2) 45 e.SetDo(true) 46 if !e.Do() { 47 t.Errorf("DO bit should be non-zero") 48 } 49 // verify that using SetDo() works for DO=1 (TEST #4) 50 e.SetDo() 51 if !e.Do() { 52 t.Errorf("DO bit should be non-zero") 53 } 54 55 if e.Version() != 0 { 56 t.Errorf("version should be non-zero") 57 } 58 59 e.SetVersion(42) 60 if e.Version() != 42 { 61 t.Errorf("set 42, expected %d, got %d", 42, e.Version()) 62 } 63 64 e.SetExtendedRcode(42) 65 if e.ExtendedRcode() != 42 { 66 t.Errorf("set 42, expected %d, got %d", 42, e.ExtendedRcode()) 67 } 68} 69