Skip to content

Commit

Permalink
Approval: Updated URL. Started on some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ToreMerkely committed Nov 27, 2023
1 parent f6468dd commit 388783b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/kosli/reportApproval.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (o *reportApprovalOptions) run(args []string, request bool) error {
}
} else {
// Request last approved git commit from kosli server
url := fmt.Sprintf("%s/api/v2/approvals/%s/%s/last-approved-commit/%s", global.Host, global.Org,
url := fmt.Sprintf("%s/api/v2/approvals/%s/%s/artifact-commit/%s", global.Host, global.Org,
o.flowName, o.payload.Environment)

getLastApprovedGitCommitParams := &requests.RequestParams{
Expand Down
23 changes: 16 additions & 7 deletions cmd/kosli/reportApproval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type ApprovalReportTestSuite struct {
artifactFingerprint string
flowName string
envName string
gitCommit string
}

func (suite *ApprovalReportTestSuite) SetupTest() {
Expand All @@ -26,10 +27,12 @@ func (suite *ApprovalReportTestSuite) SetupTest() {
suite.artifactFingerprint = "847411c6124e719a4e8da2550ac5c116b7ff930493ce8a061486b48db8a5aaa0"
suite.flowName = "approval-test"
suite.envName = "staging"
suite.gitCommit = "993a9a6be532ed4e7a87aab4df90a7f1b3168d63"

CreateFlow(suite.flowName, suite.T())
CreateArtifact(suite.flowName, suite.artifactFingerprint, "foobar", suite.T())
CreateArtifactWithCommit(suite.flowName, suite.artifactFingerprint, "foobar", suite.gitCommit, suite.T())
CreateEnv(global.Org, suite.envName, "K8S", suite.T())

}

func (suite *ApprovalReportTestSuite) TestApprovalReportCmd() {
Expand All @@ -46,19 +49,25 @@ func (suite *ApprovalReportTestSuite) TestApprovalReportCmd() {
--newest-commit HEAD --oldest-commit HEAD~3` + ` --environment staging` + suite.defaultKosliArguments,
golden: fmt.Sprintf("approval created for artifact: %s\n", suite.artifactFingerprint),
},
{
name: "report approval with an environment name and no oldest-commit and no newest-commit works",
cmd: `report approval --fingerprint ` + suite.artifactFingerprint + ` --flow ` + suite.flowName + ` --repo-root ../.. ` +
` --environment ` + suite.envName + suite.defaultKosliArguments,
golden: fmt.Sprintf("approval created for artifact: %s\n", suite.artifactFingerprint),
},
{
wantError: true,
name: "report approval with no environment name or oldest commit fails",
cmd: `report approval --fingerprint ` + suite.artifactFingerprint + ` --flow ` + suite.flowName + ` --repo-root ../.. ` +
suite.defaultKosliArguments,
golden: "Error: at least one of --environment, --oldest-commit is required\n",
},
// For the next test we have to
// - (create a flow)
// - create an artifact in that flow with git commit HEAD~5
// - (create an environment)
// - create snapshot that contains this artifact
// {
// name: "report approval with an environment name and no oldest-commit and no newest-commit works",
// cmd: `report approval --fingerprint ` + suite.artifactFingerprint + ` --flow ` + suite.flowName + ` --repo-root ../.. ` +
// ` --environment ` + suite.envName + suite.defaultKosliArguments,
// golden: fmt.Sprintf("approval created for artifact: %s\n", suite.artifactFingerprint),
// },

// Here is a case we need to investigate how to test:
// - Create approval with '--newest-commit HEAD~5', '--oldest-commit HEAD~7' and '--environment staging',
// then create approval only with '--environment staging',
Expand Down
21 changes: 21 additions & 0 deletions cmd/kosli/testHelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,27 @@ func CreateArtifact(flowName, artifactFingerprint, artifactName string, t *testi
require.NoError(t, err, "artifact should be created without error")
}

func CreateArtifactWithCommit(flowName, artifactFingerprint, artifactName string, gitCommit string, t *testing.T) {
t.Helper()
o := &reportArtifactOptions{
srcRepoRoot: "../..",
flowName: flowName,
//name: "",
gitReference: gitCommit,
payload: ArtifactPayload{
Fingerprint: artifactFingerprint,
GitCommit: gitCommit,
BuildUrl: "www.yr.no",
CommitUrl: "www.nrk.no",
},
}

o.fingerprintOptions = new(fingerprintOptions)

err := o.run([]string{artifactName})
require.NoError(t, err, "artifact should be created without error")
}

// CreateApproval creates an approval for an artifact in a flow
func CreateApproval(flowName, fingerprint string, t *testing.T) {
t.Helper()
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:
server-index:
networks: [ cli_net ]
depends_on: [ mongo_rs_initiate, minio ]
image: 772819027869.dkr.ecr.eu-central-1.amazonaws.com/merkely:0d3e1c6
image: 772819027869.dkr.ecr.eu-central-1.amazonaws.com/merkely:c8efd7a
command: /app/src/documentdb/wait_till_ready_or_raise.py
container_name: cli_kosli_server-index
read_only: true
Expand All @@ -32,7 +32,7 @@ services:
condition: service_started
server-index:
condition: service_completed_successfully
image: 772819027869.dkr.ecr.eu-central-1.amazonaws.com/merkely:0d3e1c6
image: 772819027869.dkr.ecr.eu-central-1.amazonaws.com/merkely:c8efd7a
env_file: [ "./mongo/mongo.env" ]
environment:
KOSLI_HOSTNAME: localhost
Expand Down

0 comments on commit 388783b

Please sign in to comment.