From 05fe2ad1913c7a5d094acd7e663fd99c74a54f9a Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Fri, 1 Dec 2023 08:54:55 -0500 Subject: [PATCH] E2E: fix assertion in CT native service lookup test (#19249) When porting the `ConsulTemplate` test, I made a last-minute refactor to the assertions for waiting on files, and accidentally inverted the test assertion in the process. Also, when running `jobs3.Submit` you need to include the `Namespace` option so that the cleanup function that gets return deletes the job from the correct namespace. This was causing the namespace cleanup to fail because the job deletion had failed. --- e2e/consultemplate/consultemplate_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/e2e/consultemplate/consultemplate_test.go b/e2e/consultemplate/consultemplate_test.go index 2d9bf9479..12ae4510a 100644 --- a/e2e/consultemplate/consultemplate_test.go +++ b/e2e/consultemplate/consultemplate_test.go @@ -367,7 +367,8 @@ func TestConsulTemplate_NomadServiceLookups(t *testing.T) { // Register a job which includes services destined for the Nomad provider // into the platform namespace. This is used to ensure consul-template // lookups stay bound to the allocation namespace. - _, diffCleanupJob := jobs3.Submit(t, "./input/nomad_provider_service_ns.nomad") + _, diffCleanupJob := jobs3.Submit(t, "./input/nomad_provider_service_ns.nomad", + jobs3.Namespace("platform")) t.Cleanup(diffCleanupJob) // Register a job which includes consul-template function performing Nomad @@ -377,10 +378,11 @@ func TestConsulTemplate_NomadServiceLookups(t *testing.T) { t.Cleanup(serviceLookupJobCleanup) serviceLookupAllocID := serviceLookupJobSubmission.AllocID("nomad_provider_service_lookup") - // Ensure the listing (nomadServices) template function has found all - // services within the default namespace. mustWaitForTaskFile(t, serviceLookupAllocID, "test", "${NOMAD_TASK_DIR}/services.conf", func(out string) error { + + // Ensure the listing (nomadServices) template function has found all + // services within the default namespace... expect := "service default-nomad-provider-service-primary [bar foo]" if !strings.Contains(out, expect) { return fmt.Errorf("expected %q, got %q", expect, out) @@ -389,8 +391,10 @@ func TestConsulTemplate_NomadServiceLookups(t *testing.T) { if !strings.Contains(out, expect) { return fmt.Errorf("expected %q, got %q", expect, out) } + + // ... but not the platform namespace. expect = "service platform-nomad-provider-service-secondary [baz buz]" - if !strings.Contains(out, expect) { + if strings.Contains(out, expect) { return fmt.Errorf("expected %q, got %q", expect, out) } return nil