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)
| 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. |
| 26 | func 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 | |
| 57 | func cmpGoldenFile(t *testing.T, gotPath, wantGoldenPath string) { |
| 58 | got, err := os.ReadFile(gotPath) |
nothing calls this directly
no test coverage detected