github.com/dancsecs/gotomd@v0.0.0-20240310162206-65c4805cf510/get_file_test.go (about) 1 /* 2 Golang To Github Markdown Utility: gotomd 3 Copyright (C) 2023, 2024 Leslie Dancsecs 4 5 This program is free software: you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation, either version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <https://www.gnu.org/licenses/>. 17 */ 18 19 package main 20 21 import ( 22 "os" 23 "testing" 24 25 "github.com/dancsecs/sztest" 26 ) 27 28 func Test_GetFile_GetGoFileInvalid(t *testing.T) { 29 chk := sztest.CaptureNothing(t) 30 defer chk.Release() 31 32 tstDir := "TEST_DIRECTORY_DOES_NOT_EXIST" + string(os.PathSeparator) 33 _, err := getGoFile(tstDir) 34 chk.Err( 35 err, 36 ErrInvalidRelativeDir.Error()+": \""+tstDir+"\"", 37 ) 38 39 _, err = getGoTst(example1Path + "TEST_DOES_NOT_EXIST") 40 chk.Err(err, ErrNoTestToRun.Error()) 41 } 42 43 func Test_GetFile_GetGoFile(t *testing.T) { 44 chk := sztest.CaptureNothing(t) 45 defer chk.Release() 46 47 d, err := getGoFile(example1Path + "crumb.go") 48 chk.NoErr(err) 49 chk.Str( 50 d, 51 ""+ 52 markBashCode(catCmd+example1Path+"crumb.go")+ 53 "\n\n"+ 54 markGoCode(pkgLabel+" "+example1), 55 ) 56 } 57 58 func Test_GetFile_GetGoFile2(t *testing.T) { 59 chk := sztest.CaptureNothing(t) 60 defer chk.Release() 61 62 file1 := example1Path + "crumb.go" 63 file2 := example2Path + "crumb.go" 64 65 d, err := getGoFile(file1 + " " + file2) 66 chk.NoErr(err) 67 chk.Str( 68 d, 69 ""+ 70 markBashCode(catCmd+file1)+ 71 "\n\n"+ 72 markGoCode(pkgLabel+" "+example1)+ 73 "\n\n"+ 74 markBashCode(catCmd+file2)+ 75 "\n\n"+ 76 markGoCode(pkgLabel+" "+example2)+ 77 "", 78 ) 79 }