-
-
Notifications
You must be signed in to change notification settings - Fork 650
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
Add -tags
flag to ginkgo generate
command
#1213
Comments
hey - happy to pull this in if you submit a PR. out of curiosity - what are the reasons for preferring build tags over labels? |
Great, thanks :)
To be honest, I didn't know about labels (good to know 😅). I started using ginkgo a few weeks ago, so I'm not experienced with it. Basically, we are using tags to select the values, not the tests. That's more or less the idea we had. |
hey @alegrey91 your approach works and makes sense to me - some of this is naturally subjective as there are multiple ways to solve for this sort of thing. If you never expect to run against multiple targets at once (e.g. in parallel) then your approach of doing it at compile time makes sense. I would, personally, opt for a run-time solution using labels as it would allow me to potentially run a single suite against multiple infrastructure targets in parallel simultaneously. if you're interested i can share an example of how to wire things up. either way, though, i'd be happy to accept the PR you're proposing. |
Thanks :)
Sure I'm interested! We are going to release the e2e tests in few days, but this could be helpful for future improvements and also for my personal knowledge :)
Yeh, I would like to contribute anyway. We are going to use this feature for some time at least. |
Circling back to this - there are a variety of ways to approach this to enable multiple providers and/or runtime-selection of providers vs compile-time. Here's one that comes to mind: const AKS = "aks"
const KIND = "kind"
var PROVIDERS = []string{AKS, KIND}
var KUBELET_INFOS = map[string]*sensor.KubeletInfo{
AKS: &sensor.KubeletInfo{...},
KIND: &sensor.KubeletInfo{...},
}
var _ = Describe("Kubeletinfo", func() {
var (
res *http.Response
err error
resBody []byte
)
for _, provider := range PROVIDERS {
kubeletInfo := KUBELET_INFOS[provider]
Context("testing /kubeletinfo endpoint", Label(provider), Ordered, func() {
It("should respond to a GET request", func() {
requestURL := url + "/kubeletinfo"
res, err = http.Get(requestURL)
Expect(err).ToNot(HaveOccurred())
})
It("should return a 200 status code", func() {
Expect(res.StatusCode).To(BeEquivalentTo(200))
})
It("should return the expected value of KubeletInfo", func() {
resultBody := &sensor.KubeletInfo{}
resBody, err = ioutil.ReadAll(res.Body)
Expect(err).ToNot(HaveOccurred())
err = json.Unmarshal(resBody, resultBody)
Expect(err).ToNot(HaveOccurred())
Expect(resultBody.ServiceFiles).
To(Equal(kubeletInfo.ServiceFiles))
Expect(resultBody.KubeConfigFile.Path).
To(Equal(kubeletInfo.KubeConfigFile.Path))
Expect(resultBody.ClientCAFile).
To(Equal(kubeletInfo.ClientCAFile))
})
})
}
}) there could be several other approaches no doubt, as well. Now to run all providers you just do One important thing, though. I noticed that the test you linked to assumes the tests run in order. This is actually only guaranteed if you are running in series and haven't used The independent-spec parallel friendly version of your test would look like: Context("testing /kubeletinfo endpoint", func() {
var (
res *http.Response
err error
resBody []byte
)
BeforeEach(func() {
requestURL := url + "/kubeletinfo"
res, err = http.Get(requestURL)
Expect(err).ToNot(HaveOccurred())
})
It("should return a 200 status code", func() {
Expect(res.StatusCode).To(BeEquivalentTo(200))
})
It("should return the expected value of KubeletInfo", func() {
resultBody := &sensor.KubeletInfo{}
resBody, err = ioutil.ReadAll(res.Body)
Expect(err).ToNot(HaveOccurred())
err = json.Unmarshal(resBody, resultBody)
Expect(err).ToNot(HaveOccurred())
Expect(resultBody.ServiceFiles).
To(Equal(kubeletInfo.ServiceFiles))
Expect(resultBody.KubeConfigFile.Path).
To(Equal(kubeletInfo.KubeConfigFile.Path))
Expect(resultBody.ClientCAFile).
To(Equal(kubeletInfo.ClientCAFile))
})
}) |
Wow! Thanks for the deep explanation, @onsi!! |
Hi all,
Since we use a lot of build tags in tests with ginkgo, we would really appreciate adding the
-tags
flag in theginkgo generate
command.The flag should allow the user to add the provided build tags to the generated file.
Expected behavior
Here's an example command:
ginkgo generate -tags "e2e,!integration" new_test.go
This should generate the following file:
If you like the idea, I can take care of the development :)
The text was updated successfully, but these errors were encountered: