|
| 1 | +package shellgen |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "go.jetify.com/devbox/internal/devbox/devopt" |
| 7 | + "go.jetify.com/devbox/internal/devconfig/configfile" |
| 8 | + "go.jetify.com/devbox/internal/devpkg" |
| 9 | + "go.jetify.com/devbox/internal/lock" |
| 10 | + "go.jetify.com/devbox/nix/flake" |
| 11 | +) |
| 12 | + |
| 13 | +type lockMock struct{} |
| 14 | + |
| 15 | +func (l *lockMock) Get(key string) *lock.Package { |
| 16 | + return nil |
| 17 | +} |
| 18 | + |
| 19 | +func (l *lockMock) Stdenv() flake.Ref { |
| 20 | + return flake.Ref{} |
| 21 | +} |
| 22 | + |
| 23 | +func (l *lockMock) ProjectDir() string { |
| 24 | + return "" |
| 25 | +} |
| 26 | + |
| 27 | +func (l *lockMock) Resolve(key string) (*lock.Package, error) { |
| 28 | + return &lock.Package{ |
| 29 | + Resolved: "github:NixOS/nixpkgs/10b813040df67c4039086db0f6eaf65c536886c6#python312", |
| 30 | + }, nil |
| 31 | +} |
| 32 | + |
| 33 | +func TestNewGlibcPatchFlake(t *testing.T) { |
| 34 | + stdenv := flake.Ref{ |
| 35 | + Type: flake.TypeGitHub, |
| 36 | + URL: "https://github.com/NixOS/nixpkgs", |
| 37 | + Ref: "nixpkgs-unstable", |
| 38 | + } |
| 39 | + |
| 40 | + packages := devpkg.PackagesFromStringsWithOptions([]string{"python@latest"}, &lockMock{}, devopt.AddOpts{ |
| 41 | + Patch: string(configfile.PatchAlways), |
| 42 | + }) |
| 43 | + |
| 44 | + patchFlake, err := newGlibcPatchFlake(stdenv, packages) |
| 45 | + if err != nil { |
| 46 | + t.Fatalf("expected no error, got %v", err) |
| 47 | + } |
| 48 | + |
| 49 | + if patchFlake.NixpkgsGlibcFlakeRef != stdenv.String() { |
| 50 | + t.Errorf("expected NixpkgsGlibcFlakeRef to be %s, got %s", stdenv.String(), patchFlake.NixpkgsGlibcFlakeRef) |
| 51 | + } |
| 52 | + |
| 53 | + if len(patchFlake.Outputs.Packages) != 1 { |
| 54 | + t.Errorf("expected 1 package in Outputs, got %d", len(patchFlake.Outputs.Packages)) |
| 55 | + } |
| 56 | +} |
0 commit comments