diff --git a/.github/workflows/code.yml b/.github/workflows/code.yml index 307147d..6c2e6d8 100644 --- a/.github/workflows/code.yml +++ b/.github/workflows/code.yml @@ -1,25 +1,29 @@ -on: - pull_request: - paths: - - 'src/**' - -name: Validate Code -jobs: - test: - runs-on: ubuntu-latest - defaults: - run: - working-directory: ${{ github.workspace }}/src - steps: - - name: Install Go - uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed - with: - go-version: 1.22.4 - - name: Checkout code - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - - name: Golang CI - uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 - with: - working-directory: src - - name: Unit Tests - run: go test -v ./... +on: + pull_request: + paths: + - 'src/**' + +name: Validate Code +jobs: + test: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ${{ github.workspace }}/src + steps: + - name: Install Go + uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed + with: + go-version: 1.22.4 + - name: Checkout code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + - name: Golang CI + uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 + with: + working-directory: src + - name: Fieldalignment + run: | + go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@latest + fieldalignment "./..." + - name: Unit Tests + run: go test -v ./... diff --git a/src/config/config_test.go b/src/config/config_test.go index b1ad9e3..e23a7e4 100644 --- a/src/config/config_test.go +++ b/src/config/config_test.go @@ -31,15 +31,15 @@ func TestResolveConfigPath(t *testing.T) { func TestLoadConfig(t *testing.T) { tests := []struct { + expected *Aliae name string config string - expected *Aliae expectError bool }{ { - "Valid", - "aliae.valid.yaml", - &Aliae{ + name: "Valid", + config: "aliae.valid.yaml", + expected: &Aliae{ Aliae: shell.Aliae{ {Name: "test", Value: shell.Template("test")}, {Name: "test2", Value: shell.Template("test2")}, @@ -48,13 +48,11 @@ func TestLoadConfig(t *testing.T) { {Name: "TEST_ENV", Value: "test"}, }, }, - false, }, { - "Invalid", - "aliae.invalid.yaml", - nil, - true, + name: "Invalid", + config: "aliae.invalid.yaml", + expectError: true, }, } diff --git a/src/config/unmarshal.go b/src/config/unmarshal.go index 44ffc07..f9ddde1 100644 --- a/src/config/unmarshal.go +++ b/src/config/unmarshal.go @@ -21,8 +21,8 @@ type Aliae struct { type FuncMap []StringFunc type StringFunc struct { - Name []byte F func(string) ([]byte, error) + Name []byte } func customUnmarshaler(a *Aliae, b []byte) error { diff --git a/src/context/runtime.go b/src/context/runtime.go index 198b130..50c85cb 100644 --- a/src/context/runtime.go +++ b/src/context/runtime.go @@ -10,11 +10,11 @@ import ( var Current *Runtime type Runtime struct { + Path *Path Shell string OS string Home string Arch string - Path *Path } func Init(shell string) { diff --git a/src/shell/aliae.go b/src/shell/aliae.go index 6f2c9c9..808a0d2 100644 --- a/src/shell/aliae.go +++ b/src/shell/aliae.go @@ -13,18 +13,15 @@ var ( type Aliae []*Alias type Alias struct { - Name string `yaml:"name"` - Value Template `yaml:"value"` - Type Type `yaml:"type"` - If If `yaml:"if"` - - // PowerShell only options - Description string `yaml:"description"` - Force bool `yaml:"force"` - Option Option `yaml:"option"` - Scope Option `yaml:"scope"` - - template string + Name string `yaml:"name"` + Value Template `yaml:"value"` + Type Type `yaml:"type"` + If If `yaml:"if"` + Description string `yaml:"description"` + Option Option `yaml:"option"` + Scope Option `yaml:"scope"` + template string + Force bool `yaml:"force"` } type Option string diff --git a/src/shell/aliae_test.go b/src/shell/aliae_test.go index 3149437..071b3d8 100644 --- a/src/shell/aliae_test.go +++ b/src/shell/aliae_test.go @@ -152,8 +152,8 @@ def __foobar(): func TestAliaeRender(t *testing.T) { cases := []struct { Case string - Aliae Aliae Expected string + Aliae Aliae }{ { Case: "Single alias", diff --git a/src/shell/env.go b/src/shell/env.go index 79bd618..e6ab23a 100644 --- a/src/shell/env.go +++ b/src/shell/env.go @@ -10,15 +10,14 @@ import ( type Envs []*Env type Env struct { - Name string `yaml:"name"` Value interface{} `yaml:"value"` + Name string `yaml:"name"` Delimiter Template `yaml:"delimiter"` If If `yaml:"if"` - Persist bool `yaml:"persist"` Type EnvType `yaml:"type"` - - template string - parsed bool + template string + Persist bool `yaml:"persist"` + parsed bool } func (e *Env) string() string { diff --git a/src/shell/env_test.go b/src/shell/env_test.go index 16ef733..466f229 100644 --- a/src/shell/env_test.go +++ b/src/shell/env_test.go @@ -14,9 +14,9 @@ func TestEnvironmentVariable(t *testing.T) { } cases := []struct { Case string - Env Env Shell string Expected string + Env Env }{ { Case: "PWSH", @@ -160,9 +160,9 @@ func TestEnvRender(t *testing.T) { cases := []struct { Case string Shell string + Expected string Env Envs NonEmptyScript bool - Expected string }{ { Case: "PWSH - No elements", @@ -223,9 +223,9 @@ $env:FOO = "bar"`, func TestEnvironmentVariableDelimiter(t *testing.T) { cases := []struct { + Env *Env Case string Expected string - Env *Env }{ { Case: "No delimiter", diff --git a/src/shell/path.go b/src/shell/path.go index 79c8cb4..38c11b9 100644 --- a/src/shell/path.go +++ b/src/shell/path.go @@ -10,12 +10,11 @@ import ( type Paths []*Path type Path struct { - Value Template `yaml:"value"` - If If `yaml:"if"` - Persist bool `yaml:"persist"` - Force bool `yaml:"force"` - + Value Template `yaml:"value"` + If If `yaml:"if"` template string + Persist bool `yaml:"persist"` + Force bool `yaml:"force"` } func (p *Path) string() string { diff --git a/src/shell/path_test.go b/src/shell/path_test.go index acba8fc..991b7ae 100644 --- a/src/shell/path_test.go +++ b/src/shell/path_test.go @@ -157,9 +157,9 @@ func TestPathRender(t *testing.T) { cases := []struct { Case string Shell string + Expected string Paths Paths NonEmptyScript bool - Expected string }{ { Case: "PWSH - No PATHS", diff --git a/src/shell/pwsh_test.go b/src/shell/pwsh_test.go index e65accd..203e4ea 100644 --- a/src/shell/pwsh_test.go +++ b/src/shell/pwsh_test.go @@ -8,10 +8,10 @@ import ( func TestPowerShellCommandAlias(t *testing.T) { cases := []struct { + Alias *Alias Case string Shell string Expected string - Alias *Alias }{ { Case: "PWSH", diff --git a/src/shell/script_test.go b/src/shell/script_test.go index e602de8..bb4b19f 100644 --- a/src/shell/script_test.go +++ b/src/shell/script_test.go @@ -10,9 +10,9 @@ import ( func TestScriptRender(t *testing.T) { cases := []struct { Case string + Expected string Scripts Scripts NonEmptyScript bool - Expected string }{ { Case: "No content",