@@ -17,6 +17,7 @@ import (
1717 "path/filepath"
1818 "sync"
1919 "testing"
20+ "time"
2021
2122 "github.com/nginx/agent/v3/internal/config"
2223 "github.com/nginx/agent/v3/internal/model"
@@ -1198,35 +1199,36 @@ func TestFileManagerService_DetermineFileActions_ExternalFile(t *testing.T) {
11981199 fileManagerService := NewFileManagerService (fakeFileServiceClient , types .AgentConfig (), & sync.RWMutex {})
11991200 fileManagerService .agentConfig .AllowedDirectories = []string {tempDir }
12001201
1201- diff , err := fileManagerService .DetermineFileActions (ctx , map [string ]* mpi.File {} , modifiedFiles )
1202+ diff , err := fileManagerService .DetermineFileActions (ctx , make ( map [string ]* mpi.File ) , modifiedFiles )
12021203 require .NoError (t , err )
12031204
12041205 fc , ok := diff [fileName ]
12051206 require .True (t , ok , "expected file to be present in diff" )
12061207 assert .Equal (t , model .ExternalFile , fc .Action )
12071208}
12081209
1210+ //nolint:gocognit,revive,govet // cognitive complexity is 25
12091211func TestFileManagerService_downloadExternalFiles_Cases (t * testing.T ) {
12101212 type tc struct {
1213+ allowedDomains []string
1214+ expectContent []byte
12111215 name string
1216+ expectHeaderETag string
1217+ expectHeaderLastMod string
1218+ expectErrContains string
12121219 handler http.HandlerFunc
1213- allowedDomains []string
12141220 maxBytes int
12151221 expectError bool
1216- expectErrContains string
12171222 expectTempFile bool
1218- expectContent []byte
1219- expectHeaderETag string
1220- expectHeaderLastMod string
12211223 }
12221224
12231225 tests := []tc {
12241226 {
12251227 name : "Success" ,
12261228 handler : func (w http.ResponseWriter , r * http.Request ) {
12271229 w .Header ().Set ("ETag" , "test-etag" )
1228- w .Header ().Set ("Last-Modified" , "Mon, 02 Jan 2006 15:04:05 MST" )
1229- w .WriteHeader (200 )
1230+ w .Header ().Set ("Last-Modified" , time . RFC1123 )
1231+ w .WriteHeader (http . StatusOK )
12301232 _ , _ = w .Write ([]byte ("external file content" ))
12311233 },
12321234 allowedDomains : nil , // will be set per test from ts
@@ -1235,7 +1237,7 @@ func TestFileManagerService_downloadExternalFiles_Cases(t *testing.T) {
12351237 expectTempFile : true ,
12361238 expectContent : []byte ("external file content" ),
12371239 expectHeaderETag : "test-etag" ,
1238- expectHeaderLastMod : "Mon, 02 Jan 2006 15:04:05 MST" ,
1240+ expectHeaderLastMod : time . RFC1123 ,
12391241 },
12401242 {
12411243 name : "NotModified" ,
@@ -1253,7 +1255,7 @@ func TestFileManagerService_downloadExternalFiles_Cases(t *testing.T) {
12531255 {
12541256 name : "NotAllowedDomain" ,
12551257 handler : func (w http.ResponseWriter , r * http.Request ) {
1256- w .WriteHeader (200 )
1258+ w .WriteHeader (http . StatusOK )
12571259 _ , _ = w .Write ([]byte ("external file content" ))
12581260 },
12591261 allowedDomains : []string {"not-the-host" },
@@ -1281,7 +1283,7 @@ func TestFileManagerService_downloadExternalFiles_Cases(t *testing.T) {
12811283 tempDir := t .TempDir ()
12821284 fileName := filepath .Join (tempDir , "external.conf" )
12831285
1284- ts := httptest .NewServer (http . HandlerFunc ( test .handler ) )
1286+ ts := httptest .NewServer (test .handler )
12851287 defer ts .Close ()
12861288
12871289 u , err := url .Parse (ts .URL )
@@ -1326,6 +1328,7 @@ func TestFileManagerService_downloadExternalFiles_Cases(t *testing.T) {
13261328 // ensure no temp file left
13271329 _ , statErr := os .Stat (tempFilePath (fileName ))
13281330 assert .True (t , os .IsNotExist (statErr ))
1331+
13291332 return
13301333 }
13311334
0 commit comments