Commit d11f2df9 authored by odatskov's avatar odatskov
Browse files

Pointers will point the way

parent edb5ad97
Pipeline #458279 failed with stage
in 2 minutes and 25 seconds
...@@ -7,42 +7,37 @@ import ( ...@@ -7,42 +7,37 @@ import (
"strings" "strings"
) )
func getFileList(root string, args []string) []string { func getFileList(root string, args *[]string, files *[]string) {
if len(args) == 0 { if len(*args) == 1 {
var files []string
// Recusively walk through the root path, creating list of files with *.yaml // Recusively walk through the root path, creating list of files with *.yaml
filepath.Walk(root, func(path string, info os.FileInfo, err error) error { filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if !info.IsDir() && strings.HasSuffix(path, ".yaml") { if !info.IsDir() && strings.HasSuffix(path, ".yaml") {
files = append(files, path) *files = append(*files, path)
} }
return nil return nil
}) })
if len(files) == 0 { log.Fatalf("No files found") } if len(*files) == 0 { log.Fatalf("No files found") }
return files
} else { } else {
var err_files []string var err_files []string
// Check if files passed through arguments actually exist // Check if files passed through arguments actually exist
for _, file := range args { for _, file := range *args[1:] {
_, err := os.Stat(file) _, err := os.Stat(file)
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
err_files = append(err_files, file) err_files = append(err_files, file)
} }
} } else { *files=append(*files,file) }
}
if len(err_files) > 0 {
log.Fatalf("File(s) not found: %s", err_files)
} }
return args if len(err_files) > 0 { log.Fatalf("File(s) not found: %s", err_files) }
} }
} }
func main() { func main() {
var files []string
file_list := getFileList(".", os.Args[1:]) getFileList(".", &os.Args,&files)
log.Printf(strings.Join(file_list, " ")) log.Printf("Returned list of files: %s",files)
// Check that the token still is valid // Check that the token still is valid
// For each file: // For each file:
// Get the manifest and check for changes // Get the manifest and check for changes
......
...@@ -2,28 +2,34 @@ package main ...@@ -2,28 +2,34 @@ package main
import ( import (
"testing" "testing"
//"log" "log"
//"os/exec" "fmt"
//"strings" "os/exec"
"strings"
//"math/rand" //"math/rand"
) )
func Test_getFileList_FilesExists(t *testing.T) { func Test_getFileList(t *testing.T) {
//cmd := strings.Split("find . -name *.yaml"," ")
//test_cmd, _ := exec.Command(cmd[0],cmd[1:]...).Output()
//test_str := strings.Split(string(test_cmd),"\n")
//log.Printf(len(test_str))
var input_path []string cmd := strings.Split("find . -name *.yaml"," ")
input_path = append(input_path,"IT-Batch/cc7-gitlab.yaml") test_cmd, _ := exec.Command(cmd[0],cmd[1:]...).Output()
out_test := getFileList(".",input_path) test_str := strings.Split(string(test_cmd),"\n")
log.Printf("Test string: %s",test_str)
if len(out_test) != 1 {t.Errorf("For %s expected size of 1 Received %d",input_path,len(out_test))} for i:=1; i < len(test_str); i++ {
if out_test[0] != input_path[0] {t.Errorf("For %s Received %s",input_path,out_test)} var out_test []string
getFileList(".", &test_str[:i],&out_test)
//var err_path []string t.Run(fmt.Sprintf("Size test for %d argument(s)",i), func(t *testing.T) {
//err_path = append(err_path,"IT-Batch/cc7-gitlab.yamlz") if len(out_test) != len(test_str[:1]) {
//if len(out_test) != 1 {t.Errorf("For",input_path,"expected size of 1","got",len(out_test))} t.Errorf("For %s expected size of %d, received %d", test_str[:i],len(test_str[:i]),len(out_test))
//if out_test[0] != input_path[0] {t.Errorf("For",input_path,"received",out_test)} }
} })
}
t.Run(fmt.Sprintf("File path equivalence"), func(t *testing.T) {
var out_test []string
getFileList(".",&test_str,&out_test)
if out_test[0] != test_str[0] { t.Errorf("For %s, received %s", test_str[0], out_test[0]) }
})
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment