Example #1
0
func (self *Servers) Save() error {
	var config = revel.NewEmptyConfig()
	*config.Raw() = *robfig_config.New(robfig_config.DEFAULT_COMMENT, robfig_config.ALTERNATIVE_SEPARATOR, true, true)

	for _, server := range *self {
		config.SetSection(server.Label)
		config.SetOption("host", server.Host)
		config.SetOption("port", server.Port)
		config.SetOption("username", server.Username)
		config.SetOption("password", server.Password)
		config.SetOption("private_key", server.PrivateKeyPath)
		config.SetOption("query_interval", strconv.Itoa(server.QueryIntervalSec))

		config.SetSection(server.Label + "/commands")

		for cmd_name, cmd := range server.Commands {
			config.SetOption(cmd_name, cmd)
		}
	}
	return config.Raw().WriteFile(revel.BasePath+"/conf/"+SERVERS_CONF, 0644, "remote servers")
}
Example #2
0
package cache

import (
	"github.com/revel/revel"
	"net"
	"testing"
	"time"
)

// These tests require redis server running on localhost:6379 (the default)
const redisTestServer = "localhost:6379"

var newRedisCache = func(t *testing.T, defaultExpiration time.Duration) Cache {
	revel.Config = revel.NewEmptyConfig()

	c, err := net.Dial("tcp", redisTestServer)
	if err == nil {
		c.Write([]byte("flush_all\r\n"))
		c.Close()
		redisCache := NewRedisCache(redisTestServer, "", defaultExpiration)
		redisCache.Flush()
		return redisCache
	}
	t.Errorf("couldn't connect to redis on %s", redisTestServer)
	t.FailNow()
	panic("")
}

func TestRedisCache_TypicalGetSet(t *testing.T) {
	typicalGetSet(t, newRedisCache)
}