github.com/docker/buildx@v0.14.1-0.20240514123050-afcb609966dc/store/nodegroup_test.go (about)

     1  package store
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/docker/buildx/util/platformutil"
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  func TestNodeGroupUpdate(t *testing.T) {
    11  	t.Parallel()
    12  
    13  	ng := &NodeGroup{}
    14  	err := ng.Update("foo", "foo0", []string{"linux/amd64"}, true, false, []string{"--debug"}, "", nil)
    15  	require.NoError(t, err)
    16  
    17  	err = ng.Update("foo1", "foo1", []string{"linux/arm64", "linux/arm/v7"}, true, true, nil, "", nil)
    18  	require.NoError(t, err)
    19  
    20  	require.Equal(t, len(ng.Nodes), 2)
    21  
    22  	// update
    23  	err = ng.Update("foo", "foo2", []string{"linux/amd64", "linux/arm"}, true, false, nil, "", nil)
    24  	require.NoError(t, err)
    25  
    26  	require.Equal(t, len(ng.Nodes), 2)
    27  	require.Equal(t, []string{"linux/amd64", "linux/arm/v7"}, platformutil.Format(ng.Nodes[0].Platforms))
    28  	require.Equal(t, []string{"linux/arm64"}, platformutil.Format(ng.Nodes[1].Platforms))
    29  
    30  	require.Equal(t, "foo2", ng.Nodes[0].Endpoint)
    31  	require.Equal(t, []string{"--debug"}, ng.Nodes[0].BuildkitdFlags)
    32  	require.Equal(t, []string(nil), ng.Nodes[1].BuildkitdFlags)
    33  
    34  	// duplicate endpoint
    35  	err = ng.Update("foo1", "foo2", nil, true, false, nil, "", nil)
    36  	require.Error(t, err)
    37  	require.Contains(t, err.Error(), "duplicate endpoint")
    38  
    39  	err = ng.Leave("foo")
    40  	require.NoError(t, err)
    41  
    42  	require.Equal(t, len(ng.Nodes), 1)
    43  	require.Equal(t, []string{"linux/arm64"}, platformutil.Format(ng.Nodes[0].Platforms))
    44  }