github.com/amanya/packer@v0.12.1-0.20161117214323-902ac5ab2eb6/common/http_config_test.go (about) 1 package common 2 3 import ( 4 "testing" 5 ) 6 7 func TestHTTPConfigPrepare_Bounds(t *testing.T) { 8 // Test bad 9 h := HTTPConfig{ 10 HTTPPortMin: 1000, 11 HTTPPortMax: 500, 12 } 13 err := h.Prepare(nil) 14 if err == nil { 15 t.Fatal("should have error") 16 } 17 18 // Test good 19 h = HTTPConfig{ 20 HTTPPortMin: 0, 21 HTTPPortMax: 0, 22 } 23 err = h.Prepare(nil) 24 if err != nil { 25 t.Fatalf("should not have error: %s", err) 26 } 27 portMin := uint(8000) 28 if h.HTTPPortMin != portMin { 29 t.Fatalf("HTTPPortMin: expected %d got %d", portMin, h.HTTPPortMin) 30 } 31 portMax := uint(9000) 32 if h.HTTPPortMax != portMax { 33 t.Fatalf("HTTPPortMax: expected %d got %d", portMax, h.HTTPPortMax) 34 } 35 36 // Test good 37 h = HTTPConfig{ 38 HTTPPortMin: 500, 39 HTTPPortMax: 1000, 40 } 41 err = h.Prepare(nil) 42 if err != nil { 43 t.Fatalf("should not have error: %s", err) 44 } 45 }