test: chain delete-obj cli command
Contains two subtests, that check if the --really-do-it flag (force) is respected, since removing wrong objects may lead to sync issues.
This commit is contained in:
parent
1cd590ace9
commit
c0f47e5eed
@ -220,6 +220,8 @@ var ChainDeleteObjCmd = &cli.Command{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
|
afmt := NewAppFmt(cctx.App)
|
||||||
|
|
||||||
api, closer, err := GetFullNodeAPI(cctx)
|
api, closer, err := GetFullNodeAPI(cctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -241,7 +243,7 @@ var ChainDeleteObjCmd = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Obj %s deleted\n", c.String())
|
afmt.Printf("Obj %s deleted\n", c.String())
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -115,3 +115,36 @@ func TestReadOjb(t *testing.T) {
|
|||||||
|
|
||||||
assert.Equal(t, buf.String(), fmt.Sprintf("%x\n", obj.Bytes()))
|
assert.Equal(t, buf.String(), fmt.Sprintf("%x\n", obj.Bytes()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestChainDeleteObj checks if "chain delete-obj" deletes an object from the chain blockstore, respecting the --really-do-it flag
|
||||||
|
func TestChainDeleteObj(t *testing.T) {
|
||||||
|
cmd := WithCategory("chain", ChainDeleteObjCmd)
|
||||||
|
block := mock.MkBlock(nil, 0, 0)
|
||||||
|
|
||||||
|
// given no force flag, it should return an error and no API calls should be made
|
||||||
|
t.Run("no-really-do-it", func(t *testing.T) {
|
||||||
|
app, _, _, done := newMockAppWithFullAPI(t, cmd)
|
||||||
|
defer done()
|
||||||
|
|
||||||
|
err := app.Run([]string{"chain", "delete-obj", block.Cid().String()})
|
||||||
|
assert.Error(t, err)
|
||||||
|
})
|
||||||
|
|
||||||
|
// given a force flag, API delete should be called
|
||||||
|
t.Run("really-do-it", func(t *testing.T) {
|
||||||
|
app, mockApi, buf, done := newMockAppWithFullAPI(t, cmd)
|
||||||
|
defer done()
|
||||||
|
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
gomock.InOrder(
|
||||||
|
mockApi.EXPECT().ChainDeleteObj(ctx, block.Cid()).Return(nil),
|
||||||
|
)
|
||||||
|
|
||||||
|
err := app.Run([]string{"chain", "delete-obj", "--really-do-it=true", block.Cid().String()})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
assert.Contains(t, buf.String(), block.Cid().String())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user