Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add iterm test #14

Merged
merged 4 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ linters:
- exportloopref
- depguard
- wrapcheck
- testpackage

issues:
exclude-rules:
Expand Down
3 changes: 0 additions & 3 deletions cmd/gen/export_test.go

This file was deleted.

41 changes: 40 additions & 1 deletion cmd/gen/init_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,50 @@
package gen_test
package gen

import (
"io"
"os"
"path"
"testing"
)

func TestMain(m *testing.M) {
code := m.Run()
os.Exit(code)
}

func genTestDir(t *testing.T) (string, string) {
t.Helper()

tempDir := t.TempDir()

configFilePath := path.Join(tempDir, "config.yaml")

cwDir, err := os.Getwd()
if err != nil {
t.Fatal(err)
}

testConfig, err := os.Open(path.Join(cwDir, "../../data/config.yaml"))
if err != nil {
t.Fatal(err)
}
defer testConfig.Close()

configFile, err := os.Create(configFilePath)
if err != nil {
t.Fatal(err)
}
defer configFile.Close()

_, err = io.Copy(configFile, testConfig)
if err != nil {
t.Fatal(err)
}

err = os.WriteFile(configFilePath, []byte("name: test"), 0o600)
if err != nil {
t.Fatal(err)
}

return configFilePath, tempDir
}
12 changes: 12 additions & 0 deletions cmd/gen/iterm_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package gen

import (
"testing"
)

func TestItermCmd(t *testing.T) {
t.Parallel()

configFilePath, tempDir := genTestDir(t)
itermCmd.Run(itermCmd, []string{configFilePath, tempDir})
}
58 changes: 4 additions & 54 deletions cmd/gen/vscode_test.go
Original file line number Diff line number Diff line change
@@ -1,62 +1,12 @@
package gen_test
package gen

import (
"io"
"os"
"path"
"testing"

"github.com/shiron-dev/arcanum-hue/cmd/gen"
)

var originalArgs = os.Args

func setArgs(arg string) {
//nolint:gocritic
os.Args = append(originalArgs, arg)
}

func resetArgs() {
os.Args = originalArgs
}

func Test_vscodeCmd(t *testing.T) {
func TestVSCodeCmd(t *testing.T) {
t.Parallel()

setArgs("sub")

defer resetArgs()

tempDir := t.TempDir()

configFilePath := path.Join(tempDir, "config.yaml")

cwDir, err := os.Getwd()
if err != nil {
t.Fatal(err)
}

testConfig, err := os.Open(path.Join(cwDir, "../../data/config.yaml"))
if err != nil {
t.Fatal(err)
}
defer testConfig.Close()

configFile, err := os.Create(configFilePath)
if err != nil {
t.Fatal(err)
}
defer configFile.Close()

_, err = io.Copy(configFile, testConfig)
if err != nil {
t.Fatal(err)
}

err = os.WriteFile(configFilePath, []byte("name: test"), 0o600)
if err != nil {
t.Fatal(err)
}

gen.VSCodeCmd.Run(gen.VSCodeCmd, []string{configFilePath, tempDir})
configFilePath, tempDir := genTestDir(t)
vscodeCmd.Run(vscodeCmd, []string{configFilePath, tempDir})
}
3 changes: 3 additions & 0 deletions generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package main

//go:generate go run github.com/cweill/gotests/gotests -all -exported -parallel -w internal/converter/model/iterm.go
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ module github.com/shiron-dev/arcanum-hue
go 1.23.4

require (
github.com/cweill/gotests v1.6.0
github.com/spf13/cobra v1.8.1
go.uber.org/mock v0.5.0
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -12,6 +14,9 @@ require (
github.com/buger/jsonparser v1.1.1 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/tools v0.22.0 // indirect
)

require (
Expand Down
21 changes: 19 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xW
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cweill/gotests v1.6.0 h1:KJx+/p4EweijYzqPb4Y/8umDCip1Cv6hEVyOx0mE9W8=
github.com/cweill/gotests v1.6.0/go.mod h1:CaRYbxQZGQOxXDvM9l0XJVV2Tjb2E5H53vq+reR2GrA=
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/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
Expand All @@ -19,10 +21,25 @@ github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU=
go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20191109212701-97ad0ed33101/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
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/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
11 changes: 11 additions & 0 deletions internal/converter/model/init_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package model_test

import (
"os"
"testing"
)

func TestMain(m *testing.M) {
code := m.Run()
os.Exit(code)
}
68 changes: 68 additions & 0 deletions internal/converter/model/iterm_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package model

import (
"reflect"
"testing"
)

func TestItermColorsModelToPlistModel(t *testing.T) {
t.Parallel()
t.Skip("skipping test")
}

func TestHexToItermColor(t *testing.T) {
t.Parallel()

type args struct {
hex string
}

tests := []struct {
name string
args args
want ItermColor
}{
{
name: "Red",
args: args{hex: "#FF0000"},
want: ItermColor{
AlphaComponent: 1,
BlueComponent: 0,
ColorSpace: "P3",
GreenComponent: 0,
RedComponent: 1,
},
},
{
name: "Cyan",
args: args{hex: "#00FFFF"},
want: ItermColor{
AlphaComponent: 1,
BlueComponent: 1,
ColorSpace: "P3",
GreenComponent: 1,
RedComponent: 0,
},
},
{
name: "aquamarine alpha",
args: args{hex: "#7FFFD470"},
want: ItermColor{
AlphaComponent: 0.4392156862745098,
BlueComponent: 0.8313725490196079,
ColorSpace: "P3",
GreenComponent: 1,
RedComponent: 0.4980392156862745,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

if got := hexToItermColor(tt.args.hex); !reflect.DeepEqual(got, tt.want) {
t.Errorf("HexToItermColor() = %v, want %v", got, tt.want)
}
})
}
}
3 changes: 3 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
"warningForeground": {
"type": "string"
},
"linkForeground": {
"type": "string"
},
"background": {
"type": "string"
},
Expand Down
9 changes: 9 additions & 0 deletions tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build tools
// +build tools

package main

import (
_ "github.com/cweill/gotests"
_ "go.uber.org/mock/mockgen"
)
Loading