@@ -10,7 +10,11 @@ import (
1010 "gotest.tools/assert"
1111)
1212
13- const cxAscaPort = "cx_asca_port"
13+ const (
14+ cxAscaPort = "cx_asca_port"
15+ cxScsScanOverviewPath = "cx_scs_scan_overview_path"
16+ defaultScsScanOverviewPath = "api/micro-engines/read/scans/%s/scan-overview"
17+ )
1418
1519func TestNewConfigCommand (t * testing.T ) {
1620 cmd := NewConfigCommand ()
@@ -94,3 +98,56 @@ func TestChangedOnlyAscaPortInConfigFile_ConfigFileExistsWithDefaultValues_OnlyA
9498 }
9599 }
96100}
101+
102+ func TestWriteSingleConfigKeyStringToExistingFile_UpdateScsScanOverviewPath_Success (t * testing.T ) {
103+ configuration .LoadConfiguration ()
104+ configFilePath , _ := configuration .GetConfigFilePath ()
105+ err := configuration .SafeWriteSingleConfigKeyString (configFilePath , cxScsScanOverviewPath , defaultScsScanOverviewPath )
106+ assert .NilError (t , err )
107+
108+ config , err := configuration .LoadConfig (configFilePath )
109+ assert .NilError (t , err )
110+ asserts .Equal (t , defaultScsScanOverviewPath , config [cxScsScanOverviewPath ])
111+ }
112+
113+ func TestWriteSingleConfigKeyStringNonExistingFile_CreatingTheFileAndWritesTheKey_Success (t * testing.T ) {
114+ configFilePath := "non-existing-file"
115+
116+ file , err := os .Open (configFilePath )
117+ asserts .NotNil (t , err )
118+ asserts .Nil (t , file )
119+
120+ err = configuration .SafeWriteSingleConfigKeyString (configFilePath , cxScsScanOverviewPath , defaultScsScanOverviewPath )
121+ assert .NilError (t , err )
122+
123+ file , err = os .Open (configFilePath )
124+ assert .NilError (t , err )
125+ defer func (file * os.File ) {
126+ _ = file .Close ()
127+ _ = os .Remove (configFilePath )
128+ _ = os .Remove (configFilePath + ".lock" )
129+ }(file )
130+ asserts .NotNil (t , file )
131+ }
132+
133+ func TestChangedOnlyScsScanOverviewPathInConfigFile_ConfigFileExistsWithDefaultValues_OnlyAscaPortChangedSuccess (t * testing.T ) {
134+ configuration .LoadConfiguration ()
135+ configFilePath , _ := configuration .GetConfigFilePath ()
136+
137+ oldConfig , err := configuration .LoadConfig (configFilePath )
138+ assert .NilError (t , err )
139+
140+ err = configuration .SafeWriteSingleConfigKeyString (configFilePath , cxScsScanOverviewPath , defaultScsScanOverviewPath )
141+ assert .NilError (t , err )
142+
143+ config , err := configuration .LoadConfig (configFilePath )
144+ assert .NilError (t , err )
145+ asserts .Equal (t , defaultScsScanOverviewPath , config [cxScsScanOverviewPath ])
146+
147+ // Assert all the other properties are the same
148+ for key , value := range oldConfig {
149+ if key != cxAscaPort {
150+ asserts .Equal (t , value , config [key ])
151+ }
152+ }
153+ }
0 commit comments