Skip to content

Commit

Permalink
test: add tests for insertion into the new table
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <[email protected]>
  • Loading branch information
GuptaManan100 committed Apr 1, 2024
1 parent 1b41c26 commit d9b7410
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions go/vt/vtorc/logic/topology_recovery_dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package logic

import (
"strconv"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -135,3 +136,35 @@ func TestExpireTableData(t *testing.T) {
})
}
}

func TestInsertRecoveryDetection(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()
}()
ra := &inst.ReplicationAnalysis{
AnalyzedInstanceAlias: "alias-1",
Analysis: inst.ClusterHasNoPrimary,
ClusterDetails: inst.ClusterInfo{
Keyspace: keyspace,
Shard: shard,
},
}
err := InsertRecoveryDetection(ra)
require.NoError(t, err)
require.NotEqual(t, 0, ra.RecoveryId)

var rows []map[string]sqlutils.CellData
err = db.QueryVTOrc("select * from recovery_detection", nil, func(rowMap sqlutils.RowMap) error {
rows = append(rows, rowMap)
return nil
})
require.NoError(t, err)
require.Len(t, rows, 1)
require.EqualValues(t, ra.AnalyzedInstanceAlias, rows[0]["alias"].String)
require.EqualValues(t, ra.Analysis, rows[0]["analysis"].String)
require.EqualValues(t, keyspace, rows[0]["keyspace"].String)
require.EqualValues(t, shard, rows[0]["shard"].String)
require.EqualValues(t, strconv.Itoa(int(ra.RecoveryId)), rows[0]["detection_id"].String)
require.NotEqual(t, "", rows[0]["detection_timestamp"].String)
}

0 comments on commit d9b7410

Please sign in to comment.