This repository has been archived by the owner on Dec 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #516 from darkowlzz/vm-labels
Add labels to VMs
- Loading branch information
Showing
8 changed files
with
105 additions
and
1 deletion.
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
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
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
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,68 @@ | ||
package metadata | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/weaveworks/gitops-toolkit/pkg/runtime" | ||
api "github.com/weaveworks/ignite/pkg/apis/ignite" | ||
) | ||
|
||
func TestSetLabels(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
obj runtime.Object | ||
labels []string | ||
wantLabels map[string]string | ||
err bool | ||
}{ | ||
{ | ||
name: "nil runtime object", | ||
obj: nil, | ||
err: true, | ||
}, | ||
{ | ||
name: "valid labels", | ||
obj: &api.VM{}, | ||
labels: []string{ | ||
"label1=value1", | ||
"label2=value2", | ||
"label3=", | ||
"label4=value4,label5=value5", | ||
}, | ||
wantLabels: map[string]string{ | ||
"label1": "value1", | ||
"label2": "value2", | ||
"label3": "", | ||
"label4": "value4,label5=value5", | ||
}, | ||
}, | ||
{ | ||
name: "invalid label - key without value", | ||
obj: &api.VM{}, | ||
labels: []string{"key1"}, | ||
err: true, | ||
}, | ||
{ | ||
name: "invalid label - empty name", | ||
obj: &api.VM{}, | ||
labels: []string{"="}, | ||
err: true, | ||
}, | ||
} | ||
|
||
for _, rt := range cases { | ||
t.Run(rt.name, func(t *testing.T) { | ||
err := SetLabels(rt.obj, rt.labels) | ||
if (err != nil) != rt.err { | ||
t.Errorf("expected error %t, actual: %v", rt.err, err) | ||
} | ||
|
||
// Check the values of all the labels. | ||
for k, v := range rt.wantLabels { | ||
if rt.obj.GetLabel(k) != v { | ||
t.Errorf("expected label key %q to have value %q, actual: %q", k, v, rt.obj.GetLabel(k)) | ||
} | ||
} | ||
}) | ||
} | ||
} |