Skip to content

Commit

Permalink
Change UI tests to not build for now and add more colors.go tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyak committed Apr 4, 2022
1 parent a991d6d commit bc74676
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 39 deletions.
100 changes: 72 additions & 28 deletions common/colors_test.go
Original file line number Diff line number Diff line change
@@ -1,42 +1,86 @@
package common

import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
)

func TestColorHexThreeToSix(t *testing.T) {
expected := "RRGGBB"
result, _ := hexThreeToSix("RGB")
if result != expected {
t.Errorf("expected %#v, got %#v", expected, result)
func TestHexThreeToSix(t *testing.T) {
result, err := hexThreeToSix("RGB")

assert.NoError(t, err)
assert.Equal(t, "RRGGBB", result)
}

func TestHexThreeToSixErr(t *testing.T) {
for _, input := range []string{"", "R", "RG", "RGBA"} {
t.Run(input, func(t *testing.T) {
_, err := hexThreeToSix(input)
assert.Error(t, err)
})
}
}

func TestHex(t *testing.T) {
// The testing data layout is inputer, Expected Red, Exp Green, Exp Blue, expect error
data := [][]interface{}{
{"010203", 1, 2, 3, false},
{"100", 17, 0, 0, false},
{"100", 1, 0, 0, true},
{"1000", 0, 0, 0, true},
{"010203", 1, 2, 4, true},
{"0102GG", 1, 2, 4, true},
testCases := []struct {
input string
red int
green int
blue int
}{
{"010203", 1, 2, 3},
{"#010203", 1, 2, 3},
{"100", 17, 0, 0},
{"#100", 17, 0, 0},
{"FFF", 255, 255, 255},
{"#FFF", 255, 255, 255},
}

for _, tc := range testCases {
red, green, blue, err := hex(tc.input)

assert.NoError(t, err)
assert.Equal(t, tc.red, red)
assert.Equal(t, tc.green, green)
assert.Equal(t, tc.blue, blue)
}
}

func TestHexErr(t *testing.T) {
for _, s := range []string{"", "ZZZ", "0ZZ", "00Z", "1000", "0102GG"} {
t.Run(s, func(t *testing.T) {
_, _, _, err := hex(s)
assert.Error(t, err)
})
}
}

func TestRandomColor(t *testing.T) {
// Get coverage for randomness
for i := 0; i < 100; i++ {
color := RandomColor()

assert.Len(t, color, 7)
assert.True(t, strings.HasPrefix(color, "#"))
}
}

func TestIsValidColor(t *testing.T) {
for _, s := range []string{"FFF", "#FFF", "F0F0F0", "#F0F0F0", "red"} {
t.Run(s, func(t *testing.T) {
result := IsValidColor(s)
assert.True(t, result)
})
}
}

for i := range data {
input := data[i][0].(string)
r, g, b, err := hex(input)
if err != nil {
if !data[i][4].(bool) {
t.Errorf("with input %#v: %v", input, err)
}
continue
}

rr, rg, rb := data[i][1].(int), data[i][2].(int), data[i][3].(int)

if !data[i][4].(bool) && (r != rr || g != rg || b != rb) {
t.Errorf("expected %d, %d, %d - got %d, %d, %d", r, g, b, rr, rg, rb)
}
func TestIsValidColorErr(t *testing.T) {
for _, s := range []string{"FF", "#FF", "F0F0", "#F0F0", "ZZZ", "clear"} {
t.Run(s, func(t *testing.T) {
result := IsValidColor(s)
assert.False(t, result)
})
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ require (
github.com/gorilla/sessions v1.2.1
github.com/gorilla/websocket v1.4.2
github.com/nareix/joy4 v0.0.0-20200507095837-05a4ffbb5369
github.com/playwright-community/playwright-go v0.2000.0
github.com/stretchr/testify v1.7.1
)
13 changes: 3 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,25 @@ github.com/alexflint/go-arg v1.4.3 h1:9rwwEBpMXfKQKceuZfYcwuc/7YY7tWJbFsgG5cAU/u
github.com/alexflint/go-arg v1.4.3/go.mod h1:3PZ/wp/8HuqRZMUUgu7I+e1qcpUbvmS258mRXkFH4IA=
github.com/alexflint/go-scalar v1.1.0 h1:aaAouLLzI9TChcPXotr6gUhq+Scr8rl0P9P4PnltbhM=
github.com/alexflint/go-scalar v1.1.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o=
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 h1:y5HC9v93H5EPKqaS1UYVg1uYah5Xf51mBfIoWehClUQ=
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964/go.mod h1:Xd9hchkHSWYkEqJwUGisez3G1QY8Ryz0sdWrLPMGjLk=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw=
github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4=
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI=
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/h2non/filetype v1.1.1/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY=
github.com/nareix/joy4 v0.0.0-20200507095837-05a4ffbb5369 h1:Yp0zFEufLz0H7jzffb4UPXijavlyqlYeOg7dcyVUNnQ=
github.com/nareix/joy4 v0.0.0-20200507095837-05a4ffbb5369/go.mod h1:aFJ1ZwLjvHN4yEzE5Bkz8rD8/d8Vlj3UIuvz2yfET7I=
github.com/playwright-community/playwright-go v0.2000.0 h1:a3XGQ3oABMhRuwQWN39a7UtSd3OPDZexWT4KMuB/77k=
github.com/playwright-community/playwright-go v0.2000.0/go.mod h1:1y9cM9b9dVHnuRWzED1KLM7FtbwTJC8ibDjI6MNqewU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/square/go-jose.v2 v2.6.0 h1:NGk74WTnPKBNUhNzQX7PYcTLUjoq7mzKk2OKbvwk2iI=
gopkg.in/square/go-jose.v2 v2.6.0/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 2 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build ignore

package main

import (
Expand Down

0 comments on commit bc74676

Please sign in to comment.