MCPcopy Create free account
hub / github.com/jetify-com/devbox / TestWriteFromTemplate

Function TestWriteFromTemplate

internal/shellgen/generate_test.go:26–55  ·  view source on GitHub ↗

TestWriteFromTemplate will verify that the flake.nix code generation works as expected. Note: this test was derived from an older flake.nix, prior to having the builtins.FetchClosures and so may be a bit out of date. It could be updated to be better and more exhaustive.

(t *testing.T)

Source from the content-addressed store, hash-verified

24// Note: this test was derived from an older flake.nix, prior to having the builtins.FetchClosures
25// and so may be a bit out of date. It could be updated to be better and more exhaustive.
26func TestWriteFromTemplate(t *testing.T) {
27 t.Setenv("__DEVBOX_NIX_SYSTEM", "x86_64-linux")
28 dir := filepath.Join(t.TempDir(), "makeme")
29 outPath := filepath.Join(dir, "flake.nix")
30 _, err := writeFromTemplate(dir, testFlakeTmplPlan, "flake.nix", "flake.nix")
31 if err != nil {
32 t.Fatal("got error writing flake template:", err)
33 }
34 cmpGoldenFile(t, outPath, "testdata/flake.nix.golden")
35
36 t.Run("WriteUnmodified", func(t *testing.T) {
37 _, err = writeFromTemplate(dir, testFlakeTmplPlan, "flake.nix", "flake.nix")
38 if err != nil {
39 t.Fatal("got error writing flake template:", err)
40 }
41 cmpGoldenFile(t, outPath, "testdata/flake.nix.golden")
42 })
43 t.Run("WriteModifiedSmaller", func(t *testing.T) {
44 emptyPlan := &flakePlan{
45 Packages: []*devpkg.Package{},
46 FlakeInputs: []flakeInput{},
47 System: "x86_64-linux",
48 }
49 _, err = writeFromTemplate(dir, emptyPlan, "flake.nix", "flake.nix")
50 if err != nil {
51 t.Fatal("got error writing flake template:", err)
52 }
53 cmpGoldenFile(t, outPath, "testdata/flake-empty.nix.golden")
54 })
55}
56
57func cmpGoldenFile(t *testing.T, gotPath, wantGoldenPath string) {
58 got, err := os.ReadFile(gotPath)

Callers

nothing calls this directly

Calls 3

writeFromTemplateFunction · 0.85
cmpGoldenFileFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected