You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by cs...@apache.org on 2019/01/26 19:16:35 UTC

[incubator-openwhisk-cli] branch master updated: Update README and add action unit test (#402)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 0015b1a  Update README and add action unit test (#402)
0015b1a is described below

commit 0015b1af625774f7904fb0e4d342dbda65dcbe6b
Author: rodric rabbah <ro...@gmail.com>
AuthorDate: Sat Jan 26 14:16:31 2019 -0500

    Update README and add action unit test (#402)
    
    * Update README for running tests with Go and add an action test.
    
    * Bump vendors.
    
    * Update docs for #398.
---
 .gitignore              |  1 +
 README.md               | 24 +++++++++++++++++------
 commands/action_test.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++
 vendor/vendor.json      | 10 +++++-----
 4 files changed, 75 insertions(+), 11 deletions(-)

diff --git a/.gitignore b/.gitignore
index 7ede9b7..bbc885e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,7 @@ wsk
 wsk.exe
 scripts
 Godeps/_workspace
+*~
 
 # IDE-related exclusions
 .idea/
diff --git a/README.md b/README.md
index 665832c..0d597dd 100644
--- a/README.md
+++ b/README.md
@@ -95,7 +95,7 @@ $ ./gradlew compile -PbuildPlatforms=linux-amd64,mac-amd64,windows-amd64
 
 The build library understands most representations of most Operating Systems.
 
-Tests can be run using the Gradle script as well:
+Tests can be run using the Gradle script:
 
 ```
 $ ./gradlew goTest -PgoTags=unit
@@ -127,17 +127,21 @@ $ go get -u github.com/jteeuwen/go-bindata/...
 $ go-bindata -pkg wski18n -o wski18n/i18n_resources.go wski18n/resources
 ```
 
-It is necessary to lock dependencies versions to obtain a
-clean build of wsk. To that end, it's now necessary to populate the `vendors`
-folder using the versions selected in the `vendor/vendor.json`:
+The project includes a `vendor/vendor.json` and you can lock down
+dependencies for a clean build of the CLI by populating the `vendor` folder.
 
-```sh
+```
 $ go get -u github.com/kardianos/govendor         # Install govendor tool
 $ govendor sync     # Download and install packages with specified dependencies.
 ```
 
-Once vendor is populated, it's possible to build the binary:
+NOTE: As a temporary workaround, you have to remove a redundant instance of `spf13/cobra`
+in the vendor folder. See this [issue](https://github.com/apache/incubator-openwhisk-cli/issues/398) for details.
+```
+$ rm -rf vendor/github.com/spf13
+```
 
+Now you can build the binary.
 ```
 $ go build -o wsk
 ```
@@ -155,6 +159,14 @@ $ GOOS=linux GOARCH=amd64 go build -o wsk-$GOOS-$GOARCH
 If it is executed successfully, you can find your binary `wsk` directly under
 OpenWhisk CLI home directory.
 
+You can run unit tests as well (although note the majority of the tests today are not in Go).
+
+```sh
+$ cd commands
+$ go get github.com/stretchr/testify/assert
+$ go test -tags=unit -v
+```
+
 # How to use the binary
 
 When you have the binary, you can copy the binary to any folder, and add folder
diff --git a/commands/action_test.go b/commands/action_test.go
new file mode 100644
index 0000000..fcda9b2
--- /dev/null
+++ b/commands/action_test.go
@@ -0,0 +1,51 @@
+// +build unit
+
+/*
+ * 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 commands
+
+import (
+	"encoding/base64"
+	"github.com/stretchr/testify/assert"
+	"os"
+	"testing"
+)
+
+func TestBallerinaBinaryFile(t *testing.T) {
+	file := "file.balx"
+	args := []string{"name", file}
+	parms := ActionFlags{}
+
+	f, error := os.Create(file)
+	if error != nil {
+		t.Fatalf("could not create file: %s", error.Error())
+	}
+	d := []byte("balx")
+	f.Write(d)
+	f.Close()
+
+	exec, error := getExec(args, parms)
+	os.Remove(file)
+
+	if error != nil {
+		t.Errorf("unexpected exec error: %s", error.Error())
+	} else {
+		assert.Equal(t, exec.Kind, "ballerina:default")
+		assert.Equal(t, base64.StdEncoding.EncodeToString(d), *exec.Code)
+	}
+}
diff --git a/vendor/vendor.json b/vendor/vendor.json
index 4a2176e..5280f55 100644
--- a/vendor/vendor.json
+++ b/vendor/vendor.json
@@ -3,16 +3,16 @@
 	"ignore": "test",
 	"package": [
 		{
-			"checksumSHA1": "ASp79qek5lZJ18lexnxnnw8wQSs=",
+			"checksumSHA1": "krP/Rb7hvLXzwRp+5spDj5WBk9g=",
 			"path": "github.com/apache/incubator-openwhisk-client-go/whisk",
-			"revision": "d7cee96e83a1f38413a1f5286bd524dac72686c9",
-			"revisionTime": "2018-08-03T16:52:51Z"
+			"revision": "41bdfc4b124d7a9e419ba72ab19ce31f01338509",
+			"revisionTime": "2019-01-21T12:59:58Z"
 		},
 		{
 			"checksumSHA1": "4NY5lFykxXaoN+JNMxo179L79sU=",
 			"path": "github.com/apache/incubator-openwhisk-client-go/wski18n",
-			"revision": "d7cee96e83a1f38413a1f5286bd524dac72686c9",
-			"revisionTime": "2018-08-03T16:52:51Z"
+			"revision": "41bdfc4b124d7a9e419ba72ab19ce31f01338509",
+			"revisionTime": "2019-01-21T12:59:58Z"
 		},
 		{
 			"checksumSHA1": "A/DjlgGYOKIkKC8qckZB1shNTFk=",