Commit 555576db authored by odatskov's avatar odatskov
Browse files

Adding file input function (with test)

parent a32266e8
Pipeline #457970 failed with stage
in 1 minute and 28 seconds
......@@ -9,6 +9,6 @@ sync_test:
image: golang:latest
script:
- go version
- go test
- go test -v
environment:
name: test
package main
import (
//"fmt"
"log"
"os"
"path/filepath"
"strings"
)
func print_me() string {
return "We are running this"
func getFileList(root string, args []string) []string {
if len(args) == 0 {
var files []string
// Recusively walk through the root path, creating list of files with *.yaml
filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if !info.IsDir() && strings.HasSuffix(path, ".yaml") {
files = append(files, path)
}
return nil
})
if len(files) == 0 { log.Fatalf("No files found") }
return files
} else {
var err_files []string
// Check if files passed through arguments actually exist
for _, file := range args {
_, err := os.Stat(file)
if err != nil {
if os.IsNotExist(err) {
err_files = append(err_files, file)
}
}
}
if len(err_files) > 0 {
log.Fatalf("File(s) not found: %s", err_files)
}
return args
}
}
func main() {
log.Printf(print_me())
file_list := getFileList(".", os.Args[1:])
log.Printf(strings.Join(file_list, " "))
// Check that the token still is valid
// For each file:
// Get the manifest and check for changes
// Fetch the layers
// Unpack the structure
// Adjust permissions on the files
// When done, merge changes to cvmfs
}
......@@ -2,8 +2,28 @@ package main
import (
"testing"
//"log"
//"os/exec"
//"strings"
//"math/rand"
)
func printme_test(t *testing.T) {
t.Error(print_me())
func Test_getFileList_FilesExists(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
input_path = append(input_path,"IT-Batch/cc7-gitlab.yaml")
out_test := getFileList(".",input_path)
if len(out_test) != 1 {t.Errorf("For",input_path,"expected size of 1","got",len(out_test))}
if out_test[0] != input_path[0] {t.Errorf("For",input_path,"received",out_test)}
//var err_path []string
//err_path = append(err_path,"IT-Batch/cc7-gitlab.yamlz")
//if len(out_test) != 1 {t.Errorf("For",input_path,"expected size of 1","got",len(out_test))}
//if out_test[0] != input_path[0] {t.Errorf("For",input_path,"received",out_test)}
}
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