Add, get and remove an operation.
(t *testing.T)
| 16 | |
| 17 | // Add, get and remove an operation. |
| 18 | func TestOperation(t *testing.T) { |
| 19 | tx, cleanup := db.NewTestClusterTx(t) |
| 20 | defer cleanup() |
| 21 | |
| 22 | projectID, err := cluster.GetProjectID(context.Background(), tx.Tx(), "default") |
| 23 | require.NoError(t, err) |
| 24 | nodeID := tx.GetNodeID() |
| 25 | uuid := "abcd" |
| 26 | |
| 27 | opInfo := cluster.Operation{ |
| 28 | NodeID: nodeID, |
| 29 | Type: operationtype.InstanceCreate, |
| 30 | UUID: uuid, |
| 31 | ProjectID: &projectID, |
| 32 | } |
| 33 | |
| 34 | id, err := cluster.CreateOrReplaceOperation(context.TODO(), tx.Tx(), opInfo) |
| 35 | require.NoError(t, err) |
| 36 | assert.Equal(t, int64(1), id) |
| 37 | |
| 38 | filter := cluster.OperationFilter{NodeID: &nodeID} |
| 39 | operations, err := cluster.GetOperations(context.TODO(), tx.Tx(), filter) |
| 40 | require.NoError(t, err) |
| 41 | assert.Len(t, operations, 1) |
| 42 | assert.Equal(t, operations[0].UUID, "abcd") |
| 43 | |
| 44 | filter = cluster.OperationFilter{UUID: &uuid} |
| 45 | ops, err := cluster.GetOperations(context.TODO(), tx.Tx(), filter) |
| 46 | require.NoError(t, err) |
| 47 | assert.Equal(t, len(ops), 1) |
| 48 | operation := ops[0] |
| 49 | assert.Equal(t, id, operation.ID) |
| 50 | assert.Equal(t, operationtype.InstanceCreate, operation.Type) |
| 51 | |
| 52 | filter = cluster.OperationFilter{NodeID: &nodeID} |
| 53 | ops, err = cluster.GetOperations(context.TODO(), tx.Tx(), filter) |
| 54 | require.NoError(t, err) |
| 55 | assert.Equal(t, "abcd", ops[0].UUID) |
| 56 | |
| 57 | err = cluster.DeleteOperation(context.TODO(), tx.Tx(), "abcd") |
| 58 | require.NoError(t, err) |
| 59 | |
| 60 | filter = cluster.OperationFilter{UUID: &uuid} |
| 61 | ops, err = cluster.GetOperations(context.TODO(), tx.Tx(), filter) |
| 62 | require.NoError(t, err) |
| 63 | assert.Equal(t, len(ops), 0) |
| 64 | } |
| 65 | |
| 66 | // Add, get and remove an operation not associated with any project. |
| 67 | func TestOperationNoProject(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…