Skip to content

Commit 88df63a

Browse files
committed
all: setup tests
1 parent ffbd42f commit 88df63a

File tree

8 files changed

+99
-7
lines changed

8 files changed

+99
-7
lines changed

.github/FUNDING.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These are supported funding model platforms
2+
3+
github: [changkun] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4+
patreon: # Replace with a single Patreon username
5+
open_collective: # Replace with a single Open Collective username
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay: # Replace with a single Liberapay username
10+
issuehunt: # Replace with a single IssueHunt username
11+
otechie: # Replace with a single Otechie username
12+
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

.github/workflows/code2img.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2021 The golang.design Initiative authors.
2+
# All rights reserved. Use of this source code is governed
3+
# by a GNU GPL-3.0 license that can be found in the LICENSE file.
4+
#
5+
# Written by Changkun Ou <changkun.de>
6+
7+
name: code2img
8+
9+
on:
10+
push:
11+
branches: [ main ]
12+
pull_request:
13+
branches: [ main ]
14+
15+
jobs:
16+
platform_test:
17+
18+
runs-on: ${{ matrix.os }}
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
os: [ubuntu-latest, macos-latest]
23+
24+
steps:
25+
- uses: actions/checkout@v2
26+
- uses: actions/setup-go@v2
27+
with:
28+
stable: 'false'
29+
go-version: '1.16.0'
30+
31+
- name: Test
32+
run: |
33+
go test -v -covermode=atomic ./...

code2img.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
// Copyright 2020 The golang.design Initiative authors.
1+
// Copyright 2021 The golang.design Initiative authors.
22
// All rights reserved. Use of this source code is governed
33
// by a GNU GPL-3.0 license that can be found in the LICENSE file.
4+
//
5+
// Written by Changkun Ou <changkun.de>
46

57
package code2img
68

code2img_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2021 The golang.design Initiative authors.
2+
// All rights reserved. Use of this source code is governed
3+
// by a GNU GPL-3.0 license that can be found in the LICENSE file.
4+
//
5+
// Written by Changkun Ou <changkun.de>
6+
7+
package code2img_test
8+
9+
import (
10+
"bytes"
11+
"image/png"
12+
"math"
13+
"os"
14+
"testing"
15+
16+
"golang.design/x/code2img"
17+
)
18+
19+
func TestRender(t *testing.T) {
20+
got, err := code2img.Render(`import "golang.design/x/code2img`)
21+
if err != nil {
22+
t.Fatalf("render failed: %v", err)
23+
}
24+
25+
imgGot, err := png.Decode(bytes.NewReader(got))
26+
if err != nil {
27+
t.Fatalf("cannot read rendered image: %v", err)
28+
}
29+
30+
want, err := os.ReadFile("testdata.png")
31+
if err != nil {
32+
t.Fatalf("cannot read gold test file: %v", err)
33+
}
34+
35+
imgWant, err := png.Decode(bytes.NewReader(want))
36+
if err != nil {
37+
t.Fatalf("cannot read gold image: %v", err)
38+
}
39+
40+
if math.Abs(float64(imgGot.Bounds().Dx()-imgWant.Bounds().Dx())) > 5 ||
41+
math.Abs(float64(imgGot.Bounds().Dy()-imgWant.Bounds().Dy())) > 5 {
42+
43+
err := os.WriteFile("got.png", got, os.ModePerm)
44+
if err != nil {
45+
t.Errorf("failed to write image: %v", err)
46+
}
47+
48+
t.Fatalf("image size does not match: got %+v, want %+v", imgGot.Bounds(), imgWant.Bounds())
49+
}
50+
}

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
module golang.design/x/code2img
22

3-
go 1.15
3+
go 1.16
44

55
require (
66
github.com/chromedp/cdproto v0.0.0-20200116234248-4da64dd111ac
77
github.com/chromedp/chromedp v0.5.3
88
github.com/gin-gonic/gin v1.6.3
99
github.com/google/uuid v1.1.2
10-
github.com/sirupsen/logrus v1.7.0
1110
)

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,14 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLD
4444
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
4545
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4646
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
47-
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
48-
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
4947
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
50-
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
5148
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
5249
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
5350
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
5451
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
5552
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
5653
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
5754
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
58-
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
5955
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
6056
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
6157
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=

got.png

11.3 KB
Loading

testdata.png

12.1 KB
Loading

0 commit comments

Comments
 (0)