Skip to content

Commit

Permalink
updating testing to check if files actaully got modified
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohit Sharma committed Aug 7, 2023
1 parent e37c5e7 commit 514182f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions cmd/k-license/k-license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"fmt"
"io"
"io/fs"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -53,11 +54,41 @@ func TestAddLicense(t *testing.T) {
if err := optTest.Run(); err != nil {
t.Errorf("error running test case %s: %v", c.desc, err)
}
if err := checkLicense(); err != nil {
t.Fatalf("error Check License on Files Failed %s: %v", c.desc, err)
}
defer os.RemoveAll(tmpTestDir)
})
}
}

func checkLicense() error {
err := filepath.WalkDir(optTest.path, func(path string, info fs.DirEntry, err error) error {
if info.IsDir() && containsExcluded(optTest.excludeDirs, info.Name()) {
return filepath.SkipDir
}
if !info.IsDir() && (isCodeFile(path) || isBuildFile(path)) && !isGenerateFile(path) {
hasLic, err := hasLicense(path)
if !hasLic {
if optTest.confirm {
fmt.Printf("Modified %s file\n", path)
return nil
}
}
if err != nil {

return fmt.Errorf("Error Adding Header/verifying Files")
}

}
if err != nil {
return err
}
return nil
})
return err
}

func createTmpDir() string {
tmpDir, err := os.MkdirTemp("", "testdata")
if err != nil {
Expand Down

0 comments on commit 514182f

Please sign in to comment.