github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/compute/store/utils_test.go (about)

     1  package store
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/filecoin-project/bacalhau/pkg/model"
     8  	"github.com/google/uuid"
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestValidateNewExecution(t *testing.T) {
    13  	execution := newExecution()
    14  	err := ValidateNewExecution(context.Background(), execution)
    15  	assert.NoError(t, err)
    16  }
    17  
    18  func TestValidateNewExecution_InvalidState(t *testing.T) {
    19  	execution := newExecution()
    20  	execution.State = ExecutionStateBidAccepted
    21  	err := ValidateNewExecution(context.Background(), execution)
    22  	assert.ErrorAs(t, err, &ErrInvalidExecutionState{})
    23  }
    24  
    25  func TestValidateNewExecution_InvalidVersion(t *testing.T) {
    26  	execution := newExecution()
    27  	execution.Version = 2
    28  	err := ValidateNewExecution(context.Background(), execution)
    29  	assert.ErrorAs(t, err, &ErrInvalidExecutionVersion{})
    30  }
    31  
    32  func newExecution() Execution {
    33  	return *NewExecution(
    34  		uuid.NewString(),
    35  		model.JobShard{
    36  			Job: &model.Job{
    37  				Metadata: model.Metadata{
    38  					ID: uuid.NewString(),
    39  				},
    40  			},
    41  			Index: 1,
    42  		},
    43  		"nodeID-1",
    44  		model.ResourceUsageData{
    45  			CPU:    1,
    46  			Memory: 2,
    47  		})
    48  }