github.com/orofarne/hammy@v0.0.0-20130409105742-374fadfd6ecb/src/hammy/config_test.go (about) 1 package hammy 2 3 import "testing" 4 5 func TestSetConfigDefaults(t *testing.T) { 6 var cfg Config 7 cfg.CouchbaseTriggers.Active = true 8 cfg.CouchbaseStates.Active = true 9 cfg.CouchbaseSaver.Active = true 10 11 err := SetConfigDefaults(&cfg) 12 if err == nil { 13 t.Errorf("Error should not be nil") 14 } 15 16 // Mandatory fields: 17 cfg.Workers.CmdLine = "/bin/ls" 18 cfg.CouchbaseTriggers.ConnectTo = "http://localhost:8091/" 19 cfg.CouchbaseTriggers.Bucket = "default" 20 cfg.CouchbaseStates.ConnectTo = "http://localhost:8091/" 21 cfg.CouchbaseStates.Bucket = "default" 22 cfg.CouchbaseSaver.ConnectTo = "http://localhost:8091/" 23 cfg.CouchbaseSaver.Bucket = "default" 24 cfg.CouchbaseDataReader.ConnectTo = "http://localhost:8091/" 25 cfg.CouchbaseDataReader.Bucket = "default" 26 27 // Retry 28 err = SetConfigDefaults(&cfg) 29 if err == nil { 30 t.Errorf("Error should not be nil") 31 } 32 33 cfg.CouchbaseDataReader.Active = true 34 35 // Retry... 36 err = SetConfigDefaults(&cfg) 37 if err != nil { 38 t.Fatalf("Error: %v", err) 39 } 40 if cfg.IncomingHttp.Addr != ":4000" { 41 t.Errorf("cfg.ImcomingHttp.Addr = %#v, expected %#v", cfg.IncomingHttp.Addr, ":4000") 42 } 43 if cfg.DataHttp.Addr != ":4001" { 44 t.Errorf("cfg.DataHttp.Addr = %#v, expected %#v", cfg.DataHttp.Addr, ":4001") 45 } 46 if cfg.CouchbaseStates.Ttl != 86400 { 47 t.Errorf("cfg.CouchbaseStates.Ttl = %#v, expected 86400", cfg.CouchbaseStates.Ttl) 48 } 49 if cfg.SendBuffer.SleepTime != 10.0 { 50 t.Errorf("cfg.SendBuffer.SleepTime = %#v, expected %#v", cfg.SendBuffer.SleepTime, 10.0) 51 } 52 53 cfg.MySQLTriggers.Active = true 54 55 // Retry... 56 err = SetConfigDefaults(&cfg) 57 if err == nil { 58 t.Errorf("Error should not be nil") 59 } 60 }