68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
package nix_test
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"slices"
|
|
"syscall"
|
|
"testing"
|
|
|
|
"gensokyo.uk/nix"
|
|
"hakurei.app/command"
|
|
)
|
|
|
|
func init() {
|
|
stubCommandInit = append(stubCommandInit, func(c command.Command) {
|
|
var (
|
|
flagCopyTo string
|
|
flagCopyStdin bool
|
|
)
|
|
c.NewCommand(nix.CommandCopy, "emit samples for various `nix copy` cases", func(args []string) error {
|
|
if flagCopyTo != "s3://example?compression=none¶llel-compression=false®ion=us-east-1&scheme=http&endpoint=s3.example.org&secret-key="+nonexistent || !flagCopyStdin {
|
|
return syscall.ENOSYS
|
|
}
|
|
|
|
installables, err := nix.ReadStdin(os.Stdin)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !slices.Equal(installables, instWant["pluiedev pappardelle"]) {
|
|
return syscall.EINVAL
|
|
}
|
|
return nil
|
|
}).
|
|
Flag(&flagCopyTo, trimFlagName(nix.FlagTo), command.StringFlag(""), nix.FlagTo).
|
|
Flag(&flagCopyStdin, trimFlagName(nix.FlagStdin), command.BoolFlag(false), nix.FlagStdin)
|
|
})
|
|
}
|
|
|
|
func TestCopy(t *testing.T) {
|
|
stubNixCommand(t)
|
|
if err := nix.Copy(
|
|
newStubContext(t.Context(), nil, os.Stdout, os.Stderr),
|
|
&nix.BinaryCache{
|
|
Compression: "none",
|
|
ParallelCompression: false,
|
|
Bucket: "example",
|
|
Endpoint: "s3.example.org",
|
|
Region: "us-east-1",
|
|
Scheme: "http",
|
|
CredentialsPath: "/dev/null",
|
|
KeyPath: nonexistent,
|
|
},
|
|
slices.Values(instWant["pluiedev pappardelle"]),
|
|
); err != nil {
|
|
t.Errorf("Copy: error = %v", err)
|
|
}
|
|
|
|
t.Run("nil store", func(t *testing.T) {
|
|
if err := nix.Copy(
|
|
newStubContext(t.Context(), nil, os.Stdout, os.Stderr),
|
|
nil,
|
|
nil,
|
|
); !errors.Is(err, os.ErrInvalid) {
|
|
t.Errorf("Copy: error = %v, want %v", err, os.ErrInvalid)
|
|
}
|
|
})
|
|
}
|