Skip to content
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

feat: [sc-103119] URI is not replacing the spec but merging instead #1541

Merged
merged 3 commits into from
May 3, 2024

Conversation

nvanthao
Copy link
Member

@nvanthao nvanthao commented May 2, 2024

Description, Motivation and Context

Fixes: #1486
Fixes: #1537

Demo: https://asciinema.org/a/657334

Checklist

  • New and existing tests pass locally with introduced changes.
  • Tests for the changes have been added (for bug fixes / features)
  • The commit message(s) are informative and highlight any breaking changes
  • Any documentation required has been added/updated. For changes to https://troubleshoot.sh/ create a PR here

Does this PR introduce a breaking change?

  • Yes
  • No

@nvanthao nvanthao requested a review from a team as a code owner May 2, 2024 02:05
@nvanthao nvanthao requested a review from banjoh May 2, 2024 02:06
@nvanthao nvanthao added the type::feature New feature or request label May 2, 2024
sb, _, err := loadSpecs(ctx, specs, client)
require.NoError(t, err)
assert.NotNil(t, sb.Spec.Collectors[0].Logs)
assert.Nil(t, sb.Spec.Collectors[1].ConfigMap)
Copy link
Member

@banjoh banjoh May 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this ought to be assert.Nil(t, sb.Spec.Collectors[1].ClusterInfo), if replacing the uri into orig in line 118 worked. But it won't work because "$MY_URI" does not exist in your template spec (orig) because it was already templated out by Test_loadSupportBundleSpecsFromURIs test in line 48. var orig is a global variable :(

What you want to do is extract var orig.. into a separate function and use it in your tests like below

func templSpec() string {
	return `
apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
metadata:
  name: sb-1
spec:
  uri: $MY_URI
  collectors:
    - configMap:
        name: kube-root-ca.crt
        namespace: default
`
}

Then use it in your tests like so

orig := strings.ReplaceAll(templSpec(), "$MY_URI", srv.URL)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

many thanks @banjoh! I've updated the tests.

@nvanthao nvanthao requested a review from banjoh May 3, 2024 00:15
@banjoh banjoh merged commit 088f032 into main May 3, 2024
27 checks passed
@banjoh banjoh deleted the gerard/sc-103119/b-merge-uri branch May 3, 2024 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type::feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

URI is not replacing the spec but merging instead
2 participants