mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-29 01:04:15 -04:00 
			
		
		
		
	* For caddy v1 in our org This RP changes all imports for caddyserver/caddy to coredns/caddy. This is the v1 code of caddy. For the coredns/caddy repo the following changes have been made: * anything not needed by us is deleted * all `telemetry` stuff is deleted * all its import paths are also changed to point to coredns/caddy * the v1 branch has been moved to the master branch * a v1.1.0 tag has been added to signal the latest release Signed-off-by: Miek Gieben <miek@miek.nl> * Fix imports Signed-off-by: Miek Gieben <miek@miek.nl> * Group coredns/caddy with out plugins Signed-off-by: Miek Gieben <miek@miek.nl> * remove this file Signed-off-by: Miek Gieben <miek@miek.nl> * Relax import ordering github.com/coredns is now also a coredns dep, this makes github.com/coredns/caddy fit more natural in the list. Signed-off-by: Miek Gieben <miek@miek.nl> * Fix final import Signed-off-by: Miek Gieben <miek@miek.nl>
		
			
				
	
	
		
			104 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			104 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package erratic
 | |
| 
 | |
| import (
 | |
| 	"testing"
 | |
| 
 | |
| 	"github.com/coredns/caddy"
 | |
| )
 | |
| 
 | |
| func TestSetup(t *testing.T) {
 | |
| 	c := caddy.NewTestController("dns", `erratic {
 | |
| 		drop
 | |
| 	}`)
 | |
| 	if err := setup(c); err != nil {
 | |
| 		t.Fatalf("Test 1, expected no errors, but got: %q", err)
 | |
| 	}
 | |
| 
 | |
| 	c = caddy.NewTestController("dns", `erratic`)
 | |
| 	if err := setup(c); err != nil {
 | |
| 		t.Fatalf("Test 2, expected no errors, but got: %q", err)
 | |
| 	}
 | |
| 
 | |
| 	c = caddy.NewTestController("dns", `erratic {
 | |
| 		drop -1
 | |
| 	}`)
 | |
| 	if err := setup(c); err == nil {
 | |
| 		t.Fatalf("Test 4, expected errors, but got: %q", err)
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func TestParseErratic(t *testing.T) {
 | |
| 	tests := []struct {
 | |
| 		input     string
 | |
| 		shouldErr bool
 | |
| 		drop      uint64
 | |
| 		delay     uint64
 | |
| 		truncate  uint64
 | |
| 	}{
 | |
| 		// oks
 | |
| 		{`erratic`, false, 2, 0, 0},
 | |
| 		{`erratic {
 | |
| 			drop 2
 | |
| 			delay 3 1ms
 | |
| 
 | |
| 		}`, false, 2, 3, 0},
 | |
| 		{`erratic {
 | |
| 			truncate 2
 | |
| 			delay 3 1ms
 | |
| 
 | |
| 		}`, false, 0, 3, 2},
 | |
| 		{`erraric {
 | |
| 			drop 3
 | |
| 			delay
 | |
| 		}`, false, 3, 2, 0},
 | |
| 		// fails
 | |
| 		{`erratic {
 | |
| 			drop -1
 | |
| 		}`, true, 0, 0, 0},
 | |
| 		{`erratic {
 | |
| 			delay -1
 | |
| 		}`, true, 0, 0, 0},
 | |
| 		{`erratic {
 | |
| 			delay 1 2 4
 | |
| 		}`, true, 0, 0, 0},
 | |
| 		{`erratic {
 | |
| 			delay 15.a
 | |
| 		}`, true, 0, 0, 0},
 | |
| 		{`erraric {
 | |
| 			drop 3
 | |
| 			delay 3 bla
 | |
| 		}`, true, 0, 0, 0},
 | |
| 		{`erraric {
 | |
| 			truncate 15.a
 | |
| 		}`, true, 0, 0, 0},
 | |
| 		{`erraric {
 | |
| 			something-else
 | |
| 		}`, true, 0, 0, 0},
 | |
| 	}
 | |
| 	for i, test := range tests {
 | |
| 		c := caddy.NewTestController("dns", test.input)
 | |
| 		e, err := parseErratic(c)
 | |
| 		if test.shouldErr && err == nil {
 | |
| 			t.Errorf("Test %v: Expected error but found nil", i)
 | |
| 			continue
 | |
| 		} else if !test.shouldErr && err != nil {
 | |
| 			t.Errorf("Test %v: Expected no error but found error: %v", i, err)
 | |
| 			continue
 | |
| 		}
 | |
| 
 | |
| 		if test.shouldErr {
 | |
| 			continue
 | |
| 		}
 | |
| 
 | |
| 		if test.delay != e.delay {
 | |
| 			t.Errorf("Test %v: Expected delay %d but found: %d", i, test.delay, e.delay)
 | |
| 		}
 | |
| 		if test.drop != e.drop {
 | |
| 			t.Errorf("Test %v: Expected drop %d but found: %d", i, test.drop, e.drop)
 | |
| 		}
 | |
| 		if test.truncate != e.truncate {
 | |
| 			t.Errorf("Test %v: Expected truncate %d but found: %d", i, test.truncate, e.truncate)
 | |
| 		}
 | |
| 	}
 | |
| }
 |