-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport of template: run template tests on Windows where possible in…
…to release/1.5.x #19857 We don't run the whole suite of unit tests on all platforms to keep CI times reasonable, so the only things we've been running on Windows are platform-specific. I'm working on some platform-specific `template` related work and having these tests run on Windows will reduce the risk of regressions. Our Windows CI box doesn't have Consul or Vault, so I've skipped those tests for the time being, and can follow up with that later. There's also a test with assertions looking for specific paths, and the results are different on Windows. I've skipped those for the moment as well and will follow up under a separate PR. Also swap `testify` for `shoenig/test` Co-authored-by: Tim Gross <[email protected]>
- Loading branch information
1 parent
8d168fe
commit 3b0bd14
Showing
4 changed files
with
206 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
client/allocrunner/taskrunner/template/template_default_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
//go:build !windows | ||
|
||
package template | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"syscall" | ||
"testing" | ||
"time" | ||
|
||
"github.com/hashicorp/nomad/ci" | ||
clienttestutil "github.com/hashicorp/nomad/client/testutil" | ||
"github.com/hashicorp/nomad/helper/pointer" | ||
"github.com/hashicorp/nomad/nomad/structs" | ||
"github.com/hashicorp/nomad/testutil" | ||
"github.com/shoenig/test/must" | ||
) | ||
|
||
// TestTaskTemplateManager_Permissions tests that we set file permissions | ||
// correctly. This test won't compile on Windows | ||
func TestTaskTemplateManager_Permissions(t *testing.T) { | ||
ci.Parallel(t) | ||
clienttestutil.RequireRoot(t) | ||
|
||
// Make a template that will render immediately | ||
content := "hello, world!" | ||
file := "my.tmpl" | ||
template := &structs.Template{ | ||
EmbeddedTmpl: content, | ||
DestPath: file, | ||
ChangeMode: structs.TemplateChangeModeNoop, | ||
Perms: "777", | ||
Uid: pointer.Of(503), | ||
Gid: pointer.Of(20), | ||
} | ||
|
||
harness := newTestHarness(t, []*structs.Template{template}, false, false) | ||
harness.start(t) | ||
defer harness.stop() | ||
|
||
// Wait for the unblock | ||
select { | ||
case <-harness.mockHooks.UnblockCh: | ||
case <-time.After(time.Duration(5*testutil.TestMultiplier()) * time.Second): | ||
t.Fatalf("Task unblock should have been called") | ||
} | ||
|
||
// Check the file is there | ||
path := filepath.Join(harness.taskDir, file) | ||
fi, err := os.Stat(path) | ||
if err != nil { | ||
t.Fatalf("Failed to stat file: %v", err) | ||
} | ||
|
||
if m := fi.Mode(); m != os.ModePerm { | ||
t.Fatalf("Got mode %v; want %v", m, os.ModePerm) | ||
} | ||
|
||
sys := fi.Sys() | ||
uid := pointer.Of(int(sys.(*syscall.Stat_t).Uid)) | ||
gid := pointer.Of(int(sys.(*syscall.Stat_t).Gid)) | ||
|
||
must.Eq(t, template.Uid, uid) | ||
must.Eq(t, template.Gid, gid) | ||
} |
Oops, something went wrong.