@@ -5543,15 +5543,41 @@ func TestArtifactoryCurl(t *testing.T) {
5543
5543
_ , err := createServerConfigAndReturnPassphrase (t )
5544
5544
defer deleteServerConfig (t )
5545
5545
assert .NoError (t , err )
5546
- // Check curl command with config default server
5547
- err = artifactoryCli .WithoutCredentials ().Exec ("curl" , "-XGET" , "/api/system/version" )
5548
- assert .NoError (t , err )
5549
- // Check curl command with '--server-id' flag
5550
- err = artifactoryCli .WithoutCredentials ().Exec ("curl" , "-XGET" , "/api/system/version" , "--server-id=" + tests .ServerId )
5551
- assert .NoError (t , err )
5552
- // Check curl command with invalid server id - should get an error.
5553
- err = artifactoryCli .WithoutCredentials ().Exec ("curl" , "-XGET" , "/api/system/version" , "--server-id=not_configured_name_" + tests .ServerId )
5554
- assert .Error (t , err )
5546
+
5547
+ baseArgs := []string {"curl" , "-XGET" , "/api/system/version" }
5548
+
5549
+ testRuns := []struct {
5550
+ testName string
5551
+ serverIDEnvValue string
5552
+ expectedErr bool
5553
+ serverID string
5554
+ }{
5555
+ {"defaultConfig" , "" , false , "" },
5556
+ {"serverIdFlag" , "" , false , tests .ServerId },
5557
+ {"invalidServerId" , "" , true , "not_configured_name_" + tests .ServerId },
5558
+ {"envVarSet" , tests .ServerId , false , "" },
5559
+ {"envVarWithFlag" , tests .ServerId , false , tests .ServerId },
5560
+ {"priorityFlagOverEnv" , "wrong_server_id" , false , tests .ServerId },
5561
+ {"priorityEnvOverDefault" , tests .ServerId , false , "" },
5562
+ }
5563
+
5564
+ for _ , test := range testRuns {
5565
+ t .Run (test .testName , func (t * testing.T ) {
5566
+ setEnvCallBack := clientTestUtils .SetEnvWithCallbackAndAssert (t , coreutils .ServerID , test .serverIDEnvValue )
5567
+
5568
+ args := append ([]string {}, baseArgs ... )
5569
+ if test .serverID != "" {
5570
+ args = append (args , "--server-id=" + test .serverID )
5571
+ }
5572
+ err = artifactoryCli .WithoutCredentials ().Exec (args ... )
5573
+ if test .expectedErr {
5574
+ assert .Error (t , err )
5575
+ } else {
5576
+ assert .NoError (t , err )
5577
+ }
5578
+ setEnvCallBack ()
5579
+ })
5580
+ }
5555
5581
5556
5582
cleanArtifactoryTest ()
5557
5583
}
0 commit comments