forked from apache/incubator-kie-kogito-serverless-operator
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…pache#564) * Fix apache#560 - Check if the .spec.flow has changed before building Signed-off-by: Ricardo Zanini <[email protected]> * Use CRC32 instead of comparing flows directly Signed-off-by: Ricardo Zanini <[email protected]> --------- Signed-off-by: Ricardo Zanini <[email protected]> (cherry picked from commit c429953)
- Loading branch information
1 parent
ffa0ae4
commit 4f02c95
Showing
12 changed files
with
132 additions
and
37 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
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
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
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
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
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
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
54 changes: 54 additions & 0 deletions
54
internal/controller/profiles/preview/states_preview_test.go
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,54 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package preview | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/apache/incubator-kie-kogito-serverless-operator/utils" | ||
|
||
"github.com/apache/incubator-kie-kogito-serverless-operator/internal/controller/profiles/common" | ||
"github.com/apache/incubator-kie-kogito-serverless-operator/test" | ||
"github.com/serverlessworkflow/sdk-go/v2/model" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_deployWithBuildWorkflowState_isWorkflowChanged(t *testing.T) { | ||
workflow1 := test.GetBaseSonataFlow(t.Name()) | ||
workflow2 := test.GetBaseSonataFlow(t.Name()) | ||
workflow1.Status.FlowCRC, _ = utils.Crc32Checksum(workflow1.Spec.Flow) | ||
workflow2.Status.FlowCRC, _ = utils.Crc32Checksum(workflow2.Spec.Flow) | ||
deployWithBuildWorkflowState := &deployWithBuildWorkflowState{ | ||
StateSupport: &common.StateSupport{C: test.NewSonataFlowClientBuilder().WithRuntimeObjects(workflow1).Build()}, | ||
} | ||
|
||
hasChanged, err := deployWithBuildWorkflowState.isWorkflowChanged(workflow2) | ||
assert.NoError(t, err) | ||
assert.False(t, hasChanged) | ||
|
||
// change workflow2 | ||
workflow2.Spec.Flow.Metadata = model.Metadata{ | ||
"string": model.Object{ | ||
StringValue: "test", | ||
}, | ||
} | ||
|
||
hasChanged, err = deployWithBuildWorkflowState.isWorkflowChanged(workflow2) | ||
assert.NoError(t, err) | ||
assert.True(t, hasChanged) | ||
} |
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
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
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,33 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package utils | ||
|
||
import ( | ||
"bytes" | ||
"encoding/gob" | ||
"hash/crc32" | ||
) | ||
|
||
func Crc32Checksum(v interface{}) (uint32, error) { | ||
var buf bytes.Buffer | ||
enc := gob.NewEncoder(&buf) | ||
if err := enc.Encode(v); err != nil { | ||
return 0, err | ||
} | ||
return crc32.ChecksumIEEE(buf.Bytes()), nil | ||
} |
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