From 8f66b9e86a18e34fc017fb2b33a298eef9c4bddc Mon Sep 17 00:00:00 2001 From: David Dymko Date: Sun, 21 Jul 2024 07:46:51 -0400 Subject: [PATCH 1/9] goreleaser setup for parser builds --- .gitignore | 3 +++ Makefile | 4 ++++ assets/.goreleaser.yaml | 13 +++++++++++++ assets/embed.go | 11 +++++++++++ embed.go | 8 -------- 5 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 assets/.goreleaser.yaml create mode 100644 assets/embed.go delete mode 100644 embed.go diff --git a/.gitignore b/.gitignore index 23bf8fb..0faa833 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ parser config.json + +# Parser build output for binaries +./assets/dist/ \ No newline at end of file diff --git a/Makefile b/Makefile index 70a1df3..8682f5c 100644 --- a/Makefile +++ b/Makefile @@ -8,3 +8,7 @@ build-skiff: .Phony: build-all build-all: build-parser build-skiff + +.Phony: parser-build-binaries +parser-build-binaries: + goreleaser release --snapshot --clean --config=./assets/.goreleaser.yaml \ No newline at end of file diff --git a/assets/.goreleaser.yaml b/assets/.goreleaser.yaml new file mode 100644 index 0000000..a3fe074 --- /dev/null +++ b/assets/.goreleaser.yaml @@ -0,0 +1,13 @@ +version: 2 + +dist: ./dist + +builds: + - + main: ./cmd/parser/main.go + env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin \ No newline at end of file diff --git a/assets/embed.go b/assets/embed.go new file mode 100644 index 0000000..a8b929a --- /dev/null +++ b/assets/embed.go @@ -0,0 +1,11 @@ +package hookinator + +import _ "embed" + +// This file is meant to embed the parser into skiff. This allows skiff to install the parser onto your machine + +//go:embed dist/hookinator_darwin_amd64_v1/hookinator +var MacOSIntel []byte + +//go:embed dist/hookinator_darwin_arm64/hookinator +var MacOSSilicon []byte diff --git a/embed.go b/embed.go deleted file mode 100644 index 4596842..0000000 --- a/embed.go +++ /dev/null @@ -1,8 +0,0 @@ -package hookinator - -import _ "embed" - -// This file is meant to embed the parser into skiff. This allows skiff to install the parser onto your machine - -//go:embed assets/parser -var Parser []byte From deae4a5f2bf73e573141d38a09e0dd4875d4e28d Mon Sep 17 00:00:00 2001 From: David Dymko Date: Sun, 21 Jul 2024 07:56:02 -0400 Subject: [PATCH 2/9] tweak parser goreleaser and add main goreleaser with before hook --- .gitignore | 3 ++- .goreleaser.yaml | 44 +++++++++++++++++++++++++++++++++++++++ assets/.goreleaser.yaml | 9 +++++--- assets/embed.go | 2 +- internal/embed/embeder.go | 6 ++++-- 5 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 .goreleaser.yaml diff --git a/.gitignore b/.gitignore index 0faa833..b186b62 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ parser config.json # Parser build output for binaries -./assets/dist/ \ No newline at end of file +/assets/dist/ +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..206f5f2 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,44 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com + +# The lines below are called `modelines`. See `:help modeline` +# Feel free to remove those if you don't want/need to use them. +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj + +version: 2 + +before: + hooks: + - make parser-build-binaries + + +#builds: +# - env: +# - CGO_ENABLED=0 +# goos: +# - linux +# - windows +# - darwin +# +#archives: +# - format: tar.gz +# # this name template makes the OS and Arch compatible with the results of `uname`. +# name_template: >- +# {{ .ProjectName }}_ +# {{- title .Os }}_ +# {{- if eq .Arch "amd64" }}x86_64 +# {{- else if eq .Arch "386" }}i386 +# {{- else }}{{ .Arch }}{{ end }} +# {{- if .Arm }}v{{ .Arm }}{{ end }} +# # use zip for windows archives +# format_overrides: +# - goos: windows +# format: zip +# +#changelog: +# sort: asc +# filters: +# exclude: +# - "^docs:" +# - "^test:" diff --git a/assets/.goreleaser.yaml b/assets/.goreleaser.yaml index a3fe074..8151a60 100644 --- a/assets/.goreleaser.yaml +++ b/assets/.goreleaser.yaml @@ -1,10 +1,13 @@ +# This .goreleaser.yaml configuration is used to generate all parser binaries. +# These binaries are then embedded into the main application, allowing the main +# application to install the parser on the user's machine. The embedding process +# is facilitated through the use of `//go:embed` directives in `assets/embed.go`. version: 2 -dist: ./dist +dist: ./assets/dist builds: - - - main: ./cmd/parser/main.go + - main: ./cmd/parser/main.go env: - CGO_ENABLED=0 goos: diff --git a/assets/embed.go b/assets/embed.go index a8b929a..2ca4246 100644 --- a/assets/embed.go +++ b/assets/embed.go @@ -1,4 +1,4 @@ -package hookinator +package assets import _ "embed" diff --git a/internal/embed/embeder.go b/internal/embed/embeder.go index ec7b17e..3fb5edf 100644 --- a/internal/embed/embeder.go +++ b/internal/embed/embeder.go @@ -4,13 +4,15 @@ import ( "os" "path/filepath" - "github.com/devbytes-cloud/hookinator" + "github.com/devbytes-cloud/hookinator/assets" ) +// Factory pattern + // WriteBinary ... func WriteBinary() error { op := filepath.Join(".", "parser") - if err := os.WriteFile(op, hookinator.Parser, 0o755); err != nil { + if err := os.WriteFile(op, assets.MacOSSilicon, 0o755); err != nil { return err } From 3752507a8aaff154b806ba14aa45c94c18939ee8 Mon Sep 17 00:00:00 2001 From: David Dymko Date: Sun, 21 Jul 2024 08:31:36 -0400 Subject: [PATCH 3/9] rename parser to railcar --- .gitignore | 2 +- .goreleaser.yaml | 2 +- Makefile | 4 +-- assets/.goreleaser.yaml | 8 ++++-- assets/embed.go | 6 ++-- cmd/{parser => railcar}/main.go | 12 ++++---- config.json | 13 --------- internal/blueprint/templates/config.go | 2 +- internal/blueprint/templates/hooks.go | 4 +-- internal/commands/root.go | 3 +- internal/embed/embeder.go | 39 ++++++++++++++++++++++++-- 11 files changed, 60 insertions(+), 35 deletions(-) rename cmd/{parser => railcar}/main.go (88%) delete mode 100755 config.json diff --git a/.gitignore b/.gitignore index b186b62..b49c209 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -parser +railcar config.json # Parser build output for binaries diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 206f5f2..b54ce20 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -10,7 +10,7 @@ version: 2 before: hooks: - - make parser-build-binaries + - make railcar-build-binaries #builds: diff --git a/Makefile b/Makefile index 8682f5c..b59bf59 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,6 @@ build-skiff: .Phony: build-all build-all: build-parser build-skiff -.Phony: parser-build-binaries -parser-build-binaries: +.Phony: railcar-build-binaries +railcar-build-binaries: goreleaser release --snapshot --clean --config=./assets/.goreleaser.yaml \ No newline at end of file diff --git a/assets/.goreleaser.yaml b/assets/.goreleaser.yaml index 8151a60..e164d71 100644 --- a/assets/.goreleaser.yaml +++ b/assets/.goreleaser.yaml @@ -1,13 +1,15 @@ -# This .goreleaser.yaml configuration is used to generate all parser binaries. +# This .goreleaser.yaml configuration is used to generate all railcar binaries. # These binaries are then embedded into the main application, allowing the main -# application to install the parser on the user's machine. The embedding process +# application to install the railcar on the user's machine. The embedding process # is facilitated through the use of `//go:embed` directives in `assets/embed.go`. version: 2 dist: ./assets/dist builds: - - main: ./cmd/parser/main.go + - id: railcar + binary: railcar + main: ./cmd/railcar/main.go env: - CGO_ENABLED=0 goos: diff --git a/assets/embed.go b/assets/embed.go index 2ca4246..d91d875 100644 --- a/assets/embed.go +++ b/assets/embed.go @@ -2,10 +2,10 @@ package assets import _ "embed" -// This file is meant to embed the parser into skiff. This allows skiff to install the parser onto your machine +// This file is meant to embed the railcar into skiff. This allows skiff to install the railcar onto your machine -//go:embed dist/hookinator_darwin_amd64_v1/hookinator +//go:embed dist/railcar_darwin_amd64_v1/railcar var MacOSIntel []byte -//go:embed dist/hookinator_darwin_arm64/hookinator +//go:embed dist/railcar_darwin_arm64/railcar var MacOSSilicon []byte diff --git a/cmd/parser/main.go b/cmd/railcar/main.go similarity index 88% rename from cmd/parser/main.go rename to cmd/railcar/main.go index b3bf769..dfbb788 100644 --- a/cmd/parser/main.go +++ b/cmd/railcar/main.go @@ -10,14 +10,14 @@ import ( "github.com/devbytes-cloud/hookinator/internal/blueprint" ) -type Hookinator struct { +type RailCar struct { PreCommit map[string]string `json:"pre-commit"` PostCommit map[string]string `json:"post-commit"` CommitMsg map[string]string `json:"commit-msg"` } type Config struct { - Hookinator Hookinator `json:"skiff"` + RailCar RailCar `json:"carriage"` } func main() { @@ -49,13 +49,13 @@ func main() { // Process the commit message fmt.Println("Commit message is:", os.Args[2]) - if len(config.Hookinator.CommitMsg) != 0 { - run(config.Hookinator.CommitMsg, os.Args[2]) + if len(config.RailCar.CommitMsg) != 0 { + run(config.RailCar.CommitMsg, os.Args[2]) } case blueprint.PreCommit: - if len(config.Hookinator.PreCommit) != 0 { - run(config.Hookinator.PreCommit, "") + if len(config.RailCar.PreCommit) != 0 { + run(config.RailCar.PreCommit, "") } } diff --git a/config.json b/config.json deleted file mode 100755 index 4659513..0000000 --- a/config.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "skiff": { - "pre-commit": { - "echo": "echo skiff is running!" - }, - "prepare-commit-msg": { - }, - "commit-msg": { - }, - "post-commit": { - } - } -} \ No newline at end of file diff --git a/internal/blueprint/templates/config.go b/internal/blueprint/templates/config.go index c3e97fc..b93f7f5 100644 --- a/internal/blueprint/templates/config.go +++ b/internal/blueprint/templates/config.go @@ -1,7 +1,7 @@ package templates const Config = `{ - "skiff": { + "carriage": { "pre-commit": { "echo": "echo skiff is running!" }, diff --git a/internal/blueprint/templates/hooks.go b/internal/blueprint/templates/hooks.go index b79412d..714c694 100644 --- a/internal/blueprint/templates/hooks.go +++ b/internal/blueprint/templates/hooks.go @@ -2,6 +2,6 @@ package templates const PreHookTmpl = `#!/bin/bash echo "================================" -echo "Skiff {{ .Type }} Hook" +echo "Carriage {{ .Type }} Hook" echo "================================" -{{ .Path }}/parser {{ .Type }} $1` +{{ .Path }}/railcar {{ .Type }} $1` diff --git a/internal/commands/root.go b/internal/commands/root.go index 5805c13..ff8c187 100644 --- a/internal/commands/root.go +++ b/internal/commands/root.go @@ -5,9 +5,10 @@ import ( "fmt" "os" + "github.com/devbytes-cloud/hookinator/internal/validate" + "github.com/devbytes-cloud/hookinator/internal/blueprint" "github.com/devbytes-cloud/hookinator/internal/embed" - "github.com/devbytes-cloud/hookinator/internal/validate" "github.com/spf13/cobra" ) diff --git a/internal/embed/embeder.go b/internal/embed/embeder.go index 3fb5edf..07a0321 100644 --- a/internal/embed/embeder.go +++ b/internal/embed/embeder.go @@ -1,20 +1,55 @@ package embed import ( + "fmt" "os" "path/filepath" + "runtime" "github.com/devbytes-cloud/hookinator/assets" ) // Factory pattern +const ( + macOSSilicon string = "darwin-arm64" + macOSIntel string = "darwin-amd64" +) + // WriteBinary ... func WriteBinary() error { - op := filepath.Join(".", "parser") - if err := os.WriteFile(op, assets.MacOSSilicon, 0o755); err != nil { + systemInfo := fmt.Sprintf("%s-%s", fetchOS(), fetchArch()) + binary := fetchBinary(systemInfo) + + if binary == nil { + panic("couldn't find matching os and arch") + } + + op := filepath.Join(".", "railcar") + if err := os.WriteFile(op, binary, 0o755); err != nil { return err } return nil } + +func fetchBinary(systemInfo string) []byte { + switch systemInfo { + case macOSSilicon: + return assets.MacOSSilicon + case macOSIntel: + return assets.MacOSIntel + default: + return nil + } +} + +// fetchOS returns the current os that is running +func fetchOS() string { + return runtime.GOOS +} + +// fetchArch returns the current architecture that is running +func fetchArch() string { + return runtime.GOARCH +} From 032c7fc59d1c056b8d6ba7d43dfcce34e5e18b68 Mon Sep 17 00:00:00 2001 From: David Dymko Date: Sun, 21 Jul 2024 08:46:56 -0400 Subject: [PATCH 4/9] added remaining assets --- assets/.goreleaser.yaml | 6 +++++- assets/embed.go | 18 ++++++++++++++++++ internal/embed/embeder.go | 18 ++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/assets/.goreleaser.yaml b/assets/.goreleaser.yaml index e164d71..360248f 100644 --- a/assets/.goreleaser.yaml +++ b/assets/.goreleaser.yaml @@ -15,4 +15,8 @@ builds: goos: - linux - windows - - darwin \ No newline at end of file + - darwin + goarch: + - amd64 + - arm + - arm64 \ No newline at end of file diff --git a/assets/embed.go b/assets/embed.go index d91d875..cae00f1 100644 --- a/assets/embed.go +++ b/assets/embed.go @@ -9,3 +9,21 @@ var MacOSIntel []byte //go:embed dist/railcar_darwin_arm64/railcar var MacOSSilicon []byte + +//go:embed dist/railcar_linux_amd64_v1/railcar +var LinuxAMD64 []byte + +//go:embed dist/railcar_linux_arm64/railcar +var LinuxARM64 []byte + +//go:embed dist/railcar_linux_arm_6/railcar +var LinuxARM32 []byte + +//go:embed dist/railcar_windows_amd64_v1/railcar.exe +var WindowsAMD64 []byte + +//go:embed dist/railcar_windows_arm64/railcar.exe +var WindowsARM64 []byte + +//go:embed dist/railcar_windows_arm_6/railcar.exe +var WindowsARM32 []byte diff --git a/internal/embed/embeder.go b/internal/embed/embeder.go index 07a0321..c4e66bd 100644 --- a/internal/embed/embeder.go +++ b/internal/embed/embeder.go @@ -14,6 +14,12 @@ import ( const ( macOSSilicon string = "darwin-arm64" macOSIntel string = "darwin-amd64" + linuxAMD64 string = "linux-amd64" + linuxARM64 string = "linux-arm64" + linuxARM32 string = "linux-arm" + windowsAMD64 string = "windows-amd64" + windowsARM64 string = "windows-arm64" + windowsARM32 string = "windows-arm" ) // WriteBinary ... @@ -39,6 +45,18 @@ func fetchBinary(systemInfo string) []byte { return assets.MacOSSilicon case macOSIntel: return assets.MacOSIntel + case linuxAMD64: + return assets.LinuxAMD64 + case linuxARM64: + return assets.LinuxARM64 + case linuxARM32: + return assets.LinuxARM32 + case windowsAMD64: + return assets.WindowsAMD64 + case windowsARM64: + return assets.WindowsARM64 + case windowsARM32: + return assets.WindowsARM32 default: return nil } From 7b3485f53800d444e3f1486150d26283293e26b6 Mon Sep 17 00:00:00 2001 From: David Dymko Date: Mon, 22 Jul 2024 11:06:42 -0400 Subject: [PATCH 5/9] minor cleanup --- Makefile | 2 +- assets/.goreleaser.yaml | 2 +- internal/embed/embeder.go | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index b59bf59..d3ca847 100644 --- a/Makefile +++ b/Makefile @@ -11,4 +11,4 @@ build-all: build-parser build-skiff .Phony: railcar-build-binaries railcar-build-binaries: - goreleaser release --snapshot --clean --config=./assets/.goreleaser.yaml \ No newline at end of file + goreleaser release --snapshot --clean --config=./assets/.goreleaser.yaml diff --git a/assets/.goreleaser.yaml b/assets/.goreleaser.yaml index 360248f..56312a4 100644 --- a/assets/.goreleaser.yaml +++ b/assets/.goreleaser.yaml @@ -19,4 +19,4 @@ builds: goarch: - amd64 - arm - - arm64 \ No newline at end of file + - arm64 diff --git a/internal/embed/embeder.go b/internal/embed/embeder.go index c4e66bd..413ef0e 100644 --- a/internal/embed/embeder.go +++ b/internal/embed/embeder.go @@ -9,8 +9,7 @@ import ( "github.com/devbytes-cloud/hookinator/assets" ) -// Factory pattern - +// List of supported OS + Arch railcar binaries const ( macOSSilicon string = "darwin-arm64" macOSIntel string = "darwin-amd64" @@ -22,13 +21,13 @@ const ( windowsARM32 string = "windows-arm" ) -// WriteBinary ... +// WriteBinary will install railcar into your working directory func WriteBinary() error { systemInfo := fmt.Sprintf("%s-%s", fetchOS(), fetchArch()) binary := fetchBinary(systemInfo) if binary == nil { - panic("couldn't find matching os and arch") + return fmt.Errorf("no matching railcar binary for %s", systemInfo) } op := filepath.Join(".", "railcar") @@ -39,6 +38,7 @@ func WriteBinary() error { return nil } +// fetchBinary will return the proper railcar binary for your system func fetchBinary(systemInfo string) []byte { switch systemInfo { case macOSSilicon: From edba7b0ea48a657fbde8a192a7a884d9c59f462a Mon Sep 17 00:00:00 2001 From: David Dymko Date: Mon, 22 Jul 2024 11:31:09 -0400 Subject: [PATCH 6/9] adding tests --- Makefile | 4 ++++ go.mod | 8 ++++++- go.sum | 8 +++++++ internal/embed/embeder_test.go | 39 ++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 internal/embed/embeder_test.go diff --git a/Makefile b/Makefile index d3ca847..6a3d246 100644 --- a/Makefile +++ b/Makefile @@ -12,3 +12,7 @@ build-all: build-parser build-skiff .Phony: railcar-build-binaries railcar-build-binaries: goreleaser release --snapshot --clean --config=./assets/.goreleaser.yaml + +.Phony: go-test +go-test: + go test ./... --race \ No newline at end of file diff --git a/go.mod b/go.mod index d553fe1..1d7f121 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,15 @@ module github.com/devbytes-cloud/hookinator go 1.22.4 -require github.com/spf13/cobra v1.8.1 +require ( + github.com/spf13/cobra v1.8.1 + github.com/stretchr/testify v1.9.0 +) require ( + github.com/davecgh/go-spew v1.1.1 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/spf13/pflag v1.0.5 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 912390a..4353b61 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,18 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +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= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +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/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 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.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +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= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/embed/embeder_test.go b/internal/embed/embeder_test.go new file mode 100644 index 0000000..eb65da7 --- /dev/null +++ b/internal/embed/embeder_test.go @@ -0,0 +1,39 @@ +package embed + +import ( + "fmt" + "os" + "runtime" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestWriteBinary(t *testing.T) { + err := WriteBinary() + assert.NoError(t, err) + assert.FileExists(t, "./railcar") + defer func() { + err := os.Remove("./railcar") + assert.NoError(t, err) + }() +} + +func TestFetchBinary(t *testing.T) { + t.Run("binary does not exist", func(t *testing.T) { + assert.Nil(t, fetchBinary("junk")) + }) + + t.Run("binary exists", func(t *testing.T) { + systemInfo := fmt.Sprintf("%s-%s", fetchOS(), fetchArch()) + assert.NotNil(t, fetchBinary(systemInfo)) + }) +} + +func TestFetchOS(t *testing.T) { + assert.Equal(t, runtime.GOOS, fetchOS()) +} + +func TestFetchArch(t *testing.T) { + assert.Equal(t, runtime.GOARCH, fetchArch()) +} From 495af27225661b5c6f60759761fc4e31ce95a844 Mon Sep 17 00:00:00 2001 From: David Dymko Date: Mon, 22 Jul 2024 11:33:19 -0400 Subject: [PATCH 7/9] newline --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6a3d246..1ddfccb 100644 --- a/Makefile +++ b/Makefile @@ -15,4 +15,4 @@ railcar-build-binaries: .Phony: go-test go-test: - go test ./... --race \ No newline at end of file + go test ./... --race From 6cd3efdfa1616b41ef9d8ce296de6c15137cc0d8 Mon Sep 17 00:00:00 2001 From: David Dymko Date: Mon, 22 Jul 2024 11:34:10 -0400 Subject: [PATCH 8/9] docs --- assets/embed.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/embed.go b/assets/embed.go index cae00f1..8d5cb94 100644 --- a/assets/embed.go +++ b/assets/embed.go @@ -2,7 +2,7 @@ package assets import _ "embed" -// This file is meant to embed the railcar into skiff. This allows skiff to install the railcar onto your machine +// This file is meant to embed the railcar into freight. This allows freight to install the railcar onto your machine //go:embed dist/railcar_darwin_amd64_v1/railcar var MacOSIntel []byte From dc472f7bad14939dfb1d962a0397c1d491211dbe Mon Sep 17 00:00:00 2001 From: David Dymko Date: Mon, 22 Jul 2024 11:35:48 -0400 Subject: [PATCH 9/9] cleanup --- internal/embed/embeder.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/internal/embed/embeder.go b/internal/embed/embeder.go index 413ef0e..c9302d0 100644 --- a/internal/embed/embeder.go +++ b/internal/embed/embeder.go @@ -31,11 +31,7 @@ func WriteBinary() error { } op := filepath.Join(".", "railcar") - if err := os.WriteFile(op, binary, 0o755); err != nil { - return err - } - - return nil + return os.WriteFile(op, binary, 0o755) } // fetchBinary will return the proper railcar binary for your system