github.com/projecteru2/core@v0.0.0-20240321043226-06bcc1c23f58/store/etcdv3/pod_test.go (about)

     1  package etcdv3
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/projecteru2/core/types"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestPod(t *testing.T) {
    13  	m := NewMercury(t)
    14  	ctx := context.Background()
    15  	podname := "testv3"
    16  
    17  	pod, err := m.AddPod(ctx, podname, "CPU")
    18  	assert.NoError(t, err)
    19  	assert.Equal(t, pod.Name, podname)
    20  
    21  	_, err = m.AddPod(ctx, podname, "CPU")
    22  	assert.Equal(t, err, types.ErrKeyExists)
    23  
    24  	pod2, err := m.GetPod(ctx, podname)
    25  	assert.NoError(t, err)
    26  	assert.Equal(t, pod2.Name, podname)
    27  
    28  	pods, err := m.GetAllPods(ctx)
    29  	assert.NoError(t, err)
    30  	assert.Equal(t, len(pods), 1)
    31  	assert.Equal(t, pods[0].Name, podname)
    32  
    33  	_, err = m.AddNode(ctx, &types.AddNodeOptions{Nodename: "test", Endpoint: "mock://", Podname: podname})
    34  	assert.NoError(t, err)
    35  	err = m.RemovePod(ctx, podname)
    36  	assert.Error(t, err)
    37  	err = m.RemoveNode(ctx, &types.Node{NodeMeta: types.NodeMeta{Podname: podname, Name: "test", Endpoint: "mock://"}})
    38  	assert.NoError(t, err)
    39  	err = m.RemovePod(ctx, podname)
    40  	assert.NoError(t, err)
    41  }