mirror of
https://github.com/openfaas/faasd.git
synced 2025-06-09 00:16:46 +00:00
Review feedback for Labeller
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
parent
a2ea804d2c
commit
8003748b73
@ -14,7 +14,7 @@ import (
|
|||||||
|
|
||||||
"github.com/openfaas/faas-provider/types"
|
"github.com/openfaas/faas-provider/types"
|
||||||
"github.com/openfaas/faasd/pkg"
|
"github.com/openfaas/faasd/pkg"
|
||||||
mock "github.com/openfaas/faasd/pkg/provider"
|
provider "github.com/openfaas/faasd/pkg/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_parseSecret(t *testing.T) {
|
func Test_parseSecret(t *testing.T) {
|
||||||
@ -210,10 +210,9 @@ func TestListSecrets(t *testing.T) {
|
|||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
fakeStore := &mock.FakeLabeller{}
|
labelStore := provider.NewFakeLabeller(tc.labels)
|
||||||
fakeStore.FakeLabels = tc.labels
|
|
||||||
|
|
||||||
handler := MakeSecretHandler(fakeStore, mountPath)
|
handler := MakeSecretHandler(labelStore, mountPath)
|
||||||
|
|
||||||
path := "http://example.com/foo"
|
path := "http://example.com/foo"
|
||||||
if len(tc.namespace) > 0 {
|
if len(tc.namespace) > 0 {
|
||||||
@ -226,29 +225,27 @@ func TestListSecrets(t *testing.T) {
|
|||||||
|
|
||||||
resp := w.Result()
|
resp := w.Result()
|
||||||
if resp.StatusCode != tc.status {
|
if resp.StatusCode != tc.status {
|
||||||
t.Logf("response body: %s", w.Body.String())
|
t.Fatalf("want status: %d, but got: %d", tc.status, resp.StatusCode)
|
||||||
t.Fatalf("expected status: %d, got: %d", tc.status, resp.StatusCode)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK && w.Body.String() != tc.err {
|
if resp.StatusCode != http.StatusOK && w.Body.String() != tc.err {
|
||||||
t.Fatalf("expected error message: %q, got %q", tc.err, w.Body.String())
|
t.Fatalf("want error message: %q, but got %q", tc.err, w.Body.String())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can not read response of list %v", err)
|
t.Fatalf("can't read response of list %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var res []types.Secret
|
var res []types.Secret
|
||||||
err = json.Unmarshal(body, &res)
|
err = json.Unmarshal(body, &res)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can not read response of list %v", err)
|
t.Fatalf("unable to unmarshal %q, error: %v", string(body), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(res, tc.expected) {
|
if !reflect.DeepEqual(res, tc.expected) {
|
||||||
t.Fatalf("expected response: %v, got: %v", tc.expected, res)
|
t.Fatalf("want response: %v, but got: %v", tc.expected, res)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,24 @@ package provider
|
|||||||
|
|
||||||
import "context"
|
import "context"
|
||||||
|
|
||||||
|
// Labeller can return labels for a namespace from containerd.
|
||||||
type Labeller interface {
|
type Labeller interface {
|
||||||
Labels(ctx context.Context, namespace string) (map[string]string, error)
|
Labels(ctx context.Context, namespace string) (map[string]string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
//
|
||||||
* FakeLabeller can be used to fake labels applied on namespace to mark them valid/invalid for openfaas functions
|
// FakeLabeller can be used to fake labels applied on namespace to mark
|
||||||
*/
|
// them valid/invalid for openfaas functions
|
||||||
type FakeLabeller struct {
|
type FakeLabeller struct {
|
||||||
FakeLabels map[string]string
|
labels map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFakeLabeller(labels map[string]string) Labeller {
|
||||||
|
return &FakeLabeller{
|
||||||
|
labels: labels,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *FakeLabeller) Labels(ctx context.Context, namespace string) (map[string]string, error) {
|
func (s *FakeLabeller) Labels(ctx context.Context, namespace string) (map[string]string, error) {
|
||||||
return s.FakeLabels, nil
|
return s.labels, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user