Example #1
0
func testMakeListRoutes(faultyStore bool, withRoute bool) (*bytes.Buffer, *RouteList) {

	var kvs, _ = kvstore.NewHashKVStore("")

	var writer = new(bytes.Buffer)
	var ui = &cli.BasicUi{Writer: writer, ErrorWriter: writer}
	var listRoutes = &RouteList{
		UI:      ui,
		KVStore: kvs,
	}

	if withRoute {
		b := &config.RouteConfig{
			Name:     "Route1",
			URIRoot:  "/foo",
			Backends: []string{"b1"},
			Plugins:  nil,
			MsgProps: "",
		}
		b.Store(kvs)
	}

	if faultyStore {
		kvs.InjectFaults()
	}

	return writer, listRoutes
}
Example #2
0
func TestListenerStoreAndRetrieve(t *testing.T) {
	var testKVS, _ = kvstore.NewHashKVStore("")

	//Read - not found
	ln, err := ReadListenerConfig("l1", testKVS)
	assert.Nil(t, err)
	assert.Nil(t, ln, "Expected listener to be nil")

	//Read - empty list
	listeners, err := ListListenerConfigs(testKVS)
	assert.Nil(t, err)
	assert.Nil(t, listeners)

	//Store
	ln = &ListenerConfig{"l1", []string{"route1", "route2"}}
	err = ln.Store(testKVS)
	assert.Nil(t, err)

	//Read - found
	ln, err = ReadListenerConfig("l1", testKVS)
	assert.Nil(t, err)
	testVerifyListenerRead(ln, t)

	//Grab a list of backends
	listeners, err = ListListenerConfigs(testKVS)
	assert.Nil(t, err)
	assert.Equal(t, 1, len(listeners))
	testVerifyListenerRead(listeners[0], t)
}
Example #3
0
func TestServerStoreAndRetrieve(t *testing.T) {
	var testKVS, _ = kvstore.NewHashKVStore("")

	//Read - not found
	server, err := ReadServerConfig("s1", testKVS)
	assert.Nil(t, err)
	assert.Nil(t, server, "Expected server to be nil")

	//Read - empty list
	servers, err := ListServerConfigs(testKVS)
	assert.Nil(t, err)
	assert.Nil(t, servers)

	//Store
	server = &ServerConfig{"s1", "0.0.0.0", 5000, "/ping", "none", 0, 0}
	err = server.Store(testKVS)
	assert.Nil(t, err)

	//Read - found
	server, err = ReadServerConfig("s1", testKVS)
	assert.Nil(t, err)
	testVerifyServerRead(server, t)

	//Grab a list of servers
	servers, err = ListServerConfigs(testKVS)
	assert.Nil(t, err)
	assert.Equal(t, 1, len(servers))
	testVerifyServerRead(servers[0], t)

}
Example #4
0
func testMakeAddRoute(faultyStore bool, t *testing.T) (*bytes.Buffer, *AddRoute) {

	var kvs, _ = kvstore.NewHashKVStore("")

	var writer = new(bytes.Buffer)
	var ui = &cli.BasicUi{Writer: writer, ErrorWriter: writer}
	var addRoute = &AddRoute{
		UI:      ui,
		KVStore: kvs,
	}

	//Add the backends the command will validate
	b := &config.BackendConfig{
		Name:        "b1",
		ServerNames: []string{"s1", "s2", "s3"},
	}
	err := b.Store(kvs)
	assert.Nil(t, err)

	b = &config.BackendConfig{
		Name:        "b2",
		ServerNames: []string{"s1", "s2", "s3"},
	}
	err = b.Store(kvs)
	assert.Nil(t, err)

	//Enable fault injection after writing the backend def
	if faultyStore {
		kvs.InjectFaults()
	}

	return writer, addRoute
}
Example #5
0
func testMakePingServer(faultKVStore bool, writeServerDefs bool, port int) (*bytes.Buffer, *PingServer) {

	var kvs, _ = kvstore.NewHashKVStore("")

	var writer = new(bytes.Buffer)
	var ui = &cli.BasicUi{Writer: writer, ErrorWriter: writer}
	var pingServer = &PingServer{
		UI:      ui,
		KVStore: kvs,
	}

	if writeServerDefs {
		if port == -1 {
			port = 124
			s := &config.ServerConfig{"unpingable", "host", port, "", "none", 0, 0}
			s.Store(kvs)
		} else {
			s := &config.ServerConfig{"pingable", "0.0.0.0", port, "/pingme", "none", 0, 0}
			s.Store(kvs)
		}
	}

	if faultKVStore {
		kvs.InjectFaults()
	}
	return writer, pingServer
}
Example #6
0
func BuildKVStoreTestConfig(t *testing.T) kvstore.KVStore {
	kvs, _ := kvstore.NewHashKVStore("")
	loadTestConfig1(kvs, t)
	loadConfigTwoBackendsNoPluginNameSpecified(kvs, t)
	loadMultiRoute(kvs, t)
	loadRouteWithNoBackends(kvs, t)
	loadTLSOnlyBackend(kvs, t)
	loadTLSOnlyBackendBadCert(kvs, t)
	return kvs
}
Example #7
0
func testMakeRestAgentCmd() (*bytes.Buffer, *RESTAgent) {

	var kvs, _ = kvstore.NewHashKVStore("")

	var writer = new(bytes.Buffer)
	var ui = &cli.BasicUi{Writer: writer, ErrorWriter: writer}
	var listener = &RESTAgent{
		UI:      ui,
		KVStore: kvs,
	}

	return writer, listener
}
Example #8
0
func testMakeAddServer(faultyStore bool) (*bytes.Buffer, *AddServer) {

	var kvs, _ = kvstore.NewHashKVStore("")
	if faultyStore {
		kvs.InjectFaults()
	}
	var writer = new(bytes.Buffer)
	var ui = &cli.BasicUi{Writer: writer, ErrorWriter: writer}
	var addServer = &AddServer{
		UI:      ui,
		KVStore: kvs,
	}

	return writer, addServer
}
Example #9
0
func testMakeListPlugins(faultyStore bool, withPlugin bool) (*bytes.Buffer, *PluginList) {

	var kvs, _ = kvstore.NewHashKVStore("")
	if faultyStore {
		kvs.InjectFaults()
	}
	var writer = new(bytes.Buffer)
	var ui = &cli.BasicUi{Writer: writer, ErrorWriter: writer}
	var listPlugins = &PluginList{
		UI:      ui,
		KVStore: kvs,
	}

	if withPlugin {
		plugin.RegisterWrapperFactory("AWrapper", NewAWrapper)
	}

	return writer, listPlugins
}
Example #10
0
func testMakeListListeners(faultyStore bool, withListener bool) (*bytes.Buffer, *ListenerList) {

	var kvs, _ = kvstore.NewHashKVStore("")
	if faultyStore {
		kvs.InjectFaults()
	}
	var writer = new(bytes.Buffer)
	var ui = &cli.BasicUi{Writer: writer, ErrorWriter: writer}
	var listListeners = &ListenerList{
		UI:      ui,
		KVStore: kvs,
	}

	if withListener {
		b := &config.ListenerConfig{"l1", []string{"r1", "r2", "r3"}}
		b.Store(kvs)
	}

	return writer, listListeners
}
Example #11
0
func TestMainNoArgs(t *testing.T) {
	kvs, _ := kvstore.NewHashKVStore("")
	var args []string

	buf := new(bytes.Buffer)

	status := DoMain(args, kvs, buf)
	assert.Equal(t, 1, status)
	out := buf.String()
	assert.True(t, strings.Contains(out, "add-server"), "Missing add-server command.")
	assert.True(t, strings.Contains(out, "ping-server"), "Missing ping-server command.")
	assert.True(t, strings.Contains(out, "add-backend"), "Missing add-backend command.")
	assert.True(t, strings.Contains(out, "add-route"), "Missing add-route command.")
	assert.True(t, strings.Contains(out, "add-listener"), "Missing add-listener command.")
	assert.True(t, strings.Contains(out, "listen"), "Missing listen command.")
	assert.True(t, strings.Contains(out, "boot-rest-agent"), "Missing boot-rest-agent command.")
	assert.True(t, strings.Contains(out, "list-servers"), "Missing list-servers command.")
	assert.True(t, strings.Contains(out, "list-backends"), "Missing list-backends command.")
	assert.True(t, strings.Contains(out, "list-routes"), "Missing list-routes command.")
	assert.True(t, strings.Contains(out, "list-listeners"), "Missing list-listeners command.")
	assert.True(t, strings.Contains(out, "list-plugins"), "Missing list-plugins command.")
}
Example #12
0
func testMakeListServers(faultyStore bool, withServer bool) (*bytes.Buffer, *ServerList) {

	var kvs, _ = kvstore.NewHashKVStore("")

	var writer = new(bytes.Buffer)
	var ui = &cli.BasicUi{Writer: writer, ErrorWriter: writer}
	var listServers = &ServerList{
		UI:      ui,
		KVStore: kvs,
	}

	if withServer {
		b := &config.ServerConfig{"name", "host", 123, "ping", "none", 0, 0}
		b.Store(kvs)
	}

	if faultyStore {
		kvs.InjectFaults()
	}

	return writer, listServers
}
Example #13
0
func testMakeListBackends(faultyStore bool, withBackend bool) (*bytes.Buffer, *BackendList) {

	var kvs, _ = kvstore.NewHashKVStore("")
	if faultyStore {
		kvs.InjectFaults()
	}
	var writer = new(bytes.Buffer)
	var ui = &cli.BasicUi{Writer: writer, ErrorWriter: writer}
	var listBackends = &BackendList{
		UI:      ui,
		KVStore: kvs,
	}

	if withBackend {
		b := &config.BackendConfig{
			Name:        "b1",
			ServerNames: []string{"s1", "s2", "s3"},
		}
		b.Store(kvs)
	}

	return writer, listBackends
}
Example #14
0
func TestRouteStoreAndRetrieve(t *testing.T) {
	var testKVS, _ = kvstore.NewHashKVStore("")

	//Read - not found
	r, err := ReadRouteConfig("route1", testKVS)
	assert.Nil(t, err)
	assert.Nil(t, r, "Expected route to be nil")

	//Read - empty list
	routes, err := ListRouteConfigs(testKVS)
	assert.Nil(t, err)
	assert.Nil(t, routes)

	//Store
	var plugins = []string{"plugin1", "plugin2", "plugin3"}
	r = &RouteConfig{
		Name:                "route1",
		URIRoot:             "/hello",
		Backends:            []string{"hello-backend", "hello-backend2"},
		Plugins:             plugins,
		MsgProps:            "SOAPAction:\"foo\"",
		MultiBackendAdapter: "multi-backend-adapter",
	}
	err = r.Store(testKVS)
	assert.Nil(t, err)

	//Read - found
	r, err = ReadRouteConfig("route1", testKVS)
	assert.Nil(t, err)
	testVerifyRouteRead(r, t)

	//Read - list
	routes, err = ListRouteConfigs(testKVS)
	assert.Nil(t, err)
	assert.Equal(t, 1, len(routes))
	testVerifyRouteRead(routes[0], t)
}
Example #15
0
func TestBackendStoreAndRetrieve(t *testing.T) {
	var testKVS, _ = kvstore.NewHashKVStore("")

	//Read - not found
	b, err := ReadBackendConfig("hello-backend", testKVS)
	assert.Nil(t, err)
	assert.Nil(t, b, "Expected backend to be nil")

	//Read - empty list
	backends, err := ListBackendConfigs(testKVS)
	assert.Nil(t, err)
	assert.Nil(t, backends)

	//Store
	b = &BackendConfig{
		Name:               "hello-backend",
		ServerNames:        []string{"s1", "s2", "s3"},
		LoadBalancerPolicy: "round-robin",
		CACertPath:         "",
		TLSOnly:            false,
	}
	err = b.Store(testKVS)
	assert.Nil(t, err)

	//Read - found
	b, err = ReadBackendConfig("hello-backend", testKVS)
	assert.Nil(t, err)
	testVerifyBackendConfig(b, t)

	//Grab a list of backends
	backends, err = ListBackendConfigs(testKVS)
	assert.Nil(t, err)
	assert.Equal(t, 1, len(backends))

	testVerifyBackendConfig(backends[0], t)
}
Example #16
0
func testMakeAndInitializeKVStore() *kvstore.HashKVStore {
	kvs, _ := kvstore.NewHashKVStore("")
	return kvs
}
Example #17
0
func buildTestConfigForLBCall(t *testing.T, server1Url, server2Url string) kvstore.KVStore {
	kvs, _ := kvstore.NewHashKVStore("")

	//Define listener
	ln := &config.ListenerConfig{"lbclistener", []string{"lbcroute1"}}
	err := ln.Store(kvs)
	if err != nil {
		t.Fatal(err)
	}

	//Define server 1
	url, _ := url.Parse(server1Url)
	host, port, err := net.SplitHostPort(url.Host)
	assert.Nil(t, err)

	portVal, err := strconv.Atoi(port)
	assert.Nil(t, err)

	serverConfig1 := &config.ServerConfig{"lbcserver1", host, portVal, "/hello", "none", 0, 0}
	err = serverConfig1.Store(kvs)
	if err != nil {
		t.Fatal(err)
	}

	//Define server 2
	url, _ = url.Parse(server2Url)
	host, port, err = net.SplitHostPort(url.Host)
	assert.Nil(t, err)

	portVal, err = strconv.Atoi(port)
	assert.Nil(t, err)

	serverConfig2 := &config.ServerConfig{"lbcserver2", host, portVal, "/hello", "none", 0, 0}
	err = serverConfig2.Store(kvs)
	if err != nil {
		t.Fatal(err)
	}

	//Define route
	r := &config.RouteConfig{
		Name:     "lbcroute1",
		URIRoot:  "/hello",
		Backends: []string{"lbcbackend"},
		Plugins:  []string{"Logging"},
		MsgProps: "",
	}
	err = r.Store(kvs)
	if err != nil {
		t.Fatal(err)
	}

	b := &config.BackendConfig{
		Name:        "lbcbackend",
		ServerNames: []string{"lbcserver1", "lbcserver2"},
	}
	err = b.Store(kvs)
	if err != nil {
		t.Fatal(err)
	}

	return kvs
}