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

Adding abstract errors and Windows workflow #5

Merged
merged 1 commit into from
Apr 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
21 changes: 19 additions & 2 deletions .github/workflows/go-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- main

jobs:
go-tests:
go-tests-linux:
runs-on: ubuntu-latest

steps:
Expand All @@ -24,4 +24,21 @@ jobs:
- run: go version

- name: Run GARM Go Tests
run: make go-test
run: make go-test

go-tests-windows:
runs-on: windows-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Golang
uses: actions/setup-go@v3
with:
go-version-file: go.mod

- run: go version

- name: Run GARM Go Tests
run: go test -v ./... -timeout=15m -parallel=4
8 changes: 4 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (l *LXD) GetInstanceType() LXDImageType {
func (l *LXD) Validate() error {
if l.UnixSocket != "" {
if _, err := os.Stat(l.UnixSocket); err != nil {
return fmt.Errorf("could not access unix socket %s: %q", l.UnixSocket, err)
return fmt.Errorf("could not access unix socket %s: %w", l.UnixSocket, err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self. Disable the Unix socket handling when running on Windows. Only remote TCP connections will work.

}

return nil
Expand All @@ -146,16 +146,16 @@ func (l *LXD) Validate() error {
}

if _, err := os.Stat(l.ClientCertificate); err != nil {
return fmt.Errorf("failed to access client certificate %s: %q", l.ClientCertificate, err)
return fmt.Errorf("failed to access client certificate %s: %w", l.ClientCertificate, err)
}

if _, err := os.Stat(l.ClientKey); err != nil {
return fmt.Errorf("failed to access client key %s: %q", l.ClientKey, err)
return fmt.Errorf("failed to access client key %s: %w", l.ClientKey, err)
}

if l.TLSServerCert != "" {
if _, err := os.Stat(l.TLSServerCert); err != nil {
return fmt.Errorf("failed to access tls_server_certificate %s: %q", l.TLSServerCert, err)
return fmt.Errorf("failed to access tls_server_certificate %s: %w", l.TLSServerCert, err)
}
}

Expand Down
9 changes: 5 additions & 4 deletions config/lxd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package config

import (
"os"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -83,7 +84,7 @@ func TestLXDWithInvalidUnixSocket(t *testing.T) {
cfg.UnixSocket = "bogus unix socket"
err := cfg.Validate()
require.NotNil(t, err)
require.EqualError(t, err, "could not access unix socket bogus unix socket: \"CreateFile bogus unix socket: The system cannot find the file specified.\"")
require.ErrorIs(t, err, os.ErrNotExist)
}

func TestMissingUnixSocketAndMissingURL(t *testing.T) {
Expand Down Expand Up @@ -134,14 +135,14 @@ func TestLXDIvalidCertOrKeyPaths(t *testing.T) {
cfg.ClientCertificate = "/i/am/not/here"
err := cfg.Validate()
require.NotNil(t, err)
require.EqualError(t, err, "failed to access client certificate /i/am/not/here: \"CreateFile /i/am/not/here: The system cannot find the path specified.\"")
require.ErrorIs(t, err, os.ErrNotExist)

cfg.ClientCertificate = "../testdata/lxd/certs/client.crt"
cfg.ClientKey = "/me/neither"

err = cfg.Validate()
require.NotNil(t, err)
require.EqualError(t, err, "failed to access client key /me/neither: \"CreateFile /me/neither: The system cannot find the path specified.\"")
require.ErrorIs(t, err, os.ErrNotExist)
}

func TestLXDInvalidServerCertPath(t *testing.T) {
Expand All @@ -150,7 +151,7 @@ func TestLXDInvalidServerCertPath(t *testing.T) {

err := cfg.Validate()
require.NotNil(t, err)
require.EqualError(t, err, "failed to access tls_server_certificate /not/a/valid/server/cert/path: \"CreateFile /not/a/valid/server/cert/path: The system cannot find the path specified.\"")
require.ErrorIs(t, err, os.ErrNotExist)
}

func TestInvalidLXDImageRemotes(t *testing.T) {
Expand Down
Loading