Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Vaillancourt <[email protected]>
  • Loading branch information
timvaillancourt committed Dec 17, 2024
1 parent 343f434 commit 54433aa
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions go/vt/vtorc/inst/keyspace_dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package inst

import (
"testing"
"time"

"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -124,3 +125,37 @@ func TestSaveAndReadKeyspace(t *testing.T) {
})
}
}

func TestDeleteStaleKeyspaces(t *testing.T) {
// Clear the database after the test. The easiest way to do that is to run all the initialization commands again.
defer func() {
db.ClearVTOrcDatabase()
}()

keyspaceInfo := &topo.KeyspaceInfo{
Keyspace: &topodatapb.Keyspace{
KeyspaceType: topodatapb.KeyspaceType_NORMAL,
DurabilityPolicy: "none",
BaseKeyspace: "baseKeyspace",
},
}
keyspaceInfo.SetKeyspaceName("ks1")
err := SaveKeyspace(keyspaceInfo)
require.NoError(t, err)

readKeyspaceInfo, err := ReadKeyspace("ks1")
require.NoError(t, err)
require.NotNil(t, readKeyspaceInfo)

// test a staletime before save causes no delete
require.NoError(t, DeleteStaleKeyspaces(time.Now().Add(-time.Hour)))
readKeyspaceInfo, err = ReadKeyspace("ks1")
require.NoError(t, err)
require.NotNil(t, readKeyspaceInfo)

// test statetime of now deletes everything
require.NoError(t, DeleteStaleKeyspaces(time.Now()))
readKeyspaceInfo, err = ReadKeyspace("ks1")
require.Error(t, err)
require.Nil(t, readKeyspaceInfo)
}

0 comments on commit 54433aa

Please sign in to comment.