|
|
@@ -17,65 +17,31 @@
|
|
|
package convert
|
|
|
|
|
|
import (
|
|
|
+ "strconv"
|
|
|
"testing"
|
|
|
|
|
|
"github.com/compose-spec/compose-go/types"
|
|
|
"gotest.tools/v3/assert"
|
|
|
)
|
|
|
|
|
|
-const (
|
|
|
- storageAccountNameKey = "storage_account_name"
|
|
|
- shareNameKey = "share_name"
|
|
|
-)
|
|
|
-
|
|
|
func TestGetRunVolumes(t *testing.T) {
|
|
|
volumeStrings := []string{
|
|
|
"myuser1/myshare1:/my/path/to/target1",
|
|
|
- "myuser2/myshare2:/my/path/to/target2",
|
|
|
- "myuser3/mydefaultsharename", // Use default placement at '/run/volumes/<share_name>'
|
|
|
+ "myuser2/myshare2:/my/path/to/target2:ro",
|
|
|
+ "myuser3/myshare3:/my/path/to/target3:rw",
|
|
|
+ "myuser4/mydefaultsharename", // Use default placement at '/run/volumes/<share_name>'
|
|
|
}
|
|
|
var goldenVolumeConfigs = map[string]types.VolumeConfig{
|
|
|
- "volume-0": {
|
|
|
- Name: "volume-0",
|
|
|
- Driver: "azure_file",
|
|
|
- DriverOpts: map[string]string{
|
|
|
- storageAccountNameKey: "myuser1",
|
|
|
- shareNameKey: "myshare1",
|
|
|
- },
|
|
|
- },
|
|
|
- "volume-1": {
|
|
|
- Name: "volume-1",
|
|
|
- Driver: "azure_file",
|
|
|
- DriverOpts: map[string]string{
|
|
|
- storageAccountNameKey: "myuser2",
|
|
|
- shareNameKey: "myshare2",
|
|
|
- },
|
|
|
- },
|
|
|
- "volume-2": {
|
|
|
- Name: "volume-2",
|
|
|
- Driver: "azure_file",
|
|
|
- DriverOpts: map[string]string{
|
|
|
- storageAccountNameKey: "myuser3",
|
|
|
- shareNameKey: "mydefaultsharename",
|
|
|
- },
|
|
|
- },
|
|
|
+ "volume-0": getAzurefileVolumeConfig("volume-0", "myuser1", "myshare1", false),
|
|
|
+ "volume-1": getAzurefileVolumeConfig("volume-1", "myuser2", "myshare2", true),
|
|
|
+ "volume-2": getAzurefileVolumeConfig("volume-2", "myuser3", "myshare3", false),
|
|
|
+ "volume-3": getAzurefileVolumeConfig("volume-3", "myuser4", "mydefaultsharename", false),
|
|
|
}
|
|
|
goldenServiceVolumeConfigs := []types.ServiceVolumeConfig{
|
|
|
- {
|
|
|
- Type: "azure_file",
|
|
|
- Source: "volume-0",
|
|
|
- Target: "/my/path/to/target1",
|
|
|
- },
|
|
|
- {
|
|
|
- Type: "azure_file",
|
|
|
- Source: "volume-1",
|
|
|
- Target: "/my/path/to/target2",
|
|
|
- },
|
|
|
- {
|
|
|
- Type: "azure_file",
|
|
|
- Source: "volume-2",
|
|
|
- Target: "/run/volumes/mydefaultsharename",
|
|
|
- },
|
|
|
+ getServiceVolumeConfig("volume-0", "/my/path/to/target1", false),
|
|
|
+ getServiceVolumeConfig("volume-1", "/my/path/to/target2", true),
|
|
|
+ getServiceVolumeConfig("volume-2", "/my/path/to/target3", false),
|
|
|
+ getServiceVolumeConfig("volume-3", "/run/volumes/mydefaultsharename", false),
|
|
|
}
|
|
|
|
|
|
volumeConfigs, serviceVolumeConfigs, err := GetRunVolumes(volumeStrings)
|
|
|
@@ -102,3 +68,29 @@ func TestGetRunVolumesNoShare(t *testing.T) {
|
|
|
_, _, err := GetRunVolumes([]string{"noshare"})
|
|
|
assert.ErrorContains(t, err, "does not include a storage account before '/'")
|
|
|
}
|
|
|
+
|
|
|
+func TestGetRunVolumesInvalidOption(t *testing.T) {
|
|
|
+ _, _, err := GetRunVolumes([]string{"myuser4/myshare4:/my/path/to/target4:invalid"})
|
|
|
+ assert.ErrorContains(t, err, `volume specification "myuser4/myshare4:/my/path/to/target4:invalid" has an invalid mode "invalid"`)
|
|
|
+}
|
|
|
+
|
|
|
+func getServiceVolumeConfig(source string, target string, readOnly bool) types.ServiceVolumeConfig {
|
|
|
+ return types.ServiceVolumeConfig{
|
|
|
+ Type: "azure_file",
|
|
|
+ Source: source,
|
|
|
+ Target: target,
|
|
|
+ ReadOnly: readOnly,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func getAzurefileVolumeConfig(name string, accountNameKey string, shareNameKey string, readOnly bool) types.VolumeConfig {
|
|
|
+ return types.VolumeConfig{
|
|
|
+ Name: name,
|
|
|
+ Driver: "azure_file",
|
|
|
+ DriverOpts: map[string]string{
|
|
|
+ volumeDriveroptsAccountNameKey: accountNameKey,
|
|
|
+ volumeDriveroptsShareNameKey: shareNameKey,
|
|
|
+ volumeReadOnly: strconv.FormatBool(readOnly),
|
|
|
+ },
|
|
|
+ }
|
|
|
+}
|