Skip to content

Commit

Permalink
tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcburns committed Sep 7, 2023
1 parent 37ecdda commit 78c3a15
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/go
{
"name": "Go",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/go:1-1.21-bullseye"

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "go version",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
61 changes: 61 additions & 0 deletions bmc/sel_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package bmc

import (
"context"
"testing"
"time"

"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)

type mockSELService struct {
name string
err error
}

func (m *mockSELService) ClearSEL(ctx context.Context) error {
return m.err
}

func (m *mockSELService) Name() string {
return m.name
}

func TestClearSEL(t *testing.T) {
ctx := context.Background()
timeout := 1 * time.Second

// Test with a mock SELService that returns nil
mockService := &mockSELService{name: "mock1", err: nil}
metadata, err := clearSEL(ctx, timeout, []selProviders{{name: mockService.name, selProvider: mockService}})
assert.Nil(t, err)
assert.Equal(t, mockService.name, metadata.SuccessfulProvider)

// Test with a mock SELService that returns an error
mockService = &mockSELService{name: "mock2", err: errors.New("mock error")}
metadata, err = clearSEL(ctx, timeout, []selProviders{{name: mockService.name, selProvider: mockService}})
assert.NotNil(t, err)
assert.NotEqual(t, mockService.name, metadata.SuccessfulProvider)
}

func TestClearSELFromInterfaces(t *testing.T) {
ctx := context.Background()
timeout := 1 * time.Second

// Test with an empty slice
metadata, err := ClearSELFromInterfaces(ctx, timeout, []interface{}{})
assert.NotNil(t, err)
assert.Empty(t, metadata.SuccessfulProvider)

// Test with a slice containing a non-SELService object
metadata, err = ClearSELFromInterfaces(ctx, timeout, []interface{}{"not a SELService"})
assert.NotNil(t, err)
assert.Empty(t, metadata.SuccessfulProvider)

// Test with a slice containing a mock SELService
mockService := &mockSELService{name: "mock1"}
metadata, err = ClearSELFromInterfaces(ctx, timeout, []interface{}{mockService})
assert.Nil(t, err)
assert.Equal(t, mockService.name, metadata.SuccessfulProvider)
}
18 changes: 18 additions & 0 deletions providers/ipmitool/ipmitool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,21 @@ func TestBMCReset(t *testing.T) {
t.Log(state)
t.Fatal()
}

func TestSELClear(t *testing.T) {
t.Skip("need real ipmi server")
host := "127.0.0.1"
port := "623"
user := "ADMIN"
pass := "ADMIN"
i, err := New(host, user, pass, WithPort(port), WithLogger(logging.DefaultLogger()))
if err != nil {
t.Fatal(err)
}
err = i.ClearSEL(context.Background())
if err != nil {
t.Fatal(err)
}
t.Log("SEL cleared")
t.Fatal()
}

0 comments on commit 78c3a15

Please sign in to comment.