You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by da...@apache.org on 2017/09/20 04:55:23 UTC

[incubator-openwhisk-wskdeploy] branch master updated: Move code to misc.go (#500)

This is an automated email from the ASF dual-hosted git repository.

daisyguo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-wskdeploy.git


The following commit(s) were added to refs/heads/master by this push:
     new 8affb3d  Move code to misc.go (#500)
8affb3d is described below

commit 8affb3d005c88e3165dbc8dace2ff986c0113913
Author: David Liu <no...@126.com>
AuthorDate: Wed Sep 20 12:55:21 2017 +0800

    Move code to misc.go (#500)
    
    Rename util_test.go to misc_test.go.
    Add some unitary test code.
---
 utils/contentreader.go               | 63 ------------------------------------
 utils/misc.go                        | 39 ++++++++++++++++++++++
 utils/{util_test.go => misc_test.go} | 20 ++++++++++++
 3 files changed, 59 insertions(+), 63 deletions(-)

diff --git a/utils/contentreader.go b/utils/contentreader.go
deleted file mode 100644
index d93d608..0000000
--- a/utils/contentreader.go
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package utils
-
-import (
-	"io/ioutil"
-	"net/http"
-	"strings"
-)
-
-// agnostic util reader to fetch content from web or local path or potentially other places.
-type ContentReader struct {
-	URLReader
-	LocalReader
-}
-
-type URLReader struct {
-}
-
-func (urlReader *URLReader) ReadUrl(url string) (content []byte, err error) {
-	resp, err := http.Get(url)
-	if err != nil {
-        return content, err
-    }
-	b, err := ioutil.ReadAll(resp.Body)
-    if err != nil {
-        return content, err
-    } else {
-        defer resp.Body.Close()
-    }
-	return b, nil
-}
-
-type LocalReader struct {
-}
-
-func (localReader *LocalReader) ReadLocal(path string) (content []byte, err error) {
-	cont, err := ioutil.ReadFile(path)
-	return cont, err
-}
-
-func Read(url string) (content []byte, err error) {
-	if strings.HasPrefix(url, "http") {
-		return new(ContentReader).URLReader.ReadUrl(url)
-	} else {
-		return new(ContentReader).LocalReader.ReadLocal(url)
-	}
-}
diff --git a/utils/misc.go b/utils/misc.go
index 1c33deb..481407c 100644
--- a/utils/misc.go
+++ b/utils/misc.go
@@ -644,3 +644,42 @@ func GetDeploymentFilePath(projectPath string) string {
 	}
 }
 
+// agnostic util reader to fetch content from web or local path or potentially other places.
+type ContentReader struct {
+	URLReader
+	LocalReader
+}
+
+type URLReader struct {
+}
+
+func (urlReader *URLReader) ReadUrl(url string) (content []byte, err error) {
+	resp, err := http.Get(url)
+	if err != nil {
+		return content, err
+	}
+	b, err := ioutil.ReadAll(resp.Body)
+	if err != nil {
+		return content, err
+	} else {
+		defer resp.Body.Close()
+	}
+	return b, nil
+}
+
+type LocalReader struct {
+}
+
+func (localReader *LocalReader) ReadLocal(path string) (content []byte, err error) {
+	cont, err := ioutil.ReadFile(path)
+	return cont, err
+}
+
+func Read(url string) (content []byte, err error) {
+	if strings.HasPrefix(url, "http") {
+		return new(ContentReader).URLReader.ReadUrl(url)
+	} else {
+		return new(ContentReader).LocalReader.ReadLocal(url)
+	}
+}
+
diff --git a/utils/util_test.go b/utils/misc_test.go
similarity index 80%
rename from utils/util_test.go
rename to utils/misc_test.go
index afe5ae4..638468c 100644
--- a/utils/util_test.go
+++ b/utils/misc_test.go
@@ -79,3 +79,23 @@ func TestDependencies(t *testing.T) {
 	assert.Equal(t, "http://github.com/user/repo", record.BaseRepo, "BaseRepo is wrong")
 	assert.Equal(t, "/subfolder1/subfolder2", record.SubFolder, "SubFolder is wrong")
 }
+
+func TestParseOpenWhisk(t *testing.T) {
+	openwhiskHost := "https://openwhisk.ng.bluemix.net"
+    openwhisk, err := ParseOpenWhisk(openwhiskHost)
+    assert.Equal(t, nil, err, "parse openwhisk info error happened.")
+    converted := ConvertToMap(openwhisk)
+    assert.Equal(t, 1, len(converted["nodejs"]), "not expected length")
+    assert.Equal(t, 1, len(converted["php"]),  "not expected length")
+    assert.Equal(t, 1, len(converted["java"]), "not expected length")
+    assert.Equal(t, 3, len(converted["python"]), "not expected length")
+    assert.Equal(t, 2, len(converted["swift"]), "not expected length")
+}
+
+func TestNewZipWritter(t *testing.T) {
+    filePath := "../tests/src/integration/zipaction/actions/cat"
+    zipName := filePath + ".zip"
+    err := NewZipWritter(filePath, zipName).Zip()
+    defer os.Remove(zipName)
+    assert.Equal(t, nil, err, "zip folder error happened.")
+}

-- 
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>'].