Skip to content
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: 21 additions & 0 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,27 @@ concurrency:
cancel-in-progress: true

jobs:
format:
name: Format check
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v6

- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: 'go.mod'

- name: Ensure no formatting changes
run: |
go fmt ./...
git diff --exit-code

- name: Ensure no use of empty interface (should be any)
run: |
! egrep -R --exclude-dir .git 'interface\{\}'
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm guessing this isn't working/running yet, as there were a bunch of instances of interface{}. I've pushed a commit which updates those using gofmt -r (rewrite rule).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what the story is with CI, I'm seeing them just queued and the action summary has:

The job was not acquired by Runner of type hosted even after multiple attempts

I'm hoping this is just some slowness on GitHub at the moment and it'll resolve itself. I'm seeing it in #147 at the moment as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

How about matching the string verbatim?

Suggested change
! egrep -R --exclude-dir .git 'interface\{\}'
! grep -R --exclude-dir=.git -F 'interface{}' .


binaries:
name: Build concierge
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion internal/config/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package config

// MergeMaps takes two maps and returns a combined map, where KV pairs in the second map arg
// take precedence over the first.
func MergeMaps[K string, V interface{}](m1 map[K]V, m2 map[K]V) map[K]V {
func MergeMaps[K string, V any](m1 map[K]V, m2 map[K]V) map[K]V {
combinedMap := map[K]V{}
for k := range m1 {
combinedMap[k] = m1[k]
Expand Down
6 changes: 3 additions & 3 deletions internal/juju/juju.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (j *JujuHandler) install() error {
// writeCredentials iterates over any provided cloud credentials and authors Juju's
// credentials.yaml
func (j *JujuHandler) writeCredentials() error {
credentials := map[string]interface{}{"credentials": map[string]interface{}{}}
credentials := map[string]any{"credentials": map[string]any{}}
addedCredentials := false

// Iterate over the providers
Expand All @@ -137,8 +137,8 @@ func (j *JujuHandler) writeCredentials() error {
}

// Set the credentials for the provider, under the credential name "concierge".
credentials["credentials"] = map[string]interface{}{
p.CloudName(): map[string]interface{}{
credentials["credentials"] = map[string]any{
p.CloudName(): map[string]any{
"concierge": p.Credentials(),
},
}
Expand Down
8 changes: 4 additions & 4 deletions internal/providers/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NewGoogle(system system.Worker, config *config.Config) *Google {
system: system,
bootstrap: config.Providers.Google.Bootstrap,
credentialsFile: credentialsFile,
credentials: map[string]interface{}{},
credentials: map[string]any{},
modelDefaults: config.Providers.Google.ModelDefaults,
bootstrapConstraints: config.Providers.Google.BootstrapConstraints,
}
Expand All @@ -31,7 +31,7 @@ type Google struct {
bootstrap bool
system system.Worker
credentialsFile string
credentials map[string]interface{}
credentials map[string]any
modelDefaults map[string]string
bootstrapConstraints map[string]string
}
Expand All @@ -45,7 +45,7 @@ func (l *Google) Prepare() error {
return fmt.Errorf("failed to read credentials file: %w", err)
}

credentials := make(map[string]interface{})
credentials := make(map[string]any)

err = yaml.Unmarshal(contents, &credentials)
if err != nil {
Expand All @@ -71,7 +71,7 @@ func (l *Google) CloudName() string { return "google" }
func (l *Google) GroupName() string { return "" }

// Credentials reports the section of Juju's credentials.yaml for the provider.
func (l *Google) Credentials() map[string]interface{} { return l.credentials }
func (l *Google) Credentials() map[string]any { return l.credentials }

// ModelDefaults reports the Juju model-defaults specific to the provider.
func (l *Google) ModelDefaults() map[string]string { return l.modelDefaults }
Expand Down
8 changes: 4 additions & 4 deletions internal/providers/google_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ func TestNewGoogle(t *testing.T) {
config: noOverrides,
expected: &Google{
system: system,
credentials: map[string]interface{}{},
credentials: map[string]any{},
},
},
{
config: credsInConfig,
expected: &Google{
system: system,
credentialsFile: "/home/ubuntu/credentials.yaml",
credentials: map[string]interface{}{},
credentials: map[string]any{},
},
},
{
config: overrides,
expected: &Google{
system: system,
credentialsFile: "/home/ubuntu/alternate-credentials.yaml",
credentials: map[string]interface{}{},
credentials: map[string]any{},
},
},
}
Expand Down Expand Up @@ -92,7 +92,7 @@ private-key: |
project-id: concierge
`)

fakeCredsMarshalled := make(map[string]interface{})
fakeCredsMarshalled := make(map[string]any)
err := yaml.Unmarshal(creds, &fakeCredsMarshalled)
if err != nil {
t.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/providers/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (k *K8s) CloudName() string { return "k8s" }
func (k *K8s) GroupName() string { return "" }

// Credentials reports the section of Juju's credentials.yaml for the provider
func (m K8s) Credentials() map[string]interface{} { return nil }
func (m K8s) Credentials() map[string]any { return nil }

// ModelDefaults reports the Juju model-defaults specific to the provider.
func (m *K8s) ModelDefaults() map[string]string { return m.modelDefaults }
Expand Down
2 changes: 1 addition & 1 deletion internal/providers/lxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (l *LXD) CloudName() string { return "localhost" }
func (l *LXD) GroupName() string { return "lxd" }

// Credentials reports the section of Juju's credentials.yaml for the provider
func (l *LXD) Credentials() map[string]interface{} { return nil }
func (l *LXD) Credentials() map[string]any { return nil }

// ModelDefaults reports the Juju model-defaults specific to the provider.
func (l *LXD) ModelDefaults() map[string]string { return l.modelDefaults }
Expand Down
2 changes: 1 addition & 1 deletion internal/providers/microk8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (m *MicroK8s) GroupName() string {
}

// Credentials reports the section of Juju's credentials.yaml for the provider
func (m MicroK8s) Credentials() map[string]interface{} { return nil }
func (m MicroK8s) Credentials() map[string]any { return nil }

// ModelDefaults reports the Juju model-defaults specific to the provider.
func (m *MicroK8s) ModelDefaults() map[string]string { return m.modelDefaults }
Expand Down
2 changes: 1 addition & 1 deletion internal/providers/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Provider interface {
// to allow non-root users to interact with the provider (where applicable).
GroupName() string
// Credentials reports the section of Juju's credentials.yaml for the provider.
Credentials() map[string]interface{}
Credentials() map[string]any
// ModelDefaults reports the Juju model-defaults specific to the provider.
ModelDefaults() map[string]string
// BootstrapConstraints reports the Juju bootstrap-constraints specific to the provider.
Expand Down
54 changes: 27 additions & 27 deletions internal/snapd/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ import (
// createTestServer creates a test HTTP server with a Unix socket listener.
func createTestServer(t *testing.T, handler http.Handler) (*httptest.Server, string) {
t.Helper()

// Create temporary directory for socket
tmpDir := t.TempDir()
socketPath := filepath.Join(tmpDir, "snapd.socket")

// Create Unix listener
listener, err := net.Listen("unix", socketPath)
if err != nil {
t.Fatalf("Failed to create Unix listener: %v", err)
}

// Create test server with custom listener
server := httptest.NewUnstartedServer(handler)
server.Listener = listener
server.Start()

return server, socketPath
}

Expand All @@ -36,7 +36,7 @@ func TestSnap_Success(t *testing.T) {
if r.URL.Path != "/v2/snaps/test-snap" {
t.Errorf("Expected path '/v2/snaps/test-snap', got: %s", r.URL.Path)
}

resp := response{
Type: "sync",
Status: "OK",
Expand All @@ -55,18 +55,18 @@ func TestSnap_Success(t *testing.T) {
t.Fatalf("failed to marshal snap: %v", err)
}
resp.Result = result

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(resp)
})

server, socketPath := createTestServer(t, handler)
defer server.Close()

client := NewClient(&Config{Socket: socketPath})
snap, err := client.Snap("test-snap")

if err != nil {
t.Fatalf("Expected no error, got: %v", err)
}
Expand All @@ -90,13 +90,13 @@ func TestSnap_NotFound(t *testing.T) {
}
json.NewEncoder(w).Encode(resp)
})

server, socketPath := createTestServer(t, handler)
defer server.Close()

client := NewClient(&Config{Socket: socketPath})
_, err := client.Snap("nonexistent")

if err == nil {
t.Fatal("Expected error for non-existent snap")
}
Expand All @@ -114,13 +114,13 @@ func TestSnap_UnexpectedStatusCode(t *testing.T) {
}
json.NewEncoder(w).Encode(resp)
})

server, socketPath := createTestServer(t, handler)
defer server.Close()

client := NewClient(&Config{Socket: socketPath})
_, err := client.Snap("test-snap")

if err == nil {
t.Fatal("Expected error for 500 status code")
}
Expand All @@ -134,7 +134,7 @@ func TestFindOne_Success(t *testing.T) {
if r.URL.Query().Get("name") != "test-snap" {
t.Errorf("Expected query param name=test-snap, got: %s", r.URL.Query().Get("name"))
}

resp := response{
Type: "sync",
Status: "OK",
Expand Down Expand Up @@ -162,18 +162,18 @@ func TestFindOne_Success(t *testing.T) {
t.Fatalf("failed to marshal snaps response: %v", err)
}
resp.Result = result

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(resp)
})

server, socketPath := createTestServer(t, handler)
defer server.Close()

client := NewClient(&Config{Socket: socketPath})
snap, err := client.FindOne("test-snap")

if err != nil {
t.Fatalf("Expected no error, got: %v", err)
}
Expand All @@ -194,13 +194,13 @@ func TestFindOne_NotFound(t *testing.T) {
}
json.NewEncoder(w).Encode(resp)
})

server, socketPath := createTestServer(t, handler)
defer server.Close()

client := NewClient(&Config{Socket: socketPath})
_, err := client.FindOne("nonexistent")

if err == nil {
t.Fatal("Expected error for non-existent snap")
}
Expand All @@ -221,18 +221,18 @@ func TestFindOne_EmptyResults(t *testing.T) {
t.Fatalf("failed to marshal snaps: %v", err)
}
resp.Result = result

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(resp)
})

server, socketPath := createTestServer(t, handler)
defer server.Close()

client := NewClient(&Config{Socket: socketPath})
_, err := client.FindOne("nonexistent")

if err == nil {
t.Fatal("Expected error for empty results")
}
Expand Down
Loading