github.com/release-engineering/exodus-rsync@v1.11.2/internal/cmd/cmd_sync_badlinks_test.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 "os" 6 "strings" 7 "testing" 8 9 "github.com/golang/mock/gomock" 10 "github.com/release-engineering/exodus-rsync/internal/gw" 11 ) 12 13 func TestMainSyncBadLinks(t *testing.T) { 14 SetConfig(t, CONFIG) 15 16 logs := CaptureLogger(t) 17 18 ctrl := MockController(t) 19 20 mockGw := gw.NewMockInterface(ctrl) 21 ext.gw = mockGw 22 23 client := FakeClient{blobs: make(map[string]string)} 24 25 t.Run("fails on broken symlink", func(t *testing.T) { 26 os.Mkdir("broken-link", 0755) 27 err := os.Symlink("/this/file/does/not/exist", "broken-link/src") 28 if err != nil { 29 t.Fatalf("can't make symlink, err = %v", err) 30 } 31 32 args := []string{"rsync", "-vvv", "broken-link", "exodus:/some/target"} 33 34 mockGw.EXPECT().NewClient(gomock.Any(), EnvMatcher{"best-env"}).Return(&client, nil) 35 got := Main(args) 36 37 // It should fail 38 if got != 73 { 39 t.Errorf("got unexpected exit code = %v", got) 40 } 41 42 // It should tell us why 43 entry := FindEntry(logs, "can't read files for sync") 44 if entry == nil { 45 t.Error("missing expected log message") 46 } 47 48 errMessage := fmt.Sprint(entry.Fields["error"]) 49 if !strings.Contains(errMessage, "resolving link broken-link/src") { 50 t.Error("unexpected error message", errMessage) 51 } 52 }) 53 54 }