func TestGetKey(t *testing.T) { Convey("Should return a ResponseObject with the key value", t, func() { storage.RegisterShipper("mock", mockdb.MockShipper{}) var opts = config.Options{StorageInterfaceName: "mock", Version: "0.0.0", CfgName: "mockcfg", Key: "initial"} r := GetKey(opts) So(r.Action, ShouldEqual, "get") So(r.Item.Version, ShouldEqual, int64(1)) So(string(r.Item.Value.([]byte)), ShouldEqual, "initial value for test") }) Convey("Should return a ResponseObject with the key value", t, func() { storage.RegisterShipper("mock", mockdb.MockShipper{}) var opts = config.Options{StorageInterfaceName: "mock", Version: "0.0.0", CfgName: "mockcfg", Key: "encoded"} r := GetKey(opts) So(r.Action, ShouldEqual, "get") So(r.Item.Version, ShouldEqual, int64(1)) //So(string(r.Item.Value.([]byte)), ShouldEqual, "initial value for test") log.Println(FormatJSONValue(r).Item.Value) }) Convey("Should return a ResponseObject with an Error message if no key name was provided", t, func() { storage.RegisterShipper("mock", mockdb.MockShipper{}) var opts = config.Options{StorageInterfaceName: "mock", Version: "0.0.0", CfgName: "mockcfg"} r := GetKey(opts) So(r.Action, ShouldEqual, "get") So(r.Error, ShouldEqual, MissingKeyNameMsg) }) }
func TestSetKey(t *testing.T) { Convey("Should return a ResponseObject with an Error message if no value was provided", t, func() { storage.RegisterShipper("mock", mockdb.MockShipper{}) var opts = config.Options{StorageInterfaceName: "mock", Version: "0.0.0"} r := SetKey(opts) So(r.Action, ShouldEqual, "set") So(r.Error, ShouldEqual, ValueRequiredMsg) }) Convey("Should return a ResponseObject with an Error message if no key name was provided", t, func() { storage.RegisterShipper("mock", mockdb.MockShipper{}) var opts = config.Options{StorageInterfaceName: "mock", Version: "0.0.0", CfgName: "mockcfg", Value: []byte("test")} r := SetKey(opts) So(r.Action, ShouldEqual, "set") So(r.Error, ShouldEqual, MissingKeyNameMsg) }) Convey("Should return a ResponseObject with an Error message if no config name was provided", t, func() { storage.RegisterShipper("mock", mockdb.MockShipper{}) var opts = config.Options{StorageInterfaceName: "mock", Version: "0.0.0", Value: []byte("test"), Key: "test"} r := SetKey(opts) So(r.Action, ShouldEqual, "set") So(r.Error, ShouldEqual, MissingCfgNameMsg) }) }
func TestDeleteKey(t *testing.T) { Convey("Should return a ResponseObject with an Error message if not enough arguments were provided", t, func() { storage.RegisterShipper("mock", mockdb.MockShipper{}) var opts = config.Options{StorageInterfaceName: "mock", Version: "0.0.0"} r := DeleteKey(opts) So(r.Action, ShouldEqual, "delete") So(r.Error, ShouldEqual, NotEnoughArgsMsg) }) }
func TestWhich(t *testing.T) { Convey("Should return an error when no .discfg exists", t, func() { storage.RegisterShipper("mock", mockdb.MockShipper{}) var opts = config.Options{StorageInterfaceName: "mock", Version: "0.0.0"} r := Which(opts) So(r.Action, ShouldEqual, "which") So(r.Error, ShouldEqual, NoCurrentWorkingCfgMsg) }) Convey("Should return a ResponseObject with the current working config", t, func() { _ = ioutil.WriteFile(".discfg", []byte("testcfg"), 0644) storage.RegisterShipper("mock", mockdb.MockShipper{}) var opts = config.Options{StorageInterfaceName: "mock", Version: "0.0.0"} r := Which(opts) So(r.Action, ShouldEqual, "which") So(r.CurrentDiscfg, ShouldEqual, "testcfg") _ = os.Remove(".discfg") }) }
func TestInfo(t *testing.T) { Convey("Should return a ResponseObject with info about the config", t, func() { storage.RegisterShipper("mock", mockdb.MockShipper{}) var opts = config.Options{StorageInterfaceName: "mock", Version: "0.0.0", CfgName: "mockcfg"} r := Info(opts) So(r.Action, ShouldEqual, "info") So(r.CfgVersion, ShouldEqual, int64(4)) So(r.CfgState, ShouldEqual, "ACTIVE") So(r.CfgModifiedNanoseconds, ShouldEqual, int64(1464675792991825937)) So(r.CfgModified, ShouldEqual, int64(1464675792)) // So(r.CfgModifiedParsed, ShouldEqual, "2016-05-30T23:23:12-07:00") // ^ System timezone running the tests could make this fail - doh! So(r.CfgModifiedParsed, ShouldHaveSameTypeAs, "string") }) Convey("Should return a ResponseObject with an Error message if not enough arguments were provided", t, func() { storage.RegisterShipper("mock", mockdb.MockShipper{}) var opts = config.Options{StorageInterfaceName: "mock", Version: "0.0.0"} r := Info(opts) So(r.Action, ShouldEqual, "info") So(r.Error, ShouldEqual, NotEnoughArgsMsg) }) }
func TestFormatJSONValue(t *testing.T) { Convey("Should handle basic string values", t, func() { storage.RegisterShipper("mock", mockdb.MockShipper{}) var opts = config.Options{StorageInterfaceName: "mock", Version: "0.0.0", CfgName: "mockcfg", Key: "initial"} r := GetKey(opts) rFormatted := FormatJSONValue(r) So(rFormatted.Item.Value.(string), ShouldEqual, "initial value for test") }) // Not yet // Convey("Should handle base64 encoded string values", t, func() { // storage.RegisterShipper("mock", mockdb.MockShipper{}) // var opts = config.Options{StorageInterfaceName: "mock", Version: "0.0.0", CfgName: "mockcfg", Key: "encoded"} // r := GetKey(opts) // rFormatted := FormatJSONValue(r) // mapValue := map[string]interface{}{"updated": "friday"} // So(rFormatted.Item.Value.(map[string]interface{}), ShouldResemble, mapValue) // }) }