Add command with unit tests

This commit is contained in:
Priya Wadhwa
2018-03-28 13:34:00 -07:00
parent 976afd1992
commit 89400b7410
7 changed files with 484 additions and 1 deletions
+67
View File
@@ -22,6 +22,8 @@ import (
"testing"
)
var testUrl = "https://github.com/GoogleCloudPlatform/runtimes-common/blob/master/LICENSE"
var testEnvReplacement = []struct {
path string
command string
@@ -207,6 +209,39 @@ func Test_DestinationFilepath(t *testing.T) {
}
}
var urlDestFilepathTests = []struct {
url string
cwd string
dest string
expectedDest string
}{
{
url: "https://something/something",
cwd: "/test",
dest: ".",
expectedDest: "/test/something",
},
{
url: "https://something/something",
cwd: "/cwd",
dest: "/test",
expectedDest: "/test",
},
{
url: "https://something/something",
cwd: "/test",
dest: "/dest/",
expectedDest: "/dest/something",
},
}
func Test_UrlDestFilepath(t *testing.T) {
for _, test := range urlDestFilepathTests {
actualDest := URLDestinationFilepath(test.url, test.dest, test.cwd)
testutil.CheckErrorAndDeepEqual(t, false, nil, test.expectedDest, actualDest)
}
}
var matchSourcesTests = []struct {
srcs []string
files []string
@@ -215,6 +250,7 @@ var matchSourcesTests = []struct {
{
srcs: []string{
"pkg/*",
testUrl,
},
files: []string{
"pkg/a",
@@ -226,6 +262,7 @@ var matchSourcesTests = []struct {
expectedFiles: []string{
"pkg/a",
"pkg/b",
testUrl,
},
},
}
@@ -380,6 +417,7 @@ var testResolveSources = []struct {
srcsAndDest: []string{
"context/foo",
"context/b*",
testUrl,
"dest/",
},
expectedMap: map[string][]string{
@@ -393,6 +431,9 @@ var testResolveSources = []struct {
"context/bar/bat",
"context/bar/baz",
},
testUrl: {
testUrl,
},
},
},
}
@@ -403,3 +444,29 @@ func Test_ResolveSources(t *testing.T) {
testutil.CheckErrorAndDeepEqual(t, false, err, test.expectedMap, actualMap)
}
}
var testRemoteUrls = []struct {
url string
valid bool
}{
{
url: testUrl,
valid: true,
},
{
url: "not/real/",
valid: false,
},
{
url: "https://url.com/something/not/real",
valid: false,
},
}
func Test_RemoteUrls(t *testing.T) {
for _, test := range testRemoteUrls {
valid := IsSrcRemoteFileURL(test.url)
testutil.CheckErrorAndDeepEqual(t, false, nil, test.valid, valid)
}
}