integration

package
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2025 License: MIT Imports: 15 Imported by: 0

README

Integration Tests for MCP MAAS Server

This directory contains integration tests for the MCP MAAS server. These tests verify that the server correctly interacts with a MAAS instance and provides the expected API endpoints.

Test Structure

The integration tests are organized as follows:

  • helper.go: Contains helper functions and a test server setup for integration tests.
  • main_test.go: Entry point for running all integration tests.
  • machine_test.go: Tests for machine management endpoints.
  • network_test.go: Tests for network management endpoints.
  • tag_test.go: Tests for tag management endpoints.
  • mock/: Contains mock implementations for testing.
    • maas_client.go: A mock implementation of the MAAS client.
    • maas_server.go: A mock implementation of the MAAS API server.

Running the Tests

To run all integration tests:

go test -v ./test/integration/...

To run a specific test file:

go test -v ./test/integration/machine_test.go

To run a specific test:

go test -v ./test/integration -run TestListMachines

Test Environment

The integration tests use a mock MAAS client and server to simulate interactions with a real MAAS instance. This allows the tests to run without requiring a real MAAS instance.

The mock client and server are initialized with test data that includes:

  • Test machines with different statuses and configurations
  • Test subnets and VLANs
  • Test tags

Test Coverage

The integration tests cover the following functionality:

Machine Management
  • Listing machines with and without filters
  • Getting machine details
  • Allocating machines with constraints
  • Deploying machines
  • Releasing machines
  • Getting machine power state
Network Management
  • Listing subnets with and without filters
  • Getting subnet details
  • Listing VLANs for a fabric
Tag Management
  • Listing tags
  • Creating tags
  • Applying tags to machines
  • Removing tags from machines

Adding New Tests

When adding new tests, follow these guidelines:

  1. Use the TestServer struct from helper.go to set up a test server.
  2. Use the MakeRequest method to make HTTP requests to the test server.
  3. Use the ParseJSONResponse function to parse JSON responses.
  4. Use the MockClient field to access the mock MAAS client and set up test conditions.
  5. Add assertions to verify the expected behavior.

Example:

func TestNewEndpoint(t *testing.T) {
    // Set up test server
    ts := NewTestServer(t)
    defer ts.Close()

    // Make request
    resp, respBody := ts.MakeRequest(t, http.MethodGet, "/api/v1/new-endpoint", nil)

    // Verify response
    require.Equal(t, http.StatusOK, resp.StatusCode)

    var result SomeResponseType
    ParseJSONResponse(t, respBody, &result)

    // Add assertions
    assert.Equal(t, expectedValue, result.SomeField)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseJSONResponse

func ParseJSONResponse(t *testing.T, respBody []byte, target interface{})

ParseJSONResponse parses a JSON response into the given target.

Types

type TestServer

type TestServer struct {
	Server     *httptest.Server
	Router     *gin.Engine
	MockClient *mock.MockMaasClient
	Logger     *logrus.Logger
}

TestServer represents a test server for integration tests.

func NewTestServer

func NewTestServer(t *testing.T) *TestServer

NewTestServer creates a new test server with a mock MAAS client.

func (*TestServer) Close

func (ts *TestServer) Close()

Close closes the test server.

func (*TestServer) MakeRequest

func (ts *TestServer) MakeRequest(t *testing.T, method, path string, body interface{}) (*http.Response, []byte)

MakeRequest makes an HTTP request to the test server.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL