github.com/hattya/nazuna@v0.7.1-0.20240331055452-55e14c275c1c/util_unix_test.go (about) 1 // 2 // nazuna :: util_unix_test.go 3 // 4 // Copyright (c) 2014-2023 Akinori Hattori <hattya@gmail.com> 5 // 6 // SPDX-License-Identifier: MIT 7 // 8 9 //go:build unix 10 11 package nazuna_test 12 13 import ( 14 "testing" 15 16 "github.com/hattya/nazuna" 17 ) 18 19 func TestCreateLink(t *testing.T) { 20 sandbox(t) 21 22 if err := touch("src"); err != nil { 23 t.Error(err) 24 } 25 26 if p := "src"; nazuna.IsLink(p) { 27 t.Errorf("IsLink(%q) = true, expected false", p) 28 } 29 if err := nazuna.CreateLink("src", "dst"); err != nil { 30 t.Error(err) 31 } 32 if p := "dst"; !nazuna.IsLink("dst") { 33 t.Errorf("IsLink(%q) = false, expected true", p) 34 } 35 36 if p, o := "dst", "src"; !nazuna.LinksTo(p, o) { 37 t.Errorf("LinksTo(%q, %q) = false, expected true", p, o) 38 } 39 if p, o := "dst", "_"; nazuna.LinksTo(p, o) { 40 t.Errorf("LinksTo(%q, %q) = true, expected false", p, o) 41 } 42 if p, o := "src", "dst"; nazuna.LinksTo(p, o) { 43 t.Errorf("LinksTo(%q, %q) = true, expected false", p, o) 44 } 45 46 if err := nazuna.Unlink("dst"); err != nil { 47 t.Error(err) 48 } 49 if err := nazuna.Unlink("src"); err == nil { 50 t.Error("expected error") 51 } 52 }