Skip to content

Commit

Permalink
[skip ci] fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Jul 6, 2022
1 parent d5d4cf0 commit 9961fc5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 26 deletions.
36 changes: 18 additions & 18 deletions cluster/calcium/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,31 @@ const (
eventProcessingCreated = "create-processing" // processing created but yet to delete
)

func enableWAL(config types.Config, calcium cluster.Cluster, stor store.Store) (wal.WAL, error) {
func enableWAL(config types.Config, calcium cluster.Cluster, store store.Store) (wal.WAL, error) {
hydro, err := wal.NewHydro(config.WALFile, config.WALOpenTimeout)
if err != nil {
return nil, err
}

hydro.Register(newCreateLambdaHandler(calcium, stor))
hydro.Register(newCreateWorkloadHandler(calcium, stor))
hydro.Register(newWorkloadResourceAllocatedHandler(calcium, stor))
hydro.Register(newProcessingCreatedHandler(calcium, stor))
hydro.Register(newCreateLambdaHandler(calcium, store))
hydro.Register(newCreateWorkloadHandler(calcium, store))
hydro.Register(newWorkloadResourceAllocatedHandler(calcium, store))
hydro.Register(newProcessingCreatedHandler(calcium, store))
return hydro, nil
}

// CreateLambdaHandler indicates event handler for creating lambda.
type CreateLambdaHandler struct {
typ string
calcium cluster.Cluster
stor store.Store
store store.Store
}

func newCreateLambdaHandler(calcium cluster.Cluster, stor store.Store) *CreateLambdaHandler {
func newCreateLambdaHandler(calcium cluster.Cluster, store store.Store) *CreateLambdaHandler {
return &CreateLambdaHandler{
typ: eventCreateLambda,
calcium: calcium,
stor: stor,
store: store,
}
}

Expand Down Expand Up @@ -110,14 +110,14 @@ func (h *CreateLambdaHandler) Handle(ctx context.Context, raw interface{}) error
type CreateWorkloadHandler struct {
typ string
calcium cluster.Cluster
stor store.Store
store store.Store
}

func newCreateWorkloadHandler(calcium cluster.Cluster, stor store.Store) *CreateWorkloadHandler {
func newCreateWorkloadHandler(calcium cluster.Cluster, store store.Store) *CreateWorkloadHandler {
return &CreateWorkloadHandler{
typ: eventWorkloadCreated,
calcium: calcium,
stor: stor,
store: store,
}
}

Expand Down Expand Up @@ -180,14 +180,14 @@ func (h *CreateWorkloadHandler) Handle(ctx context.Context, raw interface{}) (er
type WorkloadResourceAllocatedHandler struct {
typ string
calcium cluster.Cluster
stor store.Store
store store.Store
}

func newWorkloadResourceAllocatedHandler(calcium cluster.Cluster, stor store.Store) *WorkloadResourceAllocatedHandler {
func newWorkloadResourceAllocatedHandler(calcium cluster.Cluster, store store.Store) *WorkloadResourceAllocatedHandler {
return &WorkloadResourceAllocatedHandler{
typ: eventWorkloadResourceAllocated,
calcium: calcium,
stor: stor,
store: store,
}
}

Expand Down Expand Up @@ -250,14 +250,14 @@ func (h *WorkloadResourceAllocatedHandler) Handle(ctx context.Context, raw inter
type ProcessingCreatedHandler struct {
typ string
calcium cluster.Cluster
stor store.Store
store store.Store
}

func newProcessingCreatedHandler(calcium cluster.Cluster, stor store.Store) *ProcessingCreatedHandler {
func newProcessingCreatedHandler(calcium cluster.Cluster, store store.Store) *ProcessingCreatedHandler {
return &ProcessingCreatedHandler{
typ: eventProcessingCreated,
calcium: calcium,
stor: stor,
store: store,
}
}

Expand Down Expand Up @@ -297,7 +297,7 @@ func (h *ProcessingCreatedHandler) Handle(ctx context.Context, raw interface{})
ctx, cancel := getReplayContext(ctx)
defer cancel()

if err = h.stor.DeleteProcessing(ctx, processing); err != nil {
if err = h.store.DeleteProcessing(ctx, processing); err != nil {
return logger.ErrWithTracing(ctx, err)
}
logger.Infof(ctx, "obsolete processing deleted")
Expand Down
14 changes: 7 additions & 7 deletions cluster/calcium/wal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

func TestHandleCreateWorkloadNoHandle(t *testing.T) {
c := NewTestCluster()
wal, err := newWAL(c.config, c)
wal, err := enableWAL(c.config, c, c.store)
require.NoError(t, err)
c.wal = wal

Expand All @@ -45,10 +45,10 @@ func TestHandleCreateWorkloadNoHandle(t *testing.T) {

func TestHandleCreateWorkloadError(t *testing.T) {
c := NewTestCluster()
wal, err := newWAL(c.config, c)
wal, err := enableWAL(c.config, c, c.store)
require.NoError(t, err)
c.wal = wal
plugin := c.resource.GetPlugins()[0].(*resourcemocks.Plugin)
plugin := c.rmgr.GetPlugins()[0].(*resourcemocks.Plugin)
plugin.On("GetNodeResourceInfo", mock.Anything, mock.Anything, mock.Anything).Return(&resources.GetNodeResourceInfoResponse{
ResourceInfo: &resources.NodeResourceInfo{},
Diffs: []string{"hhh"},
Expand Down Expand Up @@ -97,10 +97,10 @@ func TestHandleCreateWorkloadError(t *testing.T) {

func TestHandleCreateWorkloadHandled(t *testing.T) {
c := NewTestCluster()
wal, err := newWAL(c.config, c)
wal, err := enableWAL(c.config, c, c.store)
require.NoError(t, err)
c.wal = wal
plugin := c.resource.GetPlugins()[0].(*resourcemocks.Plugin)
plugin := c.rmgr.GetPlugins()[0].(*resourcemocks.Plugin)
plugin.On("GetNodeResourceInfo", mock.Anything, mock.Anything, mock.Anything).Return(&resources.GetNodeResourceInfoResponse{
ResourceInfo: &resources.NodeResourceInfo{},
Diffs: []string{"hhh"},
Expand Down Expand Up @@ -142,10 +142,10 @@ func TestHandleCreateWorkloadHandled(t *testing.T) {

func TestHandleCreateLambda(t *testing.T) {
c := NewTestCluster()
wal, err := newWAL(c.config, c)
wal, err := enableWAL(c.config, c, c.store)
require.NoError(t, err)
c.wal = wal
plugin := c.resource.GetPlugins()[0].(*resourcemocks.Plugin)
plugin := c.rmgr.GetPlugins()[0].(*resourcemocks.Plugin)
plugin.On("GetNodeResourceInfo", mock.Anything, mock.Anything, mock.Anything).Return(&resources.GetNodeResourceInfoResponse{
ResourceInfo: &resources.NodeResourceInfo{},
Diffs: []string{"hhh"},
Expand Down
3 changes: 3 additions & 0 deletions resources/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,7 @@ type Manager interface {
RemoveNode(context.Context, string) error

GetRemapArgs(context.Context, string, map[string]*types.Workload) (map[string]types.EngineArgs, error)

// GetPlugins for testing
GetPlugins() []Plugin
}
7 changes: 7 additions & 0 deletions utils/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"context"
"net/http"
"os"
"testing"

Expand All @@ -26,3 +27,9 @@ func TestGetHTTPSClient(t *testing.T) {
assert.Error(t, err)
assert.Nil(t, client)
}

func TestCheckRedirect(t *testing.T) {
via := []*http.Request{{Method: http.MethodGet}}
err := checkRedirect(nil, via)
assert.Equal(t, err, http.ErrUseLastResponse)
}
1 change: 0 additions & 1 deletion utils/resource_test.go

This file was deleted.

0 comments on commit 9961fc5

Please sign in to comment.