-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* only alphanumeric chars and dash are allowed, everything else is re…
…placed with dash * leading and trailing dashes are stripped * added test #240
- Loading branch information
Showing
2 changed files
with
33 additions
and
3 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
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,23 @@ | ||
package fwdport | ||
|
||
import "testing" | ||
|
||
func Test_sanitizeHost(t *testing.T) { | ||
tests := []struct { | ||
contextName string | ||
want string | ||
}{ | ||
{ // This is how Openshift generates context names | ||
contextName: "service-name.namespace.project-name/cluster-name:6443/username", | ||
want: "service-name-namespace-project-name-cluster-name-6443-username", | ||
}, | ||
{contextName: "-----test-----", want: "test"}, | ||
} | ||
for _, tt := range tests { | ||
t.Run("Sanitize hostname generated from context and namespace: "+tt.contextName, func(t *testing.T) { | ||
if got := sanitizeHost(tt.contextName); got != tt.want { | ||
t.Errorf("sanitizeHost() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |