1
0
mirror of https://github.com/rancher/os.git synced 2025-08-31 22:32:14 +00:00

move dependencies to vendor

This commit is contained in:
Ivan Mikushin
2015-11-26 17:37:01 +05:00
parent 63d7de67cd
commit 1d691cd8d6
2232 changed files with 154499 additions and 9037 deletions

30
vendor/github.com/docker/libcompose/lookup/file.go generated vendored Normal file
View File

@@ -0,0 +1,30 @@
package lookup
import (
"io/ioutil"
"path"
"strings"
"github.com/Sirupsen/logrus"
)
// FileConfigLookup is a "bare" structure that implements the project.ConfigLookup interface
type FileConfigLookup struct {
}
// Lookup returns the content and the actual filename of the file that is "built" using the
// specified file and relativeTo string. file and relativeTo are supposed to be file path.
// If file starts with a slash ('/'), it tries to load it, otherwise it will build a
// filename using the folder part of relativeTo joined with file.
func (f *FileConfigLookup) Lookup(file, relativeTo string) ([]byte, string, error) {
if strings.HasPrefix(file, "/") {
logrus.Debugf("Reading file %s", file)
bytes, err := ioutil.ReadFile(file)
return bytes, file, err
}
fileName := path.Join(path.Dir(relativeTo), file)
logrus.Debugf("Reading file %s relative to %s", fileName, relativeTo)
bytes, err := ioutil.ReadFile(fileName)
return bytes, fileName, err
}

View File

@@ -0,0 +1,65 @@
package lookup
import (
"io/ioutil"
"path/filepath"
"testing"
)
type input struct {
file string
relativeTo string
}
func TestLookupError(t *testing.T) {
invalids := map[input]string{
input{"", ""}: "read .: is a directory",
input{"", "/tmp/"}: "read /tmp: is a directory",
input{"file", "/does/not/exists/"}: "open /does/not/exists/file: no such file or directory",
input{"file", "/does/not/something"}: "open /does/not/file: no such file or directory",
input{"file", "/does/not/exists/another"}: "open /does/not/exists/file: no such file or directory",
input{"/does/not/exists/file", "/tmp/"}: "open /does/not/exists/file: no such file or directory",
input{"does/not/exists/file", "/tmp/"}: "open /tmp/does/not/exists/file: no such file or directory",
}
fileConfigLookup := FileConfigLookup{}
for invalid, expectedError := range invalids {
_, _, err := fileConfigLookup.Lookup(invalid.file, invalid.relativeTo)
if err == nil || err.Error() != expectedError {
t.Fatalf("Expected error with '%s', got '%v'", expectedError, err)
}
}
}
func TestLookupOK(t *testing.T) {
tmpFolder, err := ioutil.TempDir("", "lookup-tests")
if err != nil {
t.Fatal(err)
}
tmpFile1 := filepath.Join(tmpFolder, "file1")
tmpFile2 := filepath.Join(tmpFolder, "file2")
if err = ioutil.WriteFile(tmpFile1, []byte("content1"), 0755); err != nil {
t.Fatal(err)
}
if err = ioutil.WriteFile(tmpFile2, []byte("content2"), 0755); err != nil {
t.Fatal(err)
}
fileConfigLookup := FileConfigLookup{}
valids := map[input]string{
input{"file1", tmpFolder + "/"}: "content1",
input{"file2", tmpFolder + "/"}: "content2",
input{tmpFile1, tmpFolder}: "content1",
input{tmpFile1, "/does/not/exists"}: "content1",
input{"file2", tmpFile1}: "content2",
}
for valid, expectedContent := range valids {
out, _, err := fileConfigLookup.Lookup(valid.file, valid.relativeTo)
if err != nil || string(out) != expectedContent {
t.Fatalf("Expected %s to contains '%s', got %s, %v.", valid.file, expectedContent, out, err)
}
}
}

View File

@@ -0,0 +1,24 @@
package lookup
import (
"fmt"
"os"
"github.com/docker/libcompose/project"
)
// OsEnvLookup is a "bare" structure that implements the project.EnvironmentLookup interface
type OsEnvLookup struct {
}
// Lookup creates a string slice of string containing a "docker-friendly" environment string
// in the form of 'key=value'. It gets environment values using os.Getenv.
// If the os environment variable does not exists, the slice is empty. serviceName and config
// are not used at all in this implementation.
func (o *OsEnvLookup) Lookup(key, serviceName string, config *project.ServiceConfig) []string {
ret := os.Getenv(key)
if ret == "" {
return []string{}
}
return []string{fmt.Sprintf("%s=%s", key, ret)}
}

View File

@@ -0,0 +1,31 @@
package lookup
import (
"testing"
"github.com/docker/libcompose/project"
)
func TestOsEnvLookup(t *testing.T) {
// Putting bare minimun value for serviceName and config as there are
// not important on this test.
serviceName := "anything"
config := &project.ServiceConfig{}
osEnvLookup := &OsEnvLookup{}
envs := osEnvLookup.Lookup("PATH", serviceName, config)
if len(envs) != 1 {
t.Fatalf("Expected envs to contains one element, but was %v", envs)
}
envs = osEnvLookup.Lookup("path", serviceName, config)
if len(envs) != 0 {
t.Fatalf("Expected envs to be empty, but was %v", envs)
}
envs = osEnvLookup.Lookup("DOES_NOT_EXIST", serviceName, config)
if len(envs) != 0 {
t.Fatalf("Expected envs to be empty, but was %v", envs)
}
}