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.
Store stack.yml annotation meta data in deploy, update and read handlers Relates to openfaas/faas#682 Signed-off-by: Edward Wilde <[email protected]>
- Loading branch information
Showing
8 changed files
with
235 additions
and
30 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
faas-swarm | ||
.idea |
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,85 @@ | ||
package handlers | ||
|
||
import ( | ||
"testing" | ||
"github.com/openfaas/faas/gateway/requests" | ||
"fmt" | ||
) | ||
|
||
func Test_BuildLabels_Defaults(t *testing.T) { | ||
request := &requests.CreateFunctionRequest {} | ||
val, err := buildLabels(request) | ||
|
||
if err != nil { | ||
t.Fatalf("want: no error got: %v", err) | ||
} | ||
|
||
if len(val) != 2 { | ||
t.Errorf("want: %d entries in label map got: %d", 2, len(val)) | ||
} | ||
|
||
if _, ok := val["com.openfaas.function"]; !ok { | ||
t.Errorf("want: '%s' entry in label map got: key not found", "com.openfaas.function") | ||
} | ||
|
||
if _, ok := val["function"]; !ok { | ||
t.Errorf("want: '%s' entry in label map got: key not found", "function") | ||
} | ||
} | ||
|
||
func Test_BuildLabels_WithAnnotations(t *testing.T) { | ||
request := &requests.CreateFunctionRequest { | ||
Labels : &map[string]string{"function_name": "echo"}, | ||
Annotations: &map[string]string{"current-time": "Wed 25 Jul 06:41:43 BST 2018"}, | ||
} | ||
|
||
val, err := buildLabels(request) | ||
|
||
if err != nil { | ||
t.Fatalf("want: no error got: %v", err) | ||
} | ||
|
||
if len(val) != 4 { | ||
t.Errorf("want: %d entries in combined label annotation map got: %d", 4, len(val)) | ||
} | ||
|
||
if _, ok := val[fmt.Sprintf("%scurrent-time", annotationLabelPrefix)]; !ok { | ||
t.Errorf("want: '%s' entry in combined label annotation map got: key not found", "annotation: current-time") | ||
} | ||
} | ||
|
||
func Test_BuildLabels_NoAnnotations(t *testing.T) { | ||
request := &requests.CreateFunctionRequest { | ||
Labels : &map[string]string{"function_name": "echo"}, | ||
} | ||
|
||
val, err := buildLabels(request) | ||
|
||
if err != nil { | ||
t.Fatalf("want: no error got: %v", err) | ||
} | ||
|
||
if len(val) != 3 { | ||
t.Errorf("want: %d entries in combined label annotation map got: %d", 3, len(val)) | ||
} | ||
|
||
if _, ok := val["function_name"]; !ok { | ||
t.Errorf("want: '%s' entry in combined label annotation map got: key not found", "function_name") | ||
} | ||
} | ||
|
||
func Test_BuildLabels_KeyClash(t *testing.T) { | ||
request := &requests.CreateFunctionRequest{ | ||
Labels: & map[string]string{ | ||
"function_name": "echo", | ||
fmt.Sprintf("%scurrent-time", annotationLabelPrefix): "foo", | ||
}, | ||
Annotations: &map[string]string{"current-time": "Wed 25 Jul 06:41:43 BST 2018"}, | ||
} | ||
|
||
_, err := buildLabels(request) | ||
|
||
if err == nil { | ||
t.Fatal("want: an error got: nil") | ||
} | ||
} |
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,63 @@ | ||
package handlers | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func Test_BuildLabelsAndAnnotationsFromServiceSpec_NoLabels(t *testing.T) { | ||
container := make(map[string]string) | ||
|
||
labels, annotation := buildLabelsAndAnnotations(container) | ||
|
||
if len(labels) != 0 { | ||
t.Errorf("want: %d entries labels got: %d", 0, len(labels)) | ||
} | ||
|
||
if len(annotation) != 0 { | ||
t.Errorf("want: %d entries annotations got: %d", 0, len(annotation)) | ||
} | ||
} | ||
|
||
func Test_BuildLabelsAndAnnotationsFromServiceSpec_Labels(t *testing.T) { | ||
container := map[string]string{ | ||
"foo": "baa", | ||
"fizz": "buzz", | ||
} | ||
|
||
labels, annotation := buildLabelsAndAnnotations(container) | ||
|
||
if len(labels) != 2 { | ||
t.Errorf("want: %d labels got: %d", 2, len(labels)) | ||
} | ||
|
||
if len(annotation) != 0 { | ||
t.Errorf("want: %d annotations got: %d", 0, len(annotation)) | ||
} | ||
|
||
if _, ok := labels["fizz"]; !ok { | ||
t.Errorf("want: '%s' entry in label map got: key not found", "fizz") | ||
} | ||
} | ||
|
||
func Test_BuildLabelsAndAnnotationsFromServiceSpec_Annotations(t *testing.T) { | ||
container := map[string]string{ | ||
"foo": "baa", | ||
"fizz": "buzz", | ||
fmt.Sprintf("%scurrent-time", annotationLabelPrefix): "Wed 25 Jul 07:10:34 BST 2018", | ||
} | ||
|
||
labels, annotation := buildLabelsAndAnnotations(container) | ||
|
||
if len(labels) != 2 { | ||
t.Errorf("want: %d labels got: %d", 2, len(labels)) | ||
} | ||
|
||
if len(annotation) != 1 { | ||
t.Errorf("want: %d annotation got: %d", 1, len(annotation)) | ||
} | ||
|
||
if _, ok := annotation[fmt.Sprintf("%scurrent-time", annotationLabelPrefix)]; !ok { | ||
t.Errorf("want: '%s' entry in annotation map got: key not found", "current-time") | ||
} | ||
} |
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