Commits

Paul Ruane  committed 4511048

Added unit-test for fingerprinter.
Modified Makefile to allow unit-tests to be run.

  • Participants
  • Parent commits 74d8ff2

Comments (0)

Files changed (2)

File src/main/Makefile

 include $(GOROOT)/src/Make.inc
 
 TARG=tmsu
+
 GOFILES=command.go \
 		commands/delete.go \
 		commands/dupes.go \
 		version.gen.go \
 
 include $(GOROOT)/src/Make.cmd
+
+test:
+	gotest

File src/main/fingerprinter_test.go

+/*
+Copyright 2011 Paul Ruane.
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+package main
+
+import (
+    "os"
+    "path/filepath"
+    "testing"
+)
+
+func TestFingerprint(test *testing.T) {
+    tempDir := os.TempDir()
+    tempFilePath := filepath.Join(tempDir, "tmsu-fingerprint")
+
+    file, err := os.Create(tempFilePath)
+    if err != nil { test.Fatal(err.Error()) }
+    defer os.Remove(tempFilePath)
+
+    _, err = file.WriteString("They were the footprints of a giagantic hound.")
+    if err != nil { test.Fatal(err.Error()) }
+
+    fingerprint, err := Fingerprint(tempFilePath)
+    if err != nil { test.Fatal(err.Error()) }
+
+    if fingerprint != "87d74123749a45e4c4e5e9053986d7ae878268a8e301d1b8125791517c0d39bf" { test.Fatal("Fingerprint incorrect.") }
+}