-
Notifications
You must be signed in to change notification settings - Fork 255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix client version output with --component option #1408
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dev |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
unknown |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v0.10.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
unknown |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dev |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v0.7.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v0.10.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v0.5.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dev |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v0.7.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v0.10.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
unknown |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dev |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
unknown |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v0.10.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v0.5.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,21 +91,84 @@ func TestVersionGood(t *testing.T) { | |
golden.Assert(t, got, fmt.Sprintf("%s.golden", t.Name())) | ||
} | ||
|
||
func TestComponentVersion(t *testing.T) { | ||
v := clientVersion | ||
defer func() { clientVersion = v }() | ||
func TestGetComponentVersions(t *testing.T) { | ||
pipelineDeploymentLabels := map[string]string{ | ||
"app.kubernetes.io/part-of": "tekton-pipelines", | ||
"app.kubernetes.io/component": "controller", | ||
"app.kubernetes.io/name": "controller", | ||
} | ||
triggersDeploymentLabels := map[string]string{ | ||
"app.kubernetes.io/part-of": "tekton-triggers", | ||
"app.kubernetes.io/component": "controller", | ||
"app.kubernetes.io/name": "controller", | ||
} | ||
dashboardDeploymentLabels := map[string]string{ | ||
"app.kubernetes.io/part-of": "tekton-dashboard", | ||
"app.kubernetes.io/component": "dashboard", | ||
"app.kubernetes.io/name": "dashboard", | ||
} | ||
pipelineDeployment := getDeploymentData("pipeline-dep", "", pipelineDeploymentLabels, map[string]string{"app.kubernetes.io/version": "v0.10.0"}, nil) | ||
triggersDeployment := getDeploymentData("triggers-dep", "", triggersDeploymentLabels, map[string]string{"app.kubernetes.io/version": "v0.5.0"}, nil) | ||
dashboardDeployment := getDeploymentData("dashboard-dep", "", dashboardDeploymentLabels, map[string]string{"app.kubernetes.io/version": "v0.7.0"}, nil) | ||
|
||
t.Run("test_client", func(t *testing.T) {}) | ||
clientVersion = "v1.2.3" | ||
testParams := []struct { | ||
name string | ||
namespace string | ||
userProvidedNamespace string | ||
deployment []*v1.Deployment | ||
goldenFile bool | ||
}{{ | ||
name: "deployment only with pipeline installed", | ||
namespace: "test", | ||
userProvidedNamespace: "test", | ||
deployment: []*v1.Deployment{pipelineDeployment}, | ||
goldenFile: true, | ||
}, { | ||
name: "deployment with pipeline and triggers installed", | ||
namespace: "test", | ||
userProvidedNamespace: "test", | ||
deployment: []*v1.Deployment{pipelineDeployment, triggersDeployment}, | ||
goldenFile: true, | ||
}, { | ||
name: "deployment with pipeline and dashboard installed", | ||
namespace: "test", | ||
userProvidedNamespace: "test", | ||
deployment: []*v1.Deployment{pipelineDeployment, dashboardDeployment}, | ||
goldenFile: true, | ||
}, { | ||
name: "deployment with pipeline, triggers and dashboard installed", | ||
namespace: "test", | ||
userProvidedNamespace: "test", | ||
deployment: []*v1.Deployment{pipelineDeployment, triggersDeployment, dashboardDeployment}, | ||
goldenFile: true, | ||
}, | ||
} | ||
components := []string{"client", "pipeline", "dashboard", "triggers"} | ||
|
||
seedData, _ := test.SeedTestData(t, pipelinetest.Data{}) | ||
for _, tp := range testParams { | ||
t.Run(tp.name, func(t *testing.T) { | ||
for _, c := range components { | ||
seedData, _ := test.SeedTestData(t, pipelinetest.Data{}) | ||
cs := pipelinetest.Clients{Kube: seedData.Kube} | ||
p := &test.Params{Kube: cs.Kube} | ||
version := Command(p) | ||
cls, err := p.Clients() | ||
if err != nil { | ||
t.Errorf("failed to get client: %v", err) | ||
} | ||
// To add multiple deployments in a particular namespace | ||
for _, v := range tp.deployment { | ||
if _, err := cls.Kube.AppsV1().Deployments(tp.namespace).Create(context.Background(), v, metav1.CreateOptions{}); err != nil { | ||
t.Errorf("failed to create deployment: %v", err) | ||
} | ||
} | ||
got, _ := test.ExecuteCommand(version, "version", "-n", "test", "--component", c) | ||
fmt.Println(t.Name()) | ||
golden.Assert(t, got, fmt.Sprintf("%s-%s.golden", t.Name(), c)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of generating golden files can't we just do assert? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tend to agree with @vinamra28, could be a follow-up though 😉 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure. I'll track this in an issue and merge this one 🙂 |
||
} | ||
}) | ||
} | ||
|
||
cs := pipelinetest.Clients{Kube: seedData.Kube} | ||
p := &test.Params{Kube: cs.Kube} | ||
version := Command(p) | ||
got, _ := test.ExecuteCommand(version, "version", "--component", "client") | ||
expected := "v1.2.3\n" | ||
test.AssertOutput(t, expected, got) | ||
} | ||
|
||
func TestVersionBad(t *testing.T) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is right though, because as is,
tkn version --component=pipeline
with a error connecting kubernetes, it will print the client version without an error, which doesn't make sense to me.We should print the client version if the component is
client
, otherwise we should either error out or printunknown
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, my bad.
I will correct it.