-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests and simplify sha1 generation
- Loading branch information
Showing
3 changed files
with
43 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,7 @@ fmt: | |
vet: | ||
go vet ./... | ||
|
||
build: fmt vet | ||
test: | ||
go test -v | ||
|
||
build: fmt vet test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package etag | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestNotWeekEtag(t *testing.T) { | ||
inputStr := `<html> | ||
<head> | ||
<title>test page</title> | ||
</head> | ||
<body> | ||
<p>test page html</p> | ||
</body> | ||
</html>` | ||
expectedOut := fmt.Sprintf("%d-%s", len(inputStr), getHash(inputStr)) | ||
generatedOut := Generate(inputStr, false) | ||
if generatedOut != expectedOut { | ||
t.Fatalf("Incorrect Etag generated") | ||
} | ||
} | ||
|
||
func TestWeekEtag(t *testing.T) { | ||
inputStr := `<html> | ||
<head> | ||
<title>test page</title> | ||
</head> | ||
<body> | ||
<p>test page html</p> | ||
</body> | ||
</html>` | ||
expectedOut := fmt.Sprintf("W/%d-%s", len(inputStr), getHash(inputStr)) | ||
generatedOut := Generate(inputStr, true) | ||
if generatedOut != expectedOut { | ||
t.Fatalf("Incorrect Etag generated") | ||
} | ||
} |