Move icon generation into dedicated files

This commit is contained in:
2022-12-26 12:14:41 +01:00
parent c7450fcdaa
commit b84f291d2b
8 changed files with 303 additions and 265 deletions

View File

@ -1,9 +1,7 @@
package main
import (
"bytes"
_ "embed"
"image/png"
"net/http"
"net/http/httptest"
"os"
@ -87,31 +85,6 @@ func TestCorrectResponseForGHColorSchemeAndPattern(t *testing.T) {
}
}
func TestIgnoreCase(t *testing.T) {
w1 := bytes.NewBuffer([]byte{})
png.Encode(w1, genIdIcon("example", 80, colorV1))
w2 := bytes.NewBuffer([]byte{})
png.Encode(w2, genIdIcon("Example", 80, colorV1))
if bytes.Compare(w1.Bytes(), w2.Bytes()) != 0 {
t.Errorf("resulting images do not match")
}
}
func TestStringMatchesHash(t *testing.T) {
w1 := bytes.NewBuffer([]byte{})
// MD5 of lowercase 'example'
png.Encode(w1, genIdIcon("1a79a4d60de6718e8e5b326e338ae533", 80, colorV2))
w2 := bytes.NewBuffer([]byte{})
png.Encode(w2, genIdIcon("Example", 80, colorV2))
if bytes.Compare(w1.Bytes(), w2.Bytes()) != 0 {
t.Errorf("resulting images do not match")
}
}
func TestUsesConfig(t *testing.T) {
configure("./testdata/testconfig.toml")
@ -154,30 +127,3 @@ func TestCorrectResponseForUserConfig(t *testing.T) {
t.Errorf("returned image does not match expected image for mapped alias '42'")
}
}
func TestHSLtoRGB(t *testing.T) {
red := hslToRgba(0, 100, 50)
if red.R != 255 || red.G != 0 || red.B != 0 {
t.Errorf("Color red not as required")
}
green := hslToRgba(120, 100, 50)
if green.R != 0 || green.G != 255 || green.B != 0 {
t.Errorf("Color green not as required")
}
blue := hslToRgba(240, 100, 50)
if blue.R != 0 || blue.G != 0 || blue.B != 255 {
t.Errorf("Color blue not as required")
}
}
func TestShouldCreateNibbles(t *testing.T) {
hash := [16]byte{}
hash[0] = 0x12
nibbles := nibbles(hash)
if nibbles[0] != 0x01 || nibbles[1] != 02 {
t.Errorf("Nibbles not extracted as expected")
}
}