Fixed unit tests
This commit is contained in:
parent
cc7ead496f
commit
46a430f58f
|
@ -44,10 +44,6 @@ func TestTableWriteController_NewItem(t *testing.T) {
|
||||||
|
|
||||||
func TestTableWriteController_SetAttributeValue(t *testing.T) {
|
func TestTableWriteController_SetAttributeValue(t *testing.T) {
|
||||||
t.Run("should preserve the type of the field if unspecified", func(t *testing.T) {
|
t.Run("should preserve the type of the field if unspecified", func(t *testing.T) {
|
||||||
client := testdynamo.SetupTestTable(t, testData)
|
|
||||||
|
|
||||||
provider := dynamo.NewProvider(client)
|
|
||||||
service := tables.NewService(provider)
|
|
||||||
|
|
||||||
scenarios := []struct {
|
scenarios := []struct {
|
||||||
attrKey string
|
attrKey string
|
||||||
|
@ -78,6 +74,11 @@ func TestTableWriteController_SetAttributeValue(t *testing.T) {
|
||||||
|
|
||||||
for _, scenario := range scenarios {
|
for _, scenario := range scenarios {
|
||||||
t.Run(fmt.Sprintf("should set value of field: %v", scenario.attrKey), func(t *testing.T) {
|
t.Run(fmt.Sprintf("should set value of field: %v", scenario.attrKey), func(t *testing.T) {
|
||||||
|
client := testdynamo.SetupTestTable(t, testData)
|
||||||
|
|
||||||
|
provider := dynamo.NewProvider(client)
|
||||||
|
service := tables.NewService(provider)
|
||||||
|
|
||||||
state := controllers.NewState()
|
state := controllers.NewState()
|
||||||
readController := controllers.NewTableReadController(state, service, "alpha-table")
|
readController := controllers.NewTableReadController(state, service, "alpha-table")
|
||||||
writeController := controllers.NewTableWriteController(state, service, readController)
|
writeController := controllers.NewTableWriteController(state, service, readController)
|
||||||
|
@ -89,28 +90,29 @@ func TestTableWriteController_SetAttributeValue(t *testing.T) {
|
||||||
assert.Equal(t, scenario.expected, after)
|
assert.Equal(t, scenario.expected, after)
|
||||||
assert.True(t, state.ResultSet().IsDirty(0))
|
assert.True(t, state.ResultSet().IsDirty(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run(fmt.Sprintf("should set value of marked fields: %v", scenario.attrKey), func(t *testing.T) {
|
|
||||||
state := controllers.NewState()
|
|
||||||
readController := controllers.NewTableReadController(state, service, "alpha-table")
|
|
||||||
writeController := controllers.NewTableWriteController(state, service, readController)
|
|
||||||
|
|
||||||
invokeCommand(t, readController.Init())
|
|
||||||
invokeCommand(t, writeController.ToggleMark(0))
|
|
||||||
invokeCommand(t, writeController.ToggleMark(2))
|
|
||||||
invokeCommandWithPrompt(t, writeController.SetAttributeValue(1, models.UnsetItemType, scenario.attrKey), scenario.attrValue)
|
|
||||||
|
|
||||||
after1, _ := state.ResultSet().Items()[0][scenario.attrKey]
|
|
||||||
assert.Equal(t, scenario.expected, after1)
|
|
||||||
assert.True(t, state.ResultSet().IsDirty(0))
|
|
||||||
|
|
||||||
after2, _ := state.ResultSet().Items()[2][scenario.attrKey]
|
|
||||||
assert.Equal(t, scenario.expected, after2)
|
|
||||||
assert.True(t, state.ResultSet().IsDirty(2))
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("should use type of selected item for marked fields if unspecified", func(t *testing.T) {
|
||||||
|
client := testdynamo.SetupTestTable(t, testData)
|
||||||
|
|
||||||
|
provider := dynamo.NewProvider(client)
|
||||||
|
service := tables.NewService(provider)
|
||||||
|
|
||||||
|
state := controllers.NewState()
|
||||||
|
readController := controllers.NewTableReadController(state, service, "alpha-table")
|
||||||
|
writeController := controllers.NewTableWriteController(state, service, readController)
|
||||||
|
|
||||||
|
invokeCommand(t, readController.Init())
|
||||||
|
invokeCommand(t, writeController.ToggleMark(0))
|
||||||
|
invokeCommandWithPrompt(t, writeController.SetAttributeValue(1, models.UnsetItemType, "alpha"), "a brand new value")
|
||||||
|
|
||||||
|
after1 := state.ResultSet().Items()[0]["alpha"].(*types.AttributeValueMemberS).Value
|
||||||
|
assert.Equal(t, "a brand new value", after1)
|
||||||
|
assert.True(t, state.ResultSet().IsDirty(0))
|
||||||
|
assert.False(t, state.ResultSet().IsDirty(1))
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("should change the value to a particular field if already present", func(t *testing.T) {
|
t.Run("should change the value to a particular field if already present", func(t *testing.T) {
|
||||||
client := testdynamo.SetupTestTable(t, testData)
|
client := testdynamo.SetupTestTable(t, testData)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue