MCPcopy
hub / github.com/perkeep/perkeep / TestStaticFileAndStaticSymlink

Function TestStaticFileAndStaticSymlink

pkg/schema/schema_test.go:527–599  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

525}
526
527func TestStaticFileAndStaticSymlink(t *testing.T) {
528 // TODO (marete): Split this into two test functions.
529 fd, err := os.CreateTemp("", "schema-test-")
530 if err != nil {
531 t.Fatalf("io.TempFile(): %v", err)
532 }
533 defer os.Remove(fd.Name())
534 defer fd.Close()
535
536 fi, err := os.Lstat(fd.Name())
537 if err != nil {
538 t.Fatalf("os.Lstat(): %v", err)
539 }
540
541 bb := NewCommonFileMap(fd.Name(), fi)
542 bb.SetType(TypeFile)
543 bb.SetFileName(fd.Name())
544 blob := bb.Blob()
545
546 sf, ok := blob.AsStaticFile()
547 if !ok {
548 t.Fatalf("Blob.AsStaticFile(): Unexpected return value: false")
549 }
550 if want, got := filepath.Base(fd.Name()), sf.FileName(); want != got {
551 t.Fatalf("StaticFile.FileName(): Expected %s, got %s",
552 want, got)
553 }
554
555 _, ok = sf.AsStaticSymlink()
556 if ok {
557 t.Fatalf("StaticFile.AsStaticSymlink(): Unexpected return value: true")
558 }
559
560 dir := t.TempDir()
561
562 target := "bar"
563 src := filepath.Join(dir, "foo")
564 err = os.Symlink(target, src)
565 if err != nil {
566 if runtime.GOOS == "windows" {
567 t.Skip("skipping symlink test on Windows")
568 }
569 t.Fatal(err)
570 }
571 fi, err = os.Lstat(src)
572 if err != nil {
573 t.Fatalf("os.Lstat(): %v", err)
574 }
575
576 bb = NewCommonFileMap(src, fi)
577 bb.SetType(TypeSymlink)
578 bb.SetFileName(src)
579 bb.SetSymlinkTarget(target)
580 blob = bb.Blob()
581
582 sf, ok = blob.AsStaticFile()
583 if !ok {
584 t.Fatalf("Blob.AsStaticFile(): Unexpected return value: false")

Callers

nothing calls this directly

Calls 15

NewCommonFileMapFunction · 0.85
SetTypeMethod · 0.80
SetFileNameMethod · 0.80
AsStaticFileMethod · 0.80
AsStaticSymlinkMethod · 0.80
FatalMethod · 0.80
SetSymlinkTargetMethod · 0.80
FatalfMethod · 0.65
RemoveMethod · 0.65
NameMethod · 0.65
CloseMethod · 0.65
LstatMethod · 0.65

Tested by

no test coverage detected