This repository has been archived by the owner on Dec 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**What** - Update the faas-provider to 0.14.0 - Update the types used in the secrets handler to use the Secret struct from the faas-provider - Remove the FunctionDeleteRequest import so that we can remove the gateway from the vendor list. This decouples the two projects better and removes a dependency change that would require updating the gateway provider version to update this project as well - Test the DeleteHandler - Rename the proivder info variables to use the same names as in faas-netes and faas-containerd, making the info handler code more portable Relates to openfaas/faas-provider#38 Signed-off-by: Lucas Roesler <[email protected]>
- Loading branch information
1 parent
ee713b2
commit bb8b883
Showing
16 changed files
with
244 additions
and
199 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package handlers | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
"net/http/httptest" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/docker/docker/api/types" | ||
"github.com/docker/docker/api/types/swarm" | ||
) | ||
|
||
type fakeServiceDeleter struct { | ||
services []swarm.Service | ||
listErr error | ||
removeErr error | ||
} | ||
|
||
func (s fakeServiceDeleter) ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error) { | ||
return s.services, s.listErr | ||
} | ||
|
||
func (s fakeServiceDeleter) ServiceRemove(ctx context.Context, serviceID string) error { | ||
return s.removeErr | ||
} | ||
|
||
func Test_DeleteHandler(t *testing.T) { | ||
|
||
cases := []struct { | ||
name string | ||
funcName string | ||
services []swarm.Service | ||
listErr error | ||
removeErr error | ||
expectedCode int | ||
}{ | ||
{ | ||
name: "parsing error returns StatusBadRequest", | ||
expectedCode: http.StatusBadRequest, | ||
}, | ||
{ | ||
name: "listing error returns StatusNotFound", | ||
funcName: "test-func", | ||
listErr: errors.New("failed to list functions"), | ||
expectedCode: http.StatusNotFound, | ||
}, | ||
{ | ||
name: "remove error returns StatusInternalServerError", | ||
funcName: "test-func", | ||
services: []swarm.Service{ | ||
{ | ||
ID: "test-func-id", | ||
Spec: swarm.ServiceSpec{ | ||
Annotations: swarm.Annotations{Name: "test-func"}, | ||
TaskTemplate: swarm.TaskSpec{ | ||
ContainerSpec: &swarm.ContainerSpec{ | ||
Labels: map[string]string{"function": "true"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
removeErr: errors.New("failed to delete function"), | ||
expectedCode: http.StatusInternalServerError, | ||
}, | ||
{ | ||
name: "returns Accepted when no errors", | ||
funcName: "test-func", | ||
services: []swarm.Service{ | ||
{ | ||
ID: "test-func-id", | ||
Spec: swarm.ServiceSpec{ | ||
Annotations: swarm.Annotations{Name: "test-func"}, | ||
TaskTemplate: swarm.TaskSpec{ | ||
ContainerSpec: &swarm.ContainerSpec{ | ||
Labels: map[string]string{"function": "true"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expectedCode: http.StatusAccepted, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
client := fakeServiceDeleter{ | ||
listErr: tc.listErr, | ||
removeErr: tc.removeErr, | ||
services: tc.services, | ||
} | ||
handler := DeleteHandler(client) | ||
|
||
payload := fmt.Sprintf(`{"functionName": %q}`, tc.funcName) | ||
|
||
w := httptest.NewRecorder() | ||
r := httptest.NewRequest("POST", "/", strings.NewReader(payload)) | ||
handler(w, r) | ||
|
||
if w.Code != tc.expectedCode { | ||
t.Fatalf("expected status code %d, got %d", tc.expectedCode, w.Code) | ||
} | ||
|
||
}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package handlers | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/openfaas/faas-provider/types" | ||
"net/http/httptest" | ||
"testing" | ||
) | ||
|
||
func Test_InfoHandler(t *testing.T) { | ||
sha := "4b825dc642cb6eb9a060e54bf8d69288fbee4904" | ||
version := "0.0.1" | ||
handler := MakeInfoHandler(version, sha) | ||
w := httptest.NewRecorder() | ||
r := httptest.NewRequest("GET", "/", nil) | ||
handler(w, r) | ||
|
||
resp := types.InfoResponse{} | ||
err := json.Unmarshal(w.Body.Bytes(), &resp) | ||
if err != nil { | ||
t.Fatalf("unexpected error unmarshalling the response") | ||
} | ||
|
||
if resp.Provider != ProviderName { | ||
t.Fatalf("expected provider %q, got %q", ProviderName, resp.Provider) | ||
} | ||
|
||
if resp.Orchestration != OrchestrationIdentifier { | ||
t.Fatalf("expected orchestration %q, got %q", OrchestrationIdentifier, resp.Orchestration) | ||
} | ||
|
||
if resp.Version.SHA != sha { | ||
t.Fatalf("expected orchestration %q, got %q", sha, resp.Version.SHA) | ||
} | ||
|
||
if resp.Version.Release != version { | ||
t.Fatalf("expected release %q, got %q", version, resp.Version.Release) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.