package system

import (
	"encoding/json"
	"net/http"
	"net/http/httptest"
	"runtime"
	"testing"

	"github.com/gin-gonic/gin"
	"github.com/stretchr/testify/require"
)

func TestSystemInfoHandlerIncludesPathMetadata(t *testing.T) {
	gin.SetMode(gin.TestMode)
	router := gin.New()
	router.GET("/system-info", NewSystemInfoHandler())

	req := httptest.NewRequest(http.MethodGet, "/system-info", nil)
	rec := httptest.NewRecorder()
	router.ServeHTTP(rec, req)

	require.Equal(t, http.StatusOK, rec.Code, rec.Body.String())

	var body SystemInfoResponse
	require.NoError(t, json.Unmarshal(rec.Body.Bytes(), &body))
	require.NotEmpty(t, body.BinaryPath)
	require.NotEmpty(t, body.ConfigPath)
	require.NotEmpty(t, body.ConfigDir)
	if runtime.GOOS == "linux" {
		require.NotEmpty(t, body.UpgradeLogPath)
		require.NotEmpty(t, body.UpgradeCommand)
	} else {
		require.Empty(t, body.UpgradeLogPath)
		require.Empty(t, body.UpgradeCommand)
		require.Empty(t, body.UpgradeCommandTarget)
	}
}
