mirror of https://github.com/knative/client.git
Fix `domain describe` reference (#1477)
* Fix domain describe reference * Add unit test coverage
This commit is contained in:
parent
03045c8195
commit
2939f36bbd
|
|
@ -88,7 +88,14 @@ func describe(w io.Writer, domainMapping *v1alpha1.DomainMapping, printDetails b
|
|||
commands.WriteMetadata(dw, &domainMapping.ObjectMeta, printDetails)
|
||||
dw.WriteLine()
|
||||
dw.WriteAttribute("URL", domainMapping.Status.URL.String())
|
||||
dw.WriteAttribute("Service", domainMapping.Spec.Ref.Name)
|
||||
dw.WriteLine()
|
||||
ref := dw.WriteAttribute("Reference", "")
|
||||
ref.WriteAttribute("APIVersion", domainMapping.Spec.Ref.APIVersion)
|
||||
ref.WriteAttribute("Kind", domainMapping.Spec.Ref.Kind)
|
||||
ref.WriteAttribute("Name", domainMapping.Spec.Ref.Name)
|
||||
if domainMapping.Namespace != domainMapping.Spec.Ref.Namespace {
|
||||
ref.WriteAttribute("Namespace", domainMapping.Spec.Ref.Namespace)
|
||||
}
|
||||
dw.WriteLine()
|
||||
commands.WriteConditions(dw, domainMapping.Status.Conditions, printDetails)
|
||||
if err := dw.Flush(); err != nil {
|
||||
|
|
|
|||
|
|
@ -42,6 +42,9 @@ func TestDomainMappingDescribe(t *testing.T) {
|
|||
assert.Assert(t, cmp.Regexp("Name:\\s+foo.bar", out))
|
||||
assert.Assert(t, cmp.Regexp("Namespace:\\s+default", out))
|
||||
assert.Assert(t, util.ContainsAll(out, "URL:", "http://foo.bar"))
|
||||
assert.Assert(t, cmp.Regexp("Reference:", out))
|
||||
assert.Assert(t, cmp.Regexp("Kind:\\s+Service", out))
|
||||
assert.Assert(t, cmp.Regexp("Name:\\s+foo", out))
|
||||
assert.Assert(t, util.ContainsAll(out, "Conditions:", "Ready"))
|
||||
|
||||
// There're 2 empty lines used in the "describe" formatting
|
||||
|
|
@ -51,7 +54,27 @@ func TestDomainMappingDescribe(t *testing.T) {
|
|||
lineCounter++
|
||||
}
|
||||
}
|
||||
assert.Equal(t, lineCounter, 2)
|
||||
assert.Equal(t, lineCounter, 3)
|
||||
|
||||
servingRecorder.Validate()
|
||||
}
|
||||
|
||||
func TestDomainMappingDescribeDiffNamespace(t *testing.T) {
|
||||
client := v1alpha1.NewMockKnServiceClient(t)
|
||||
|
||||
servingRecorder := client.Recorder()
|
||||
servingRecorder.GetDomainMapping("foo.bar", getDomainMapping("otherNS"), nil)
|
||||
|
||||
out, err := executeDomainCommand(client, nil, "describe", "foo.bar")
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, cmp.Regexp("Name:\\s+foo.bar", out))
|
||||
assert.Assert(t, cmp.Regexp("Namespace:\\s+default", out))
|
||||
assert.Assert(t, util.ContainsAll(out, "URL:", "http://foo.bar"))
|
||||
assert.Assert(t, cmp.Regexp("Reference:", out))
|
||||
assert.Assert(t, cmp.Regexp("Kind:\\s+Service", out))
|
||||
assert.Assert(t, cmp.Regexp("Name:\\s+foo", out))
|
||||
assert.Assert(t, cmp.Regexp("Namespace:\\s+otherNS", out))
|
||||
assert.Assert(t, util.ContainsAll(out, "Conditions:", "Ready"))
|
||||
|
||||
servingRecorder.Validate()
|
||||
}
|
||||
|
|
@ -68,6 +91,24 @@ func TestDomainMappingDescribeError(t *testing.T) {
|
|||
servingRecorder.Validate()
|
||||
}
|
||||
|
||||
func TestDomainMappingDescribeNameError(t *testing.T) {
|
||||
client := v1alpha1.NewMockKnServiceClient(t)
|
||||
|
||||
servingRecorder := client.Recorder()
|
||||
|
||||
_, err := executeDomainCommand(client, nil, "describe")
|
||||
assert.Assert(t, err != nil)
|
||||
assert.Assert(t, util.ContainsAll(err.Error(), "name", "single", "argument"))
|
||||
|
||||
servingRecorder.Validate()
|
||||
|
||||
_, err = executeDomainCommand(client, nil, "describe", "foo", "bar")
|
||||
assert.Assert(t, err != nil)
|
||||
assert.Assert(t, util.ContainsAll(err.Error(), "name", "single", "argument"))
|
||||
|
||||
servingRecorder.Validate()
|
||||
}
|
||||
|
||||
func TestDomainMappingDescribeURL(t *testing.T) {
|
||||
client := v1alpha1.NewMockKnServiceClient(t)
|
||||
|
||||
|
|
@ -94,11 +135,15 @@ func TestDomainMappingDescribeYAML(t *testing.T) {
|
|||
servingRecorder.Validate()
|
||||
}
|
||||
|
||||
func getDomainMapping() *servingv1alpha1.DomainMapping {
|
||||
dm := createDomainMapping("foo.bar", createServiceRef("foo", "default"), "")
|
||||
func getDomainMapping(ns ...string) *servingv1alpha1.DomainMapping {
|
||||
serviceNamespace := "default"
|
||||
if len(ns) == 1 {
|
||||
serviceNamespace = ns[0]
|
||||
}
|
||||
dm := createDomainMapping("foo.bar", createServiceRef("foo", serviceNamespace), "")
|
||||
dm.TypeMeta = v1.TypeMeta{
|
||||
Kind: "DomainMapping",
|
||||
APIVersion: "serving.knative.dev/v1alpha1",
|
||||
APIVersion: servingv1alpha1.SchemeGroupVersion.String(),
|
||||
}
|
||||
dm.Status = servingv1alpha1.DomainMappingStatus{
|
||||
Status: duckv1.Status{
|
||||
|
|
|
|||
Loading…
Reference in New Issue