Skip to content

Commit

Permalink
fix [close #7]: move genfilelist.py correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
matbme authored Jun 26, 2024
1 parent 4ce44ef commit 22ee665
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
31 changes: 18 additions & 13 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,34 @@ type FsGuardModule struct {
FilelistPaths []string `json:"FilelistPaths"`
}

var FSGUARD_URL string = "https://github.com/linux-immutability-tools/FsGuard/releases/download/v0.1.2-2/FsGuard_0.1.2-2_linux_amd64.tar.gz"
var FSGUARD_CHECKSUM string = "b4aa058e4c4828ac57335e8cabd6b3baeff660ff524aa71069c3f56fd0445335"
var (
FSGUARD_URL string = "https://github.com/linux-immutability-tools/FsGuard/releases/download/v0.1.2-2/FsGuard_0.1.2-2_linux_amd64.tar.gz"
FSGUARD_CHECKSUM string = "b4aa058e4c4828ac57335e8cabd6b3baeff660ff524aa71069c3f56fd0445335"
)

var GENFILELIST_URL string = "https://raw.githubusercontent.com/Vanilla-OS/vib-fsguard/3323f7c3c3f8459a64b97ad408d805edc5520c8d/genfilelist.py"
var GENFILELIST_CHECKSUM string = "22658b7246d7a38c71d0c0fa64fd073ea7867da08344365242873f003abff8c5"
var (
GENFILELIST_URL string = "https://raw.githubusercontent.com/Vanilla-OS/vib-fsguard/3323f7c3c3f8459a64b97ad408d805edc5520c8d/genfilelist.py"
GENFILELIST_CHECKSUM string = "22658b7246d7a38c71d0c0fa64fd073ea7867da08344365242873f003abff8c5"
)

var prepCommands []string
var mainCommands []string
var cleanCommands []string
var (
prepCommands []string
mainCommands []string
cleanCommands []string
)

// Helper functions for tests
// TODO: move to api
func convertToCString(s string) *C.char {
return C.CString(s)
}

func convertToGoString(s *C.char) string {
return C.GoString(s)
}

func fetchFsGuard(module *FsGuardModule, recipe *api.Recipe) error {
var source api.Source
source = api.Source{URL: FSGUARD_URL, Type: "tar", Checksum: FSGUARD_CHECKSUM}
source := api.Source{URL: FSGUARD_URL, Type: "tar", Checksum: FSGUARD_CHECKSUM}
err := api.DownloadSource(recipe.DownloadsPath, source, module.Name)
if err != nil {
return err
Expand All @@ -56,14 +62,13 @@ func fetchFsGuard(module *FsGuardModule, recipe *api.Recipe) error {
}

func fetchFileListScript(module *FsGuardModule, recipe *api.Recipe) error {
var source api.Source
source = api.Source{URL: GENFILELIST_URL, Type: "single", Checksum: GENFILELIST_CHECKSUM}
source := api.Source{URL: GENFILELIST_URL, Type: "single", Checksum: GENFILELIST_CHECKSUM}
api.DownloadTarSource(recipe.DownloadsPath, source, module.Name)
err := os.MkdirAll(filepath.Join(recipe.SourcesPath, module.Name), 0777)
err := os.MkdirAll(filepath.Join(recipe.SourcesPath, module.Name), 0o777)
if err != nil {
return err
}
err = os.Rename(filepath.Join(recipe.DownloadsPath, module.Name), filepath.Join(recipe.SourcesPath, module.Name, "genfilelist.py"))
err = os.Rename(filepath.Join(recipe.DownloadsPath, module.Name+".tar"), filepath.Join(recipe.SourcesPath, module.Name, "genfilelist.py"))
if err != nil {
return err
}
Expand Down
10 changes: 4 additions & 6 deletions plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ var test = []testCases{
var recipe = "{\"Name\":\"fsguard unit test\",\"Id\":\"fsguard\",\"Stages\":[{\"id\":\"test\",\"base\":\"test:latest\",\"singlelayer\":false,\"copy\":null,\"labels\":null,\"env\":null,\"adds\":null,\"args\":null,\"runs\":null,\"expose\":null,\"cmd\":null,\"modules\":[{}],\"Entrypoint\":null}],\"Path\":\"/fakepath/recipe.yml\",\"ParentPath\":\"/fakepath\",\"DownloadsPath\":\"/tmp/fsguard/downloads\",\"SourcesPath\":\"/tmp/fsguard/sources\",\"PluginPath\":\"/plugins\",\"Containerfile\":\"/Containerfile\"}"

func TestBuildModule(t *testing.T) {
err := os.MkdirAll("/tmp/fsguard/downloads", 0777)
err := os.MkdirAll("/tmp/fsguard/downloads", 0o777)
if err != nil {
t.Errorf("%s", err)
}
err = os.MkdirAll("/tmp/fsguard/sources", 0777)
err = os.MkdirAll("/tmp/fsguard/sources", 0o777)
if err != nil {
t.Errorf("%s", err)
}
Expand All @@ -49,18 +49,16 @@ func TestBuildModule(t *testing.T) {
if err != nil {
t.Errorf("%s", err)
}
output := convertToCString("")
moduleInterface, err := json.Marshal(testCase.module)
if err != nil {
t.Errorf("Error in json %s", err.Error())
}
output = BuildModule(convertToCString(string(moduleInterface)), convertToCString(recipe))
output := BuildModule(convertToCString(string(moduleInterface)), convertToCString(recipe))
if convertToGoString(output) != testCase.expected {
t.Errorf("Output %s not equivalent to expected %s", convertToGoString(output), testCase.expected)
} else {
fmt.Printf("-- Testcase %d succeeded --\n", i)
fmt.Printf("-- Testcase %d succeeded --\n", i+1)
}
}
os.RemoveAll("/tmp/fsguard")

}

0 comments on commit 22ee665

Please sign in to comment.