github.com/projecteru2/core@v0.0.0-20240321043226-06bcc1c23f58/strategy/strategy_test.go (about)

     1  package strategy
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func deployedNodes() []Info {
    11  	return []Info{
    12  		{
    13  			Nodename: "n1",
    14  			Capacity: 10,
    15  			Count:    2,
    16  		},
    17  		{
    18  			Nodename: "n2",
    19  			Capacity: 10,
    20  			Count:    3,
    21  		},
    22  		{
    23  			Nodename: "n3",
    24  			Capacity: 10,
    25  			Count:    5,
    26  		},
    27  		{
    28  			Nodename: "n4",
    29  			Capacity: 10,
    30  			Count:    7,
    31  		},
    32  	}
    33  }
    34  
    35  func TestDeploy(t *testing.T) {
    36  	ctx := context.Background()
    37  
    38  	// invalid strategy
    39  	_, err := Deploy(ctx, "invalid", -1, 3, nil, 2)
    40  	assert.Error(t, err)
    41  
    42  	// count < 0
    43  	_, err = Deploy(ctx, "AUTO", -1, 3, nil, 2)
    44  	assert.Error(t, err)
    45  
    46  	Plans["test"] = func(_ context.Context, _ []Info, _, _, _ int) (map[string]int, error) {
    47  		return nil, nil
    48  	}
    49  	_, err = Deploy(ctx, "test", 1, 3, nil, 2)
    50  	assert.NoError(t, err)
    51  }