M config.go +10 -10
@@ 17,18 17,18 @@ type Configuration struct {
}
-func (h Configuration) GetWorkspaces ( limit int ) map[string]([]string) {
+func (h Configuration) GetWorkspaces ( limit int ) (workspace map[string]([]string)) {
revs := h.Repo.Revs()
if limit != 0 {
revs = revs[:limit]
}
tags := h.Repo.Tags()
branches := h.Repo.Branches()
- return_map := make( map[string]([]string), 3 )
- return_map["revisions"] = revs
- return_map["tags"] = tags
- return_map["branches"] = branches
- return return_map
+ workspace = make( map[string]([]string), 3 )
+ workspace["revisions"] = revs
+ workspace["tags"] = tags
+ workspace["branches"] = branches
+ return
}
@@ 88,14 88,14 @@ func to_string( path []string ) string {
}
-func keys( m StoreMap ) []string {
- mk := make([]string, len(m))
+func keys( m StoreMap ) (keys []string) {
+ keys = make([]string, len(m))
i := 0
for k,_ := range m {
- mk[i] = k
+ keys[i] = k
i++
}
- return mk
+ return
}
M hg.go +18 -14
@@ 16,8 16,10 @@ type Hg struct {
revs_cache map[string]string
}
-const CONF_FILENAME = "config.json"
-const DEFAULT = "default"
+const (
+ CONF_FILENAME = "config.json"
+ DEFAULT = "default"
+ )
@@ 31,8 33,7 @@ func (r *Hg) Init( repo_dir string ) {
r.repo_path = repo_dir
r.revs_cache = make( map[string]string, 0 )
// get entries for repo_path
- finfo, e := ioutil.ReadDir( r.repo_path )
- if e == nil {
+ if finfo, e := ioutil.ReadDir( r.repo_path ); e == nil {
// If entries contains more than .. and . but not .hg, then error out
hasHg := false
isEmpty := true
@@ 62,15 63,18 @@ func (r *Hg) Init( repo_dir string ) {
// else, hg init
init := exec.Command( "hg", "init", r.repo_path )
if init.Run() != nil {
- panic( "Fatal error initializing repository: "+e.String() )
+ panic( "Fatal error initializing repository" )
}
- err := ioutil.WriteFile( r.repo_path+"/config.json", []byte("{}"), 0600 )
- if err != nil { panic( "Error writing config.json: "+err.String() ) }
- _, err = runHg( r.repo_path, "add", CONF_FILENAME )
- if err != nil { panic( "Error adding config.json: "+err.String() ) }
- _, err = runHg( r.repo_path, "ci", "-m", "Initial commit" )
- if err != nil { panic( "Error committing config.json: "+err.String() ) }
+ if err := ioutil.WriteFile( r.repo_path+"/config.json", []byte("{}"), 0600 ); err != nil {
+ panic( "Error writing config.json: "+err.String() )
+ }
+ if _, err := runHg( r.repo_path, "add", CONF_FILENAME ); err != nil {
+ panic( "Error adding config.json: "+err.String() )
+ }
+ if _, err := runHg( r.repo_path, "ci", "-m", "Initial commit" ); err != nil {
+ panic( "Error committing config.json: "+err.String() )
+ }
}
@@ 156,16 160,16 @@ func (r Hg) Branch( version string, name
r.revs_cache[ name ] = string(bytes)
}
-func runHg( path string, args ...string ) (string, os.Error) {
+func runHg( path string, args ...string ) (output string, err os.Error) {
//log.Print( args )
cmd := exec.Command( "hg", args[:]... )
cmd.Dir = path
outputBytes, err := cmd.Output()
- output := string(outputBytes)
+ output = string(outputBytes)
if err != nil {
log.Printf( "Failure %v:\n %s", args, err.String() )
}
- return string(output), err
+ return output, err
}
M server.go +1 -1
@@ 223,7 223,7 @@ func (w *TerminateHandler) ServeHTTP( re
}
-func respond( response http.ResponseWriter, payload interface{}, code int, values http.Values ) {
+func respond(response http.ResponseWriter, payload interface{}, code int, values http.Values) {
var serial Serializer
var content_type string
switch values.Get("format") {
M test/functional.rb +13 -0
@@ 65,6 65,19 @@ class Functional < Test::Unit::TestCase
res = RestClient.get( @@base + 'component/server1' )
assert_equal( '{"server1":{"attributes":{"attr1":3,"attr2":"two"},"parents":["servers"]}}', res )
end
+
+ def test_put_complex
+ # POST to create a new workspace
+ RestClient.post( @@base + 'workspace/0', "" )
+ # PUT to write a config
+ RestClient.put( @@base + 'component/servers', '{ "attributes": {"attr1":1, "attr2":"two"}, "parents": [] }' )
+ # GET to get a config
+ RestClient.put( @@base + 'component/server1', '{ "attributes": {"attr1":3}, "parents": ["servers"] }' )
+ res = RestClient.get( @@base + 'component/server1/0' )
+ RestClient.put( @@base + "workspace/0", "" )
+ res = RestClient.get( @@base + 'component/server1' )
+ assert_equal( '{"server1":{"attributes":{"attr1":3,"attr2":"two"},"parents":["servers"]}}', res )
+ end
def test_alter_parent