Example #1
0
func TestIPRangeOverlap(t *testing.T) {
	ipr1, err := ParseIPRange("192.168.1.1-100")
	tt.TestExpectSuccess(t, err)
	ipr2, err := ParseIPRange("192.168.1.101-200")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, ipr1.Overlaps(ipr2), false)

	ipr2, err = ParseIPRange("192.168.1.100-200")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, ipr1.Overlaps(ipr2), true)

	ipr2, err = ParseIPRange("192.168.1.50-55")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, ipr1.Overlaps(ipr2), true)

	ipr2, err = ParseIPRange("192.168.1.1")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, ipr1.Overlaps(ipr2), true)

	ipr1, err = ParseIPRange("192.168.1.200-210")
	tt.TestExpectSuccess(t, err)
	ipr2, err = ParseIPRange("192.168.1.100-150")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, ipr1.Overlaps(ipr2), false)

	ipr2, err = ParseIPRange("192.168.1.100-250")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, ipr1.Overlaps(ipr2), true)

	ipr1, err = ParseIPRange("192.168.1.1-255/24")
	tt.TestExpectSuccess(t, err)
	ipr2, err = ParseIPRange("192.168.0.1-3.255/22")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, ipr1.Overlaps(ipr2), true)
}
Example #2
0
func TestReadInt64(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	f := tt.WriteTempFile(t, "foo\nbar")

	_, err := ReadInt64(f)
	tt.TestExpectError(t, err)

	f = tt.WriteTempFile(t, "123\n456")

	v, err := ReadInt64(f)
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, v, int64(123))

	f = tt.WriteTempFile(t, "123456789")
	v, err = ReadInt64(f)
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, v, int64(123456789))

	maxInt64 := fmt.Sprintf("%d", int64(1<<63-1))
	f = tt.WriteTempFile(t, maxInt64)

	v, err = ReadInt64(f)
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, v, int64(1<<63-1))

	maxInt64WithExtra := fmt.Sprintf("%d666", int64(1<<63-1))
	f = tt.WriteTempFile(t, maxInt64WithExtra)

	v, err = ReadInt64(f)
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, v, int64(1<<63-1))
}
Example #3
0
func TestDeepMergeChildrenPropagateToSource(t *testing.T) {
	dst := make(map[string]interface{})
	src1 := map[string]interface{}{
		"foobar": map[string]interface{}{
			"one":   float64(1),
			"three": float64(3),
		},
	}
	src2 := map[string]interface{}{
		"foobar": map[string]interface{}{
			"two":  "2",
			"four": float64(4),
		},
	}
	expected := map[string]interface{}{
		"foobar": map[string]interface{}{
			"one":   float64(1),
			"two":   "2",
			"three": float64(3),
			"four":  float64(4),
		},
	}
	expectedSrc1 := map[string]interface{}{
		"foobar": map[string]interface{}{
			"one":   float64(1),
			"three": float64(3),
		},
	}
	tt.TestExpectSuccess(t, Merge(dst, src1))
	tt.TestExpectSuccess(t, Merge(dst, src2))
	tt.TestEqual(t, dst, expected)
	tt.TestEqual(t, src1, expectedSrc1)
}
Example #4
0
func TestNewRequest(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	// create a test server
	method, path, body := "", "", ""
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		method = req.Method
		path = req.URL.Path

		defer req.Body.Close()
		b, err := ioutil.ReadAll(req.Body)
		if err != nil {
			t.Errorf("Error reading request: %v", err)
			w.WriteHeader(500)
			return
		}
		body = string(b)
		w.WriteHeader(200)
	}))
	defer server.Close()

	client, err := New(server.URL)
	tt.TestExpectSuccess(t, err)
	req := client.NewRequest("POST", "/blobs", "text/plain", strings.NewReader("I am a giant blob of bytes!"))
	err = client.Result(req, nil)
	tt.TestExpectSuccess(t, err)

	// Verify request as received by server
	tt.TestEqual(t, method, "POST")
	tt.TestEqual(t, path, "/blobs")
	tt.TestEqual(t, body, "I am a giant blob of bytes!")
}
Example #5
0
func TestEmptyPostRequest(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	// create a test server
	body := ""
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		defer req.Body.Close()
		b, err := ioutil.ReadAll(req.Body)
		if err != nil {
			t.Errorf("Error reading request: %v", err)
			w.WriteHeader(500)
			return
		}
		body = string(b)
		w.WriteHeader(200)
	}))
	defer server.Close()

	client, err := New(server.URL)
	tt.TestExpectSuccess(t, err)
	req := client.NewJsonRequest("POST", "/", nil)

	err = client.Result(req, nil)
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, body, "")
}
Example #6
0
func TestSubtract(t *testing.T) {
	ipr, err := ParseIPRange("192.168.1.10-19")
	tt.TestExpectSuccess(t, err)
	alloc := NewAllocator(ipr)
	tt.TestEqual(t, alloc.remaining, int64(10))

	// create a smaller range within the same one
	ipr2, err := ParseIPRange("192.168.1.10-14")
	tt.TestExpectSuccess(t, err)

	// subtract it
	alloc.Subtract(ipr2)

	// validate it
	tt.TestEqual(t, alloc.remaining, int64(5))
	tt.TestEqual(t, len(alloc.reserved), 5)

	// consume everything and ensure we don't get an IP in the second range.
	for {
		if alloc.Remaining() == 0 {
			break
		}

		ip := alloc.Allocate()
		tt.TestNotEqual(t, ip, nil)
		tt.TestEqual(t, ipr2.Contains(ip), false)
	}
}
Example #7
0
func TestGetImageMetadata(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	img, statusCode, err := GetImage("foo/bar", "")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, statusCode, 200)

	var m1 map[string]interface{}
	err = img.Metadata("tag2", &m1)
	tt.TestExpectError(t, err)
	tt.TestEqual(t, err.Error(), "can't find tag 'tag2' for image 'foo/bar'")

	var m2 map[string]interface{}
	err = img.Metadata("latest", &m2)
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, len(m2), 2)
	tt.TestEqual(t, m2["id"], "deadbeef")
	tt.TestEqual(t, m2["k2"], "v2")

	var m3 map[string]interface{}
	err = img.Metadata("base", &m3)
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, len(m3), 2)
	tt.TestEqual(t, m3["id"], "badcafe")
	tt.TestEqual(t, m3["k1"], "v1")
}
Example #8
0
func TestErrorResponseNoBody(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	// create a test server
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		w.Header().Set("Content-Type", "text/plain")
		w.WriteHeader(500)
	}))
	defer server.Close()

	client, err := New(server.URL)
	tt.TestExpectSuccess(t, err)
	req := client.NewFormRequest("GET", "/", nil)
	resp, err := client.Do(req)
	tt.TestExpectError(t, err)

	rerr, ok := err.(*RestError)
	tt.TestEqual(t, ok, true, "Error should be of type *RestError")
	tt.TestEqual(t, rerr.Error(), "error in response: 500 Internal Server Error")

	body, err := ioutil.ReadAll(resp.Body)
	defer resp.Body.Close()
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, string(body), "")
}
Example #9
0
func TestFormRequest(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	// create a test server
	var form url.Values
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		if err := req.ParseForm(); err != nil {
			t.Errorf("Error reading request: %v", err)
			w.WriteHeader(500)
			return
		}
		form = req.Form
		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(200)
		io.WriteString(w, `{"foo":"bar"}`)
	}))
	defer server.Close()

	client, err := New(server.URL)
	tt.TestExpectSuccess(t, err)
	req := client.NewFormRequest("POST", "/", map[string]string{"name": "Tim"})
	err = client.Result(req, nil)
	tt.TestExpectSuccess(t, err)

	// Verify form data as received by server
	tt.TestEqual(t, form.Get("name"), "Tim")
}
Example #10
0
func createSocketServer(t *testing.T) (string, net.Listener) {
	socketFile := tt.TempFile(t)
	tt.TestExpectSuccess(t, os.Remove(socketFile))

	l, err := net.Listen("unix", socketFile)
	tt.TestExpectSuccess(t, err)

	return socketFile, l
}
Example #11
0
func TestClient_Start(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	socketFile, l := createSocketServer(t)
	defer l.Close()

	var startContent string
	readChan := setupReadRequest(t, l, &startContent, "REQUEST OK\n")

	client := New(socketFile)
	err := client.Start(
		"echo", []string{"123"}, "dir", []string{"FOO=bar"},
		"/a", "/b", "123", "456", time.Second,
	)
	tt.TestExpectSuccess(t, err)

	select {
	case <-readChan:
	case <-time.After(time.Second):
		tt.Fatalf(t, "Expected to have read client response within 1 second")
	}

	expectedRequest := "1\n6\n2\n5\nSTART4\necho1\n3\n1231\n3\ndir1\n7\nFOO=bar2\n2\n/a2\n/b2\n3\n1233\n456"
	tt.TestEqual(t, startContent, expectedRequest)
}
Example #12
0
func TestAllocate(t *testing.T) {
	ipr, err := ParseIPRange("192.168.1.10-19")
	tt.TestExpectSuccess(t, err)
	alloc := NewAllocator(ipr)

	// get the first one
	ip := alloc.Allocate()
	tt.TestEqual(t, ipr.Contains(ip), true)
	tt.TestEqual(t, alloc.Remaining(), int64(9))

	// consume the others
	for i := 0; i < 8; i++ {
		ip = alloc.Allocate()
		tt.TestEqual(t, ipr.Contains(ip), true, fmt.Sprintf("%s was not within the range", ip.String()))
	}
	tt.TestEqual(t, alloc.Remaining(), int64(1))

	// last ip
	ip = alloc.Allocate()
	tt.TestEqual(t, ipr.Contains(ip), true)
	tt.TestEqual(t, alloc.Remaining(), int64(0))

	// no more left
	ip = alloc.Allocate()
	tt.TestEqual(t, ip, nil)
	tt.TestEqual(t, alloc.Remaining(), int64(0))
}
Example #13
0
func TestRelease(t *testing.T) {
	ipr, err := ParseIPRange("192.168.1.10-19")
	tt.TestExpectSuccess(t, err)
	alloc := NewAllocator(ipr)

	// test releasing when empty
	alloc.Release(net.ParseIP("192.168.1.11"))
	tt.TestEqual(t, alloc.remaining, int64(10))

	// consume everything
	for {
		if alloc.Remaining() == 0 {
			break
		}
		ip := alloc.Allocate()
		tt.TestNotEqual(t, ip, nil)
	}

	// release an IP
	tt.TestEqual(t, alloc.remaining, int64(0))
	alloc.Release(net.ParseIP("192.168.1.11"))
	tt.TestEqual(t, alloc.remaining, int64(1))

	// allocate one more and should get that one
	tt.TestEqual(t, alloc.Allocate().String(), "192.168.1.11")
	tt.TestEqual(t, alloc.remaining, int64(0))
}
Example #14
0
func TestErrorResult(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	// create a test server
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		w.Header().Set("Content-Type", "text/plain")
		w.WriteHeader(500)
		io.WriteString(w, "Didn't work")
	}))
	defer server.Close()

	client, err := New(server.URL)
	tt.TestExpectSuccess(t, err)
	req := client.NewFormRequest("GET", "/", nil)
	err = client.Result(req, nil)
	tt.TestExpectError(t, err)

	rerr, ok := err.(*RestError)
	tt.TestEqual(t, ok, true, "Error should be of type *RestError")
	tt.TestEqual(t, rerr.Error(), "error in response: 500 Internal Server Error - Didn't work")
	tt.TestEqual(t, rerr.Body(), "Didn't work")

	rerr2 := new(RestError)
	rerr2.err = fmt.Errorf("foo bar baz wibble")
	tt.TestEqual(t, rerr2.Error(), "foo bar baz wibble")

	rerr2 = new(RestError)
	rerr2.Resp = &http.Response{
		StatusCode: 404,
	}
	rerr2.err = fmt.Errorf("foo bar baz wibble")
	tt.TestEqual(t, rerr2.Error(), "foo bar baz wibble")
}
Example #15
0
func TestClient_Exec(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	socketFile, l := createSocketServer(t)
	defer l.Close()

	var execContent string
	readChan := setupReadRequest(t, l, &execContent, "REQUEST OK\n")

	client := New(socketFile)
	err := client.Exec(
		[]string{"/sbin/init", "foo"}, []string{"FOO=bar"}, "/a", "/b", time.Second,
	)
	tt.TestExpectSuccess(t, err)

	select {
	case <-readChan:
	case <-time.After(time.Second):
		tt.Fatalf(t, "Expected to have read client response within 1 second")
	}

	expectedRequest := "1\n4\n1\n4\nEXEC2\n10\n/sbin/init3\nfoo1\n7\nFOO=bar2\n2\n/a2\n/b"
	tt.TestEqual(t, execContent, expectedRequest)
}
Example #16
0
func TestNewAllocator(t *testing.T) {
	ipr, err := ParseIPRange("192.168.1.10-19")
	tt.TestExpectSuccess(t, err)

	alloc := NewAllocator(ipr)
	tt.TestEqual(t, alloc.size, int64(10))
	tt.TestEqual(t, alloc.remaining, int64(10))
}
Example #17
0
func TestGetImageHistory(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	img, statusCode, err := GetImage("foo/bar", "")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, statusCode, 200)

	h, err := img.History("tag2")
	tt.TestExpectError(t, err)
	tt.TestEqual(t, err.Error(), "can't find tag 'tag2' for image 'foo/bar'")

	h, err = img.History("latest")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, len(h), 2)
	tt.TestEqual(t, h[0], "deadbeef")
	tt.TestEqual(t, h[1], "badcafe")
}
Example #18
0
func TestClient_WaitForSocket(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	socketFile := tt.TempFile(t)
	tt.TestExpectSuccess(t, os.Remove(socketFile))

	client := New(socketFile)
	err := client.WaitForSocket(10 * time.Millisecond)
	tt.TestExpectError(t, err)

	f, err := os.Create(socketFile)
	tt.TestExpectSuccess(t, err)
	f.Close()

	err = client.WaitForSocket(10 * time.Millisecond)
	tt.TestExpectSuccess(t, err)
}
Example #19
0
func TestDeepMergeRecursiveMap(t *testing.T) {
	dst := map[string]interface{}{
		"settings": map[string]interface{}{
			"internal": map[string]interface{}{
				"foo": "bar",
				"baz": []interface{}{"arg", "agg", "ugh"},
			},
			"external": map[string]interface{}{
				"path":     "/",
				"approved": false,
				"number":   float64(123),
			},
		},
		"domain": "example.com",
	}
	src := map[string]interface{}{
		"admin":  "John",
		"domain": "example.org",
		"settings": map[string]interface{}{
			"internal": map[string]interface{}{
				"foo": "buf",
			},
			"external": map[string]interface{}{
				"path":     []interface{}{"/v1", "/v2"},
				"approved": true,
				"allowed":  false,
			},
			"wildcard": map[string]interface{}{
				"destination": "home",
				"source":      "work",
			},
		},
	}
	expected := map[string]interface{}{
		"domain": "example.org",
		"admin":  "John",
		"settings": map[string]interface{}{
			"internal": map[string]interface{}{
				"foo": "buf",
				"baz": []interface{}{"arg", "agg", "ugh"},
			},
			"external": map[string]interface{}{
				"path":     []interface{}{"/v1", "/v2"},
				"approved": true,
				"allowed":  false,
				"number":   float64(123),
			},
			"wildcard": map[string]interface{}{
				"destination": "home",
				"source":      "work",
			},
		},
	}
	tt.TestExpectSuccess(t, Merge(dst, src))
	tt.TestEqual(t, dst, expected)
}
Example #20
0
func TestGetImage(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	img, statusCode, err := GetImage("", "")
	tt.TestExpectError(t, err)
	tt.TestEqual(t, statusCode, -1)
	tt.TestEqual(t, err.Error(), "image name is empty")

	img, statusCode, err = GetImage("foo/bar", "")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, statusCode, 200)
	tt.TestEqual(t, img.Name, "foo/bar")

	img, statusCode, err = GetImage("base", "")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, statusCode, 200)
	tt.TestEqual(t, img.Name, "base")
}
Example #21
0
func TestTempFile(t *testing.T) {
	r := strings.NewReader("blah")
	f, err := New(r)
	tt.TestExpectSuccess(t, err)

	b, err := ioutil.ReadAll(f)
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, string(b), "blah")

	tf := f.(*unlinkOnCloseFile)
	st, err := os.Stat(tf.File.Name())
	tt.TestExpectSuccess(t, err)
	tt.TestNotEqual(t, st, nil)

	tt.TestExpectSuccess(t, f.Close())

	_, err = os.Stat(tf.File.Name())
	tt.TestExpectError(t, err)
	tt.TestEqual(t, os.IsNotExist(err), true)
}
Example #22
0
func TestReserveOutOfRange(t *testing.T) {
	ipr, err := ParseIPRange("192.168.1.10-19")
	tt.TestExpectSuccess(t, err)
	alloc := NewAllocator(ipr)

	// reserve an IP
	reservedIP := net.ParseIP("10.0.0.1")
	alloc.Reserve(reservedIP)
	tt.TestEqual(t, alloc.remaining, int64(10))
	tt.TestEqual(t, len(alloc.reserved), 0)
}
Example #23
0
func TestGetImageTagLayerID(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	img, statusCode, err := GetImage("foo/bar", "")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, statusCode, 200)

	_, err = img.TagLayerID("tag2")
	tt.TestExpectError(t, err)
	tt.TestEqual(t, err.Error(), "can't find tag 'tag2' for image 'foo/bar'")

	id, err := img.TagLayerID("latest")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, id, "deadbeef")

	id, err = img.TagLayerID("base")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, id, "badcafe")
}
Example #24
0
func TestBasicJsonRequest(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	// create a test server
	method, path, body := "", "", ""
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		method = req.Method
		path = req.URL.Path

		defer req.Body.Close()
		b, err := ioutil.ReadAll(req.Body)
		if err != nil {
			t.Errorf("Error reading request: %v", err)
			w.WriteHeader(500)
			return
		}
		body = string(b)
		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(200)
		io.WriteString(w, `{"foo":"bar"}`)
	}))
	defer server.Close()

	client, err := New(server.URL)
	tt.TestExpectSuccess(t, err)
	req := client.NewJsonRequest("POST", "/foo", map[string]string{"bar": "baz"})

	var res map[string]string
	err = client.Result(req, &res)
	tt.TestExpectSuccess(t, err)

	// Verify request as received by server
	tt.TestEqual(t, method, "POST")
	tt.TestEqual(t, path, "/foo")
	tt.TestEqual(t, body, `{"bar":"baz"}`+"\n")

	// Verify response was parsed by client
	tt.TestEqual(t, len(res), 1)
	tt.TestEqual(t, res["foo"], "bar")
}
Example #25
0
func TestGetImageTags(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	img, statusCode, err := GetImage("foo/bar", "")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, statusCode, 200)

	tags := img.Tags()
	sort.Strings(tags)
	tt.TestEqual(t, tags, []string{"base", "latest"})
}
Example #26
0
func TestHelper_newRequestWithParams(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	client, err := New("http://example.com/resources")
	tt.TestExpectSuccess(t, err)
	req := client.newRequest(GET, "/excellence?yeah=stuff&more=params")

	tt.TestEqual(t, req.Method, GET)
	tt.TestEqual(t, req.URL.String(), "http://example.com/resources/excellence?yeah=stuff&more=params")
	tt.TestEqual(t, req.Headers, http.Header(map[string][]string{}))
}
Example #27
0
func TestParseMimetype(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	// create a test server
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		w.Header().Set("Content-Type", "application/json; charset=utf-8")
		w.WriteHeader(200)
		io.WriteString(w, `{"Name":"Molly","Age":45}`)
	}))
	defer server.Close()

	client, err := New(server.URL)
	tt.TestExpectSuccess(t, err)
	req := client.NewJsonRequest("GET", "/", nil)

	var responsePerson person
	err = client.Result(req, &responsePerson)
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, responsePerson.Name, "Molly")
	tt.TestEqual(t, responsePerson.Age, 45)
}
Example #28
0
func TestDeepMergeHandlesNilDestination(t *testing.T) {
	var dst map[string]interface{}
	src := map[string]interface{}{
		"two":  "2",
		"four": float64(4),
	}
	err := Merge(dst, src)
	tt.TestExpectError(t, err)
	tt.TestEqual(t, err, NilDestinationError)
	dst = make(map[string]interface{})
	tt.TestExpectSuccess(t, Merge(dst, src))
	tt.TestEqual(t, dst, src)
}
Example #29
0
func TestIPRangeContains(t *testing.T) {
	ipr1, err := ParseIPRange("192.168.1.10-50")
	tt.TestExpectSuccess(t, err)

	tt.TestEqual(t, ipr1.Contains(net.ParseIP("192.168.1.1")), false)
	tt.TestEqual(t, ipr1.Contains(net.ParseIP("192.168.1.9")), false)
	tt.TestEqual(t, ipr1.Contains(net.ParseIP("192.168.1.51")), false)
	tt.TestEqual(t, ipr1.Contains(net.ParseIP("192.168.2.10")), false)

	tt.TestEqual(t, ipr1.Contains(net.ParseIP("192.168.1.10")), true)
	tt.TestEqual(t, ipr1.Contains(net.ParseIP("192.168.1.20")), true)
	tt.TestEqual(t, ipr1.Contains(net.ParseIP("192.168.1.50")), true)
}
Example #30
0
func TestReadLayer(t *testing.T) {
	tt.StartTest(t)
	defer tt.FinishTest(t)

	img, statusCode, err := GetImage("foo/bar", "")
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, statusCode, 200)

	r, err := img.LayerReader("deadbeef")
	tt.TestExpectSuccess(t, err)
	body, err := ioutil.ReadAll(r)
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, body, []byte{0xd4, 0xe5, 0xf6})

	r, err = img.LayerReader("badcafe")
	tt.TestExpectSuccess(t, err)
	body, err = ioutil.ReadAll(r)
	tt.TestExpectSuccess(t, err)
	tt.TestEqual(t, body, []byte{0xa1, 0xb2, 0xc3})

	r, err = img.LayerReader("badbad")
	tt.TestExpectError(t, err)
}