-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move logic out of the Configuration container
- It shouldn't be necessary to figure out the namespace if we just pass --version flag - other small improvements - The version will now be printed as Info at startup, to prevent confusion in pipelines. Signed-off-by: Chris <github.account@chrigel.net>
- Loading branch information
Showing
10 changed files
with
179 additions
and
156 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
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,77 @@ | ||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_SplitNamespaceAndImagestream(t *testing.T) { | ||
type args struct { | ||
repo string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
expectedNamespace string | ||
expectedImage string | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "ShouldSplit_NamespaceAndImageName", | ||
args: args{ | ||
repo: "namespace/image", | ||
}, | ||
expectedNamespace: "namespace", | ||
expectedImage: "image", | ||
}, | ||
{ | ||
name: "ShouldReturnActiveNamespace_IfRepoDoesNotContainNamespace", | ||
args: args{ | ||
repo: "image", | ||
}, | ||
expectedNamespace: "currently-active-ns", | ||
expectedImage: "image", | ||
}, | ||
{ | ||
name: "ShouldThrowError_IfRepoDoesNotContainImage", | ||
args: args{ | ||
repo: "namespace/", | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "ShouldThrowError_IfRepoIsInvalid", | ||
args: args{ | ||
repo: "/", | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "ShouldThrowError_IfRepoIsEmpty", | ||
args: args{}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "ShouldIgnore_Registry", | ||
args: args{ | ||
repo: "docker.io/namespace/image", | ||
}, | ||
expectedNamespace: "namespace", | ||
expectedImage: "image", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
config.Namespace = "currently-active-ns" | ||
namespace, image, err := splitNamespaceAndImagestream(tt.args.repo) | ||
if tt.wantErr { | ||
assert.Error(t, err) | ||
return | ||
} | ||
assert.NoError(t, err) | ||
assert.Equal(t, namespace, tt.expectedNamespace) | ||
assert.Equal(t, image, tt.expectedImage) | ||
}) | ||
} | ||
} |
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.