-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ftest: Partial implementation for global SSC functionality
- Loading branch information
Showing
6 changed files
with
147 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...al-test/src/ftest/groovy/com/fortify/cli/ftest/_common/util/RuntimeResourcesHelper.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Copyright 2023 Open Text. | ||
* | ||
* The only warranties for products and services of Open Text | ||
* and its affiliates and licensors ("Open Text") are as may | ||
* be set forth in the express warranty statements accompanying | ||
* such products and services. Nothing herein should be construed | ||
* as constituting an additional warranty. Open Text shall not be | ||
* liable for technical or editorial errors or omissions contained | ||
* herein. The information contained herein is subject to change | ||
* without notice. | ||
*/ | ||
package com.fortify.cli.ftest._common.util | ||
|
||
import java.nio.file.Files | ||
import java.nio.file.Path | ||
import java.nio.file.StandardCopyOption | ||
|
||
class RuntimeResourcesHelper { | ||
private static tempDir = TempDirHelper.create(); | ||
|
||
static void close() { | ||
TempDirHelper.rm(tempDir); | ||
} | ||
|
||
static Path extractResource(String resourceFile) { | ||
Path outputFilePath = tempDir.resolve(resourceFile); | ||
if ( !Files.exists(outputFilePath) ) { | ||
getResource(resourceFile).withCloseable { | ||
outputFilePath.parent.toFile().mkdirs() | ||
Files.copy(it, outputFilePath, StandardCopyOption.REPLACE_EXISTING) | ||
} | ||
} | ||
return outputFilePath | ||
} | ||
|
||
private static InputStream getResource(String resourceFile) { | ||
def cl = RuntimeResourcesHelper.class.classLoader | ||
def stream = cl.getResourceAsStream(resourceFile) | ||
if ( stream==null ) { | ||
stream = cl.getResourceAsStream(resourceFile+"-no-shadow") | ||
} | ||
if ( stream==null ) { | ||
throw new IllegalStateException("${resourceFile} (or ${resourceFile}-no-shadow) referenced in @TestResource not found") | ||
} | ||
return stream | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...-other/fcli-functional-test/src/ftest/groovy/com/fortify/cli/ftest/ssc/SSCTestSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Copyright 2023 Open Text. | ||
* | ||
* The only warranties for products and services of Open Text | ||
* and its affiliates and licensors ("Open Text") are as may | ||
* be set forth in the express warranty statements accompanying | ||
* such products and services. Nothing herein should be construed | ||
* as constituting an additional warranty. Open Text shall not be | ||
* liable for technical or editorial errors or omissions contained | ||
* herein. The information contained herein is subject to change | ||
* without notice. | ||
*/ | ||
package com.fortify.cli.ftest.ssc | ||
|
||
import static com.fortify.cli.ftest._common.spec.FcliSessionType.SSC | ||
|
||
import com.fortify.cli.ftest._common.spec.FcliBaseSpec | ||
import com.fortify.cli.ftest._common.spec.FcliSession | ||
import com.fortify.cli.ftest._common.spec.Prefix | ||
import com.fortify.cli.ftest.ssc._common.SSCGlobal | ||
|
||
@Prefix("test") @FcliSession(SSC) | ||
class SSCTestSpec extends FcliBaseSpec { | ||
def setupSpec() { | ||
println "setup" | ||
} | ||
|
||
def "t"() { | ||
println SSCGlobal.AppVersion.eightball.version | ||
when: | ||
def a = "b" | ||
then: | ||
a=="b" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
.../fcli-functional-test/src/ftest/groovy/com/fortify/cli/ftest/ssc/_common/SSCGlobal.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.fortify.cli.ftest.ssc._common; | ||
|
||
import java.nio.file.Path | ||
|
||
import org.spockframework.runtime.extension.IGlobalExtension | ||
|
||
import com.fortify.cli.ftest._common.Fcli | ||
import com.fortify.cli.ftest._common.spec.TestResource | ||
import com.fortify.cli.ftest._common.util.RuntimeResourcesHelper | ||
import com.fortify.cli.ftest.ssc._common.SSCAppVersionSupplier.SSCAppVersion | ||
|
||
import groovy.transform.CompileStatic | ||
|
||
@CompileStatic | ||
class SSCGlobal implements IGlobalExtension { | ||
@Override | ||
public void start() {} | ||
|
||
@Override | ||
public void stop() { | ||
AppVersion.values().each { v->v.close() } | ||
} | ||
|
||
public static enum AppVersion implements Closeable, AutoCloseable { | ||
empty(AppVersion.&initEmpty), | ||
eightball(AppVersion.&initEightball), | ||
|
||
private SSCAppVersion version; | ||
private Closure initVersion; | ||
private AppVersion(Closure initVersion) { | ||
this.initVersion = initVersion; | ||
} | ||
|
||
private static void initEmpty(SSCAppVersion version) { | ||
|
||
} | ||
|
||
private static void initEightball(SSCAppVersion version) { | ||
Path fprPath = RuntimeResourcesHelper.extractResource("runtime/shared/EightBall-22.1.0.fpr"); | ||
Fcli.run("ssc artifact upload -f $fprPath --appversion ${version.variableRef} --store globalEightBallFpr") | ||
Fcli.run("ssc artifact wait-for ::globalEightBallFpr:: -i 2s") | ||
} | ||
|
||
public SSCAppVersion getVersion() { | ||
if ( !version ) { | ||
version = new SSCAppVersion().create() | ||
initVersion(version) | ||
} | ||
return version | ||
} | ||
|
||
@Override | ||
public void close() { | ||
if ( version ) { | ||
version.close(); | ||
version = null; | ||
} | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...c/ftest/resources/META-INF/services/org.spockframework.runtime.extension.IGlobalExtension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters