diff --git a/cmd/kosli/reportApproval.go b/cmd/kosli/reportApproval.go index 5d002db11..d6f77df12 100644 --- a/cmd/kosli/reportApproval.go +++ b/cmd/kosli/reportApproval.go @@ -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{ diff --git a/cmd/kosli/reportApproval_test.go b/cmd/kosli/reportApproval_test.go index 5b33d1d4b..d0c0e8a95 100644 --- a/cmd/kosli/reportApproval_test.go +++ b/cmd/kosli/reportApproval_test.go @@ -13,6 +13,7 @@ type ApprovalReportTestSuite struct { artifactFingerprint string flowName string envName string + gitCommit string } func (suite *ApprovalReportTestSuite) SetupTest() { @@ -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() { @@ -46,12 +49,6 @@ 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", @@ -59,6 +56,18 @@ func (suite *ApprovalReportTestSuite) TestApprovalReportCmd() { 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', diff --git a/cmd/kosli/testHelpers.go b/cmd/kosli/testHelpers.go index fbecb6b34..c7d36d398 100644 --- a/cmd/kosli/testHelpers.go +++ b/cmd/kosli/testHelpers.go @@ -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() diff --git a/docker-compose.yml b/docker-compose.yml index 42e183426..76619b539 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 @@ -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