@@ -15,25 +15,14 @@ import (
1515 "errors"
1616 "fmt"
1717 "net"
18- << << << < HEAD
19- "testing"
20- "time"
21-
22- == == == =
23- "net/http"
24- "net/http/httptest"
25- "os"
26- "path/filepath"
27- "strings"
2818 "sync"
2919 "testing"
3020 "time"
3121
32- "github.com/elastic/elastic-agent-client/v7/pkg/proto"
22+ "github.com/elastic/elastic-agent/internal/pkg/config"
23+ "github.com/elastic/elastic-agent/internal/pkg/fleetapi"
3324 "github.com/elastic/elastic-agent/internal/pkg/fleetapi/acker"
34- "github.com/elastic/elastic-agent/internal/pkg/testutils"
3525
36- >> >> >> > a7a76f6e1 (Enhancement / 5235 use disk space error to set upgrade detail in coordinator (#9392 ))
3726 "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status"
3827 "go.opentelemetry.io/collector/component/componentstatus"
3928 "go.opentelemetry.io/collector/confmap"
@@ -45,18 +34,12 @@ import (
4534 "github.com/elastic/elastic-agent-libs/logp"
4635 "github.com/elastic/elastic-agent/internal/pkg/agent/application/info"
4736 "github.com/elastic/elastic-agent/internal/pkg/agent/application/monitoring/reload"
48- << << << < HEAD
49- == == == =
50- "github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
5137 "github.com/elastic/elastic-agent/internal/pkg/agent/application/reexec"
52- "github.com/elastic/elastic-agent/internal/pkg/agent/application/secret"
53- >> >> >> > a7a76f6e1 (Enhancement / 5235 use disk space error to set upgrade detail in coordinator (#9392 ))
5438 "github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade"
5539 "github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/artifact"
5640 upgradeErrors "github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/artifact/download/errors"
5741 "github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/details"
5842 "github.com/elastic/elastic-agent/internal/pkg/agent/transpiler"
59- "github.com/elastic/elastic-agent/internal/pkg/config"
6043 monitoringCfg "github.com/elastic/elastic-agent/internal/pkg/core/monitoring/config"
6144 "github.com/elastic/elastic-agent/pkg/component"
6245 "github.com/elastic/elastic-agent/pkg/component/runtime"
@@ -1461,157 +1444,6 @@ func (fs *fakeMonitoringServer) Reset() {
14611444func (fs * fakeMonitoringServer ) Addr () net.Addr {
14621445 return nil
14631446}
1464- << << << < HEAD
1465- == == == =
1466-
1467- func TestMergeFleetConfig (t * testing.T ) {
1468- testutils .InitStorage (t )
1469-
1470- cfg := map [string ]interface {}{
1471- "fleet" : map [string ]interface {}{
1472- "enabled" : true ,
1473- "kibana" : map [string ]interface {}{"host" : "demo" },
1474- "access_api_key" : "123" ,
1475- },
1476- "agent" : map [string ]interface {}{
1477- "grpc" : map [string ]interface {}{
1478- "port" : uint16 (6790 ),
1479- },
1480- },
1481- }
1482-
1483- path := paths .AgentConfigFile ()
1484- store , err := storage .NewEncryptedDiskStore (t .Context (), path )
1485- require .NoError (t , err )
1486-
1487- rawConfig := config .MustNewConfigFrom (cfg )
1488- conf , err := mergeFleetConfig (t .Context (), rawConfig , store )
1489- require .NoError (t , err )
1490- assert .NotNil (t , conf )
1491- assert .Equal (t , conf .Fleet .Enabled , cfg ["fleet" ].(map [string ]interface {})["enabled" ])
1492- assert .Equal (t , conf .Fleet .AccessAPIKey , cfg ["fleet" ].(map [string ]interface {})["access_api_key" ])
1493- assert .Equal (t , conf .Settings .GRPC .Port , cfg ["agent" ].(map [string ]interface {})["grpc" ].(map [string ]interface {})["port" ].(uint16 ))
1494- }
1495-
1496- func TestComputeEnrollOptions (t * testing.T ) {
1497- testutils .InitStorage (t )
1498- tmp := t .TempDir ()
1499-
1500- storePath := filepath .Join (tmp , "fleet.enc" )
1501- cfgPath := filepath .Join (tmp , "elastic-agent.yml" )
1502-
1503- cfg := map [string ]interface {}{
1504- "fleet" : map [string ]interface {}{
1505- "enabled" : true ,
1506- "access_api_key" : "123" ,
1507- },
1508- "agent" : map [string ]interface {}{
1509- "grpc" : map [string ]interface {}{
1510- "port" : uint16 (6790 ),
1511- },
1512- },
1513- }
1514-
1515- rawAgentConfigData , err := yaml .Marshal (cfg )
1516- require .NoError (t , err )
1517-
1518- require .NoError (t , os .WriteFile (cfgPath , rawAgentConfigData , 0644 ))
1519-
1520- store , err := storage .NewEncryptedDiskStore (t .Context (), storePath )
1521- require .NoError (t , err )
1522-
1523- fleetConfig := `fleet:
1524- hosts: [localhost:1234]
1525- ssl:
1526- ca_sha256: ["sha1", "sha2"]
1527- verification_mode: none
1528- proxy_url: http://proxy.example.com:8080
1529- proxy_disable: false
1530- proxy_headers:
1531- Proxy-Authorization: "Bearer token"
1532- Custom-Header: "custom-value"
1533- enrollment_token: enrollment-token-123
1534- force: true
1535- insecure: true
1536- agent:
1537- id: test-agent-id
1538- `
1539- require .NoError (t , store .Save (bytes .NewReader ([]byte (fleetConfig ))))
1540-
1541- options , err := computeEnrollOptions (t .Context (), cfgPath , storePath )
1542- require .NoError (t , err )
1543-
1544- require .NoError (t , err )
1545- assert .NotNil (t , options )
1546-
1547- assert .Equal (t , "123" , options .EnrollAPIKey , "EnrollAPIKey mismatch" )
1548- assert .Equal (t , "http://localhost:1234" , options .URL , "URL mismatch" )
1549-
1550- assert .Equal (t , []string {"sha1" , "sha2" }, options .CASha256 , "CASha256 mismatch" )
1551- assert .Equal (t , true , options .Insecure , "Insecure mismatch" )
1552- assert .Equal (t , "test-agent-id" , options .ID , "ID mismatch" )
1553- assert .Equal (t , "http://proxy.example.com:8080" , options .ProxyURL , "ProxyURL mismatch" )
1554- assert .Equal (t , false , options .ProxyDisabled , "ProxyDisabled mismatch" )
1555- expectedProxyHeaders := map [string ]string {
1556- "Proxy-Authorization" : "Bearer token" ,
1557- "Custom-Header" : "custom-value" ,
1558- }
1559- assert .Equal (t , expectedProxyHeaders , options .ProxyHeaders , "ProxyHeaders mismatch" )
1560- }
1561-
1562- func TestHasEndpoint (t * testing.T ) {
1563- testCases := []struct {
1564- name string
1565- state State
1566- expected bool
1567- }{
1568- {
1569- "endpoint" ,
1570- State {
1571- Components : []runtime.ComponentComponentState {
1572- {
1573- Component : component.Component {
1574- InputType : endpoint ,
1575- },
1576- },
1577- },
1578- },
1579- true ,
1580- },
1581- {
1582- "no endpoint" ,
1583- State {
1584- Components : []runtime.ComponentComponentState {
1585- {
1586- Component : component.Component {
1587- InputType : "not endpoint" ,
1588- },
1589- },
1590- },
1591- },
1592- false ,
1593- },
1594-
1595- {
1596- "no component" ,
1597- State {
1598- Components : []runtime.ComponentComponentState {},
1599- },
1600- false ,
1601- },
1602- }
1603-
1604- for _ , tc := range testCases {
1605- t .Run (tc .name , func (t * testing.T ) {
1606- c := & Coordinator {
1607- state : tc .state ,
1608- }
1609-
1610- result := c .HasEndpoint ()
1611- assert .Equal (t , tc .expected , result , "HasEndpoint result mismatch" )
1612- })
1613- }
1614- }
16151447
16161448type mockUpgradeManager struct {
16171449 upgradeErr error
@@ -1625,7 +1457,7 @@ func (m *mockUpgradeManager) Reload(cfg *config.Config) error {
16251457 return nil
16261458}
16271459
1628- func (m * mockUpgradeManager ) Upgrade (ctx context.Context , version string , rollback bool , sourceURI string , action * fleetapi.ActionUpgrade , details * details.Details , skipVerifyOverride bool , skipDefaultPgp bool , pgpBytes ... string ) (_ reexec.ShutdownCallbackFn , err error ) {
1460+ func (m * mockUpgradeManager ) Upgrade (ctx context.Context , version string , sourceURI string , action * fleetapi.ActionUpgrade , details * details.Details , skipVerifyOverride bool , skipDefaultPgp bool , pgpBytes ... string ) (_ reexec.ShutdownCallbackFn , err error ) {
16291461 return nil , m .upgradeErr
16301462}
16311463
@@ -1709,4 +1541,3 @@ func TestCoordinator_Upgrade_InsufficientDiskSpaceError(t *testing.T) {
17091541 },
17101542 }, upgradeDetails )
17111543}
1712- >> >> >> > a7a76f6e1 (Enhancement / 5235 use disk space error to set upgrade detail in coordinator (#9392 ))
0 commit comments