diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0f7ace3557effa51e5458b9af66e5b849f804f81..c5a28ddabf417d2d0f60008d75ca644fb5fc2c0b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,6 +9,6 @@ sync_test: image: golang:latest script: - go version - - go test + - go test -v environment: name: test diff --git a/sync.go b/sync.go index 2373c8007ca8cc50efd2560f5a215a2802081e9c..6a35585d305da31fd963eaaf2ff366e8a9103605 100644 --- a/sync.go +++ b/sync.go @@ -1,14 +1,53 @@ 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 } diff --git a/sync_test.go b/sync_test.go index aa32267aed9834ad1b6785c4ef1fe29d937dfd1d..f50a24cd7f1a245eb1d5db4a08eff5e8bf031833 100644 --- a/sync_test.go +++ b/sync_test.go @@ -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)} } +