Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ TEST_SECRETS = \

export TEST_FUNCTIONS TEST_SECRETS

.PHONY: lint
lint: ## Verifies `golangci-lint` passes
@echo "+ $@"
@golangci-lint run ./...


clean-kubernetes:
- ./contrib/clean_kubernetes.sh
Expand Down
15 changes: 4 additions & 11 deletions tests/function_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package tests
import (
"context"
"fmt"
"net/http"
"os"
"path"
"testing"

sdk "github.com/openfaas/faas-cli/proxy"
Expand Down Expand Up @@ -68,17 +66,12 @@ func deleteFunction(t *testing.T, function *sdk.DeployFunctionSpec) {
}
}

func scaleFunction(t *testing.T, name string, count int) {
func scaleFunction(t *testing.T, name, namespace string, count uint64) {
t.Helper()

// the CLI sdk does not currently support manually scaling
gwURL := resourceURL(t, path.Join("system", "scale-function", name), "")
payload := makeReader(map[string]interface{}{"service": name, "replicas": count})

// TODO : enable auth
_, res := request(t, gwURL, http.MethodPost, config.Auth, payload)
if res.StatusCode != http.StatusAccepted && res.StatusCode != http.StatusOK {
t.Fatalf("scale got %d, wanted %d (or %d)", res.StatusCode, http.StatusAccepted, http.StatusOK)
err := config.Client.ScaleFunction(context.Background(), name, namespace, count)
if err != nil {
t.Fatalf("scale got %s", err)
}
}

Expand Down
7 changes: 0 additions & 7 deletions tests/http_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package tests

import (
"bytes"
"context"
"encoding/json"
"io"
"io/ioutil"
"net/http"
Expand All @@ -28,11 +26,6 @@ func resourceURL(t *testing.T, reqPath, query string) string {
return uri.String()
}

func makeReader(input interface{}) *bytes.Buffer {
res, _ := json.Marshal(input)
return bytes.NewBuffer(res)
}

func request(t *testing.T, url, method string, auth sdk.ClientAuth, reader io.Reader) ([]byte, *http.Response) {
t.Helper()
return requestContext(t, context.Background(), url, method, auth, reader)
Expand Down
13 changes: 13 additions & 0 deletions tests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/url"
"os"
"path/filepath"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -108,6 +109,8 @@ type Config struct {
// AuthEnabled
AuthEnabled bool

IdlerEnabled bool

// SecretUpdate enables/disables the secret update test
SecretUpdate bool
// ScaleToZero enables/disables the scale from zero test
Expand Down Expand Up @@ -148,4 +151,14 @@ func FromEnv(config *Config) {
} else {
config.DefaultNamespace = "openfaas-fn"
}

idlerEnabled, ok := os.LookupEnv("idler_enabled")
if ok && idlerEnabled != "" {
enableTest, err := strconv.ParseBool(idlerEnabled)
if err != nil {
log.Fatalf("can parse idler_enabled env flag: %s", err.Error())
}

config.IdlerEnabled = enableTest
}
}
Loading