// Copyright 2024 Matthew Rich . All rights reserved. package resource import ( "context" "decl/tests/mocks" "github.com/docker/docker/api/types/volume" "github.com/stretchr/testify/assert" "testing" ) func TestNewContainerVolumeResource(t *testing.T) { c := NewContainerVolume(&mocks.MockContainerClient{}) assert.NotNil(t, c) } func TestReadContainerVolume(t *testing.T) { ctx := context.Background() decl := ` name: "testcontainervolume" state: present ` m := &mocks.MockContainerClient{ InjectVolumeList: func(ctx context.Context, options volume.ListOptions) (volume.ListResponse, error) { return volume.ListResponse{ Volumes: []*volume.Volume{}, Warnings: []string{}, }, nil }, InjectVolumeInspect: func(ctx context.Context, volumeID string) (volume.Volume, error) { return volume.Volume{ Name: "test", Driver: "local", Mountpoint: "/src", }, nil }, } v := NewContainerVolume(m) assert.NotNil(t, v) e := v.LoadDecl(decl) assert.Nil(t, e) assert.Equal(t, "testcontainervolume", v.Name) resourceYaml, readContainerVolumeErr := v.Read(ctx) assert.Equal(t, nil, readContainerVolumeErr) assert.Greater(t, len(resourceYaml), 0) }