summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2021-07-16 18:07:01 +0200
committerJon Bratseth <bratseth@gmail.com>2021-07-16 18:07:01 +0200
commit29663060c492c128b6ab3409634d311535ff9602 (patch)
tree3caed484a6d0fe2adb72dff5cd2380b6ce5aa863 /client
parentbe3b8b5e549d9cfafe9b2d3855965a81199d423f (diff)
Add unit testing
Diffstat (limited to 'client')
-rwxr-xr-xclient/go/build.sh1
-rw-r--r--client/go/src/github.com/vespa-engine/vespa/cmd/deploy.go9
-rw-r--r--client/go/src/github.com/vespa-engine/vespa/cmd/status.go2
-rw-r--r--client/go/src/github.com/vespa-engine/vespa/utils/http.go25
-rw-r--r--client/go/src/github.com/vespa-engine/vespa/utils/http_test.go28
5 files changed, 57 insertions, 8 deletions
diff --git a/client/go/build.sh b/client/go/build.sh
index 1812e60dcb5..cc3355827b8 100755
--- a/client/go/build.sh
+++ b/client/go/build.sh
@@ -3,4 +3,5 @@
# Execute from this directory to build the command-line client to bin/vespa
export GOPATH=`pwd`
cd "$GOPATH/src/github.com/vespa-engine/vespa"
+go test ./...
go install
diff --git a/client/go/src/github.com/vespa-engine/vespa/cmd/deploy.go b/client/go/src/github.com/vespa-engine/vespa/cmd/deploy.go
index edee85fdf96..ea50dadff66 100644
--- a/client/go/src/github.com/vespa-engine/vespa/cmd/deploy.go
+++ b/client/go/src/github.com/vespa-engine/vespa/cmd/deploy.go
@@ -3,7 +3,7 @@ package cmd
import (
"github.com/spf13/cobra"
- // "github.com/vespa-engine/vespa/utils"
+ "github.com/vespa-engine/vespa/utils"
)
func init() {
@@ -11,7 +11,7 @@ func init() {
}
var deployCmd = &cobra.Command{
- Use: "deploy",
+ Use: "deploy application-package-dir OR application.zip",
Short: "Deploys an application package",
Long: `TODO`,
Run: func(cmd *cobra.Command, args []string) {
@@ -20,6 +20,9 @@ var deployCmd = &cobra.Command{
}
func deploy() {
-
+ // (cd src/main/application && zip -r - .) | \
+ // curl --header Content-Type:application/zip --data-binary @- \
+ // localhost:19071/application/v2/tenant/default/prepareandactivate
+ utils.HttpRequest("http://127.0.0.1:19071", "/application/v2/tenant/default/prepareandactivate", "Config server")
}
diff --git a/client/go/src/github.com/vespa-engine/vespa/cmd/status.go b/client/go/src/github.com/vespa-engine/vespa/cmd/status.go
index 47be28813d7..ddda71ff0b2 100644
--- a/client/go/src/github.com/vespa-engine/vespa/cmd/status.go
+++ b/client/go/src/github.com/vespa-engine/vespa/cmd/status.go
@@ -7,7 +7,7 @@ import (
)
func init() {
- rootCmd.AddCommand(statusCmd)
+ rootCmd.AddCommand(statusCmd)
statusCmd.AddCommand(statusContainerCmd)
statusCmd.AddCommand(statusConfigServerCmd)
}
diff --git a/client/go/src/github.com/vespa-engine/vespa/utils/http.go b/client/go/src/github.com/vespa-engine/vespa/utils/http.go
index 981f0d2d7e1..df5163de1a0 100644
--- a/client/go/src/github.com/vespa-engine/vespa/utils/http.go
+++ b/client/go/src/github.com/vespa-engine/vespa/utils/http.go
@@ -8,11 +8,28 @@ import (
"time"
)
-func HttpRequest(host string, path string, description string) (response *http.Response) {
- client := &http.Client{
- Timeout: time.Second * 10,
+var httpClient = CreateClient()
+
+type HttpClient interface {
+ get(url string) (response *http.Response, error error)
+}
+
+type defaultHttpClient struct {
+ client http.Client
+}
+
+func (c defaultHttpClient) get(url string) (response *http.Response, error error) {
+ return c.client.Get(url)
+}
+
+func CreateClient() (client HttpClient) {
+ return &defaultHttpClient{
+ client: http.Client{Timeout: time.Second * 10,},
}
- response, error := client.Get(host + path)
+}
+
+func HttpRequest(host string, path string, description string) (response *http.Response) {
+ response, error := httpClient.get(host + path)
if error != nil {
Error("Could not connect to", strings.ToLower(description), "at", host)
Detail(error.Error())
diff --git a/client/go/src/github.com/vespa-engine/vespa/utils/http_test.go b/client/go/src/github.com/vespa-engine/vespa/utils/http_test.go
new file mode 100644
index 00000000000..cbb7d68daad
--- /dev/null
+++ b/client/go/src/github.com/vespa-engine/vespa/utils/http_test.go
@@ -0,0 +1,28 @@
+package utils
+
+import (
+ "bytes"
+ "io/ioutil"
+ "net/http"
+ "testing"
+)
+
+type mockHttpClient struct {}
+
+func (c mockHttpClient) get(url string) (response *http.Response, error error) {
+ return &http.Response{
+ StatusCode: 200,
+ Body: ioutil.NopCloser(bytes.NewBufferString(`OK`)),
+ Header: make(http.Header),
+ },
+ nil
+}
+
+func TestHttpRequest(t *testing.T) {
+ httpClient = mockHttpClient{}
+ response := HttpRequest("http://host", "/path", "description")
+ if (response.StatusCode != 200) {
+ t.Errorf("Status is not 200")
+ }
+}
+