logo

go-deblob

remove binary blobs from a directory
commit: ccd8fd7089d7bb15b8ad956f07ae6830c32fb148
parent: b37658478c362c6a8ed70cd51cc0869dda96add3
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Thu, 12 Dec 2019 03:51:43 +0100

Add test for checkDir()

Diffstat:

MMakefile2++
Mgo-deblob_test.go65++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
2 files changed, 56 insertions(+), 11 deletions(-)

diff --git a/Makefile b/Makefile @@ -17,7 +17,9 @@ clean: .PHONY: test test: + cp -r test/fixtures test/checkDir-fixtures go test + rm -r test/checkDir-fixtures .PHONY: install install: diff --git a/go-deblob_test.go b/go-deblob_test.go @@ -3,20 +3,26 @@ // SPDX-License-Identifier: BSD-3-Clause package main -import "testing" +import ( + "testing" + + "os" + "path/filepath" + "reflect" +) func TestIsBlob(t *testing.T) { tests := []struct { - path string - expect bool - }{ - {"test/fixtures/hello.1", false}, - {"test/fixtures/hello.c", false}, - {"test/fixtures/hello", true}, - // {"test/fixtures/hello.o", true}, - {"test/fixtures/hello.ar", true}, - {"test/fixtures/empty", false}, - } + path string + expect bool + }{ + {"test/fixtures/hello.1", false}, + {"test/fixtures/hello.c", false}, + {"test/fixtures/hello", true}, + // {"test/fixtures/hello.o", true}, + {"test/fixtures/hello.ar", true}, + {"test/fixtures/empty", false}, + } for _, test := range tests { got := isBlob(test.path) @@ -25,3 +31,40 @@ func TestIsBlob(t *testing.T) { } } } + +func TestCheckDir(t *testing.T) { + dirname := "test/checkDir-fixtures" + var files_before []string + var files_after []string + + err := filepath.Walk(dirname, func(path string, info os.FileInfo, err error) error { + if err != nil { + t.Errorf("filepath.Walk(%s, /*files_before*/): %s\n", dirname, err) + return err + } + files_before = append(files_before, path) + return nil + }) + if err != nil { + t.Errorf("filepath.Walk(%s, /*files_before*/): %s\n", dirname, err) + return + } + + checkDir(dirname) + + err = filepath.Walk(dirname, func(path string, info os.FileInfo, err error) error { + if err != nil { + t.Errorf("filepath.Walk(%s, /*files_after*/): %s\n", dirname, err) + return err + } + files_after = append(files_after, path) + return nil + }) + if err != nil { + t.Errorf("filepath.Walk(%s, /*files_after*/): %s\n", dirname, err) + return + } + if reflect.DeepEqual(files_before, files_after) { + t.Errorf("Expected files_before and files_after to differ. files_after: %v\n", files_after) + } +}