Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
This commit is contained in:
Ulysses Souza 2020-05-19 20:03:53 +02:00
Родитель 762f462d80
Коммит d2fece3311
3 изменённых файлов: 3 добавлений и 57 удалений

Просмотреть файл

@ -1,54 +0,0 @@
package run
import (
"fmt"
"strconv"
"strings"
"github.com/docker/api/containers"
)
type runOpts struct {
name string
publish []string
volumes []string
}
func toPorts(ports []string) ([]containers.Port, error) {
var result []containers.Port
for _, port := range ports {
parts := strings.Split(port, ":")
if len(parts) != 2 {
return nil, fmt.Errorf("unable to parse ports %q", port)
}
source, err := strconv.Atoi(parts[0])
if err != nil {
return nil, err
}
destination, err := strconv.Atoi(parts[1])
if err != nil {
return nil, err
}
result = append(result, containers.Port{
HostPort: uint32(source),
ContainerPort: uint32(destination),
})
}
return result, nil
}
func (r *runOpts) toContainerConfig(image string) (containers.ContainerConfig, error) {
publish, err := toPorts(r.publish)
if err != nil {
return containers.ContainerConfig{}, err
}
return containers.ContainerConfig{
ID: r.name,
Image: image,
Ports: publish,
Volumes: r.volumes,
}, nil
}

Просмотреть файл

@ -45,7 +45,7 @@ var (
// ErrNotImplemented is returned when a backend doesn't implement // ErrNotImplemented is returned when a backend doesn't implement
// an action // an action
ErrNotImplemented = errors.New("not implemented") ErrNotImplemented = errors.New("not implemented")
// ErrParsingFailed // ErrParsingFailed is returned when a string cannot be parsed
ErrParsingFailed = errors.New("parsing failed") ErrParsingFailed = errors.New("parsing failed")
) )
@ -74,7 +74,7 @@ func IsErrNotImplemented(err error) bool {
return errors.Is(err, ErrNotImplemented) return errors.Is(err, ErrNotImplemented)
} }
// IsErrParseFail returns true if the unwrapped error is ErrParsingFailed // IsErrParsingFailed returns true if the unwrapped error is ErrParsingFailed
func IsErrParsingFailed(err error) bool { func IsErrParsingFailed(err error) bool {
return errors.Is(err, ErrParsingFailed) return errors.Is(err, ErrParsingFailed)
} }

Просмотреть файл

@ -208,7 +208,7 @@ func uploadFile(credential azfile.SharedKeyCredential, baseURL, fileName, fileCo
fURL, err := url.Parse(baseURL + "/" + fileName) fURL, err := url.Parse(baseURL + "/" + fileName)
Expect(err).To(BeNil()) Expect(err).To(BeNil())
fileURL := azfile.NewFileURL(*fURL, azfile.NewPipeline(&credential, azfile.PipelineOptions{})) fileURL := azfile.NewFileURL(*fURL, azfile.NewPipeline(&credential, azfile.PipelineOptions{}))
err = azfile.UploadBufferToAzureFile(context.TODO(), []byte(testFileContent), fileURL, azfile.UploadToAzureFileOptions{}) err = azfile.UploadBufferToAzureFile(context.TODO(), []byte(fileContent), fileURL, azfile.UploadToAzureFileOptions{})
Expect(err).To(BeNil()) Expect(err).To(BeNil())
} }