66package integration
77
88import (
9- "encoding/json"
10- "fmt"
11- "net/http"
129 "testing"
1310
14- "github.com/go-resty/resty/v2"
15- mpi "github.com/nginx/agent/v3/api/grpc/mpi/v1"
16- "github.com/stretchr/testify/require"
17- "google.golang.org/protobuf/encoding/protojson"
18-
1911 "github.com/stretchr/testify/assert"
2012)
2113
@@ -24,82 +16,6 @@ func TestNginxLessGrpc_Connection(t *testing.T) {
2416 teardownTest := setupConnectionTest (t , true , true )
2517 defer teardownTest (t )
2618
27- verifyNginxLessConnection (t , 1 )
19+ verifyConnection (t , 1 )
2820 assert .False (t , t .Failed ())
2921}
30-
31- // nolint
32- func verifyNginxLessConnection (t * testing.T , instancesLength int ) string {
33- t .Helper ()
34-
35- client := resty .New ()
36- client .SetRetryCount (retryCount ).SetRetryWaitTime (retryWaitTime ).SetRetryMaxWaitTime (retryMaxWaitTime )
37- connectionRequest := mpi.CreateConnectionRequest {}
38-
39- url := fmt .Sprintf ("http://%s/api/v1/connection" , mockManagementPlaneAPIAddress )
40- t .Logf ("Connecting to %s" , url )
41- resp , err := client .R ().EnableTrace ().Get (url )
42-
43- require .NoError (t , err )
44- assert .Equal (t , http .StatusOK , resp .StatusCode ())
45-
46- responseData := resp .Body ()
47- t .Logf ("Response: %s" , string (responseData ))
48- assert .True (t , json .Valid (responseData ))
49-
50- pb := protojson.UnmarshalOptions {DiscardUnknown : true }
51- unmarshalErr := pb .Unmarshal (responseData , & connectionRequest )
52- require .NoError (t , unmarshalErr )
53-
54- t .Logf ("ConnectionRequest: %v" , & connectionRequest )
55-
56- resource := connectionRequest .GetResource ()
57-
58- assert .NotNil (t , resource .GetResourceId ())
59- assert .NotNil (t , resource .GetContainerInfo ().GetContainerId ())
60-
61- assert .Len (t , resource .GetInstances (), instancesLength )
62-
63- var nginxInstanceID string
64-
65- for _ , instance := range resource .GetInstances () {
66- switch instance .GetInstanceMeta ().GetInstanceType () {
67- case mpi .InstanceMeta_INSTANCE_TYPE_AGENT :
68- agentInstanceMeta := instance .GetInstanceMeta ()
69-
70- assert .NotEmpty (t , agentInstanceMeta .GetInstanceId ())
71- assert .NotEmpty (t , agentInstanceMeta .GetVersion ())
72-
73- assert .NotEmpty (t , instance .GetInstanceRuntime ().GetBinaryPath ())
74-
75- assert .Equal (t , "/etc/nginx-agent/nginx-agent.conf" , instance .GetInstanceRuntime ().GetConfigPath ())
76- case mpi .InstanceMeta_INSTANCE_TYPE_NGINX :
77- nginxInstanceMeta := instance .GetInstanceMeta ()
78-
79- nginxInstanceID = nginxInstanceMeta .GetInstanceId ()
80- assert .NotEmpty (t , nginxInstanceID )
81- assert .NotEmpty (t , nginxInstanceMeta .GetVersion ())
82-
83- assert .NotEmpty (t , instance .GetInstanceRuntime ().GetBinaryPath ())
84-
85- assert .Equal (t , "/etc/nginx/nginx.conf" , instance .GetInstanceRuntime ().GetConfigPath ())
86- case mpi .InstanceMeta_INSTANCE_TYPE_NGINX_PLUS :
87- nginxInstanceMeta := instance .GetInstanceMeta ()
88-
89- nginxInstanceID = nginxInstanceMeta .GetInstanceId ()
90- assert .NotEmpty (t , nginxInstanceID )
91- assert .NotEmpty (t , nginxInstanceMeta .GetVersion ())
92-
93- assert .NotEmpty (t , instance .GetInstanceRuntime ().GetBinaryPath ())
94-
95- assert .Equal (t , "/etc/nginx/nginx.conf" , instance .GetInstanceRuntime ().GetConfigPath ())
96- case mpi .InstanceMeta_INSTANCE_TYPE_UNIT ,
97- mpi .InstanceMeta_INSTANCE_TYPE_UNSPECIFIED :
98- fallthrough
99- default :
100- t .Fail ()
101- }
102- }
103-
104- return nginxInstanceID
105- }
0 commit comments