github.com/dancsecs/gotomd@v0.0.0-20240310162206-65c4805cf510/arg_usage_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  	"testing"
    23  
    24  	"github.com/dancsecs/sztest"
    25  )
    26  
    27  func Test_ArgUsage_SampleNoArgsNotDirectory(t *testing.T) {
    28  	chk := sztest.CaptureNothing(t)
    29  	defer chk.Release()
    30  
    31  	chk.SetupArgsAndFlags([]string{
    32  		"programName",
    33  	})
    34  
    35  	chk.AddSub(`(?s)\n.*$`, "\\nUsage Information")
    36  	chk.Panic(
    37  		main,
    38  		"at least one file or directory must be specified\\nUsage Information",
    39  	)
    40  }
    41  
    42  func Test_ArgUsage_SampleInvalidFile(t *testing.T) {
    43  	chk := sztest.CaptureNothing(t)
    44  	defer chk.Release()
    45  
    46  	fPath := chk.CreateTmpFile(nil)
    47  	chk.SetupArgsAndFlags([]string{
    48  		"programName",
    49  		fPath,
    50  	})
    51  
    52  	chk.Panic(
    53  		main,
    54  		ErrUnexpectedExtension.Error()+": expected - .md.gtm",
    55  	)
    56  }
    57  
    58  func Test_ArgUsage_InvalidDefaultPermissions(t *testing.T) {
    59  	chk := sztest.CaptureNothing(t)
    60  	defer chk.Release()
    61  
    62  	fPath := chk.CreateTmpFile(nil)
    63  	chk.SetupArgsAndFlags([]string{
    64  		"programName",
    65  		"-p", "0744",
    66  		fPath,
    67  	})
    68  
    69  	chk.AddSub(`(?s)\n.*$`, "\\nUsage Information")
    70  	chk.Panic(
    71  		main,
    72  		"invalid default permissions specified\\nUsage Information",
    73  	)
    74  }
    75  
    76  func Test_ArgUsage_InvalidCleanAndReplace(t *testing.T) {
    77  	chk := sztest.CaptureNothing(t)
    78  	defer chk.Release()
    79  
    80  	fPath := chk.CreateTmpFile(nil)
    81  	chk.SetupArgsAndFlags([]string{
    82  		"programName",
    83  		"-r",
    84  		"-c",
    85  		fPath,
    86  	})
    87  
    88  	chk.AddSub(`(?s)\n.*$`, "\\nUsage Information")
    89  	chk.Panic(
    90  		main,
    91  		"only one of -c and -r may be specified\\nUsage Information",
    92  	)
    93  }
    94  
    95  func Test_ArgUsage_InvalidOutDirectory(t *testing.T) {
    96  	chk := sztest.CaptureNothing(t)
    97  	defer chk.Release()
    98  
    99  	fPath := chk.CreateTmpFile(nil)
   100  	chk.SetupArgsAndFlags([]string{
   101  		"programName",
   102  		"-o", "DIRECTORY_DOES_NOT_EXIST",
   103  		fPath,
   104  	})
   105  
   106  	chk.AddSub(`(?s)\n.*$`, "\\nUsage Information")
   107  	chk.Panic(
   108  		main,
   109  		"invalid output directory specified: "+
   110  			"DIRECTORY_DOES_NOT_EXIST\\nUsage Information",
   111  	)
   112  }