-
-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor 2 #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Refactor 2 #15
Changes from all commits
2f529e7
7d1c7d3
71dba48
fb24084
ca334cb
04bd021
91ec287
53d46fd
c2700a5
07b9798
16d707b
e0d75c2
8368574
ca2703d
deb8365
4392d58
f6016ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,13 @@ | ||||||||||||||||||
coverage: | ||||||||||||||||||
precision: 2 | ||||||||||||||||||
round: nearest | ||||||||||||||||||
range: "70...100" | ||||||||||||||||||
status: | ||||||||||||||||||
project: | ||||||||||||||||||
default: | ||||||||||||||||||
target: auto | ||||||||||||||||||
threshold: 15% | ||||||||||||||||||
patch: | ||||||||||||||||||
default: | ||||||||||||||||||
target: 30% | ||||||||||||||||||
threshold: 30% | ||||||||||||||||||
Comment on lines
+10
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quote patch-level --- a/.github/codecov.yml
+++ b/.github/codecov.yml
@@ -12,7 +12,7 @@ status:
default:
target: 30%
- threshold: 30%
+ threshold: "30%" 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,6 @@ on: | |
tags: | ||
- v* | ||
pull_request: | ||
pull_request_target: | ||
types: [opened, edited] | ||
|
||
env: | ||
GO_VERSION: "~1.20" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package app_test | ||
|
||
import ( | ||
"runtime" | ||
"testing" | ||
|
||
"github.com/stackup-app/stackup/lib/app" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
type MockJsEngine struct { | ||
MockEvaluate func(script string) interface{} | ||
mock.Mock | ||
} | ||
|
||
func (m *MockJsEngine) Evaluate(script string) interface{} { | ||
return m.MockEvaluate(script) | ||
} | ||
Comment on lines
+12
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Fix MockJsEngine implementation inconsistency. The MockJsEngine struct embeds Choose one of these approaches: Option 1: Use testify mock framework properly: type MockJsEngine struct {
- MockEvaluate func(script string) interface{}
mock.Mock
}
func (m *MockJsEngine) Evaluate(script string) interface{} {
- return m.MockEvaluate(script)
+ args := m.Called(script)
+ return args.Get(0)
} Option 2: Use simple function field approach: type MockJsEngine struct {
MockEvaluate func(script string) interface{}
- mock.Mock
} 🤖 Prompt for AI Agents
|
||
|
||
func TestGetDisplayName(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
// Test case: When Include field has a value with "https://" | ||
task1 := app.Task{ | ||
Include: "https://example.com", | ||
Name: "TestName", | ||
Id: "TestId", | ||
Uuid: "TestUuid", | ||
} | ||
assert.Equal("example.com", task1.GetDisplayName()) | ||
|
||
// Test case: When Include field has a value without "https://" | ||
task2 := app.Task{ | ||
Include: "example.com", | ||
Name: "TestName", | ||
Id: "TestId", | ||
Uuid: "TestUuid", | ||
} | ||
assert.Equal("example.com", task2.GetDisplayName()) | ||
|
||
// Test case: When Name field has a value | ||
task3 := app.Task{ | ||
Name: "TestName", | ||
Id: "TestId", | ||
Uuid: "TestUuid", | ||
} | ||
assert.Equal("TestName", task3.GetDisplayName()) | ||
|
||
// Test case: When Id field has a value | ||
task4 := app.Task{ | ||
Id: "TestId", | ||
Uuid: "TestUuid", | ||
} | ||
assert.Equal("TestId", task4.GetDisplayName()) | ||
|
||
// Test case: When only Uuid field has a value | ||
task5 := app.Task{ | ||
Uuid: "TestUuid", | ||
} | ||
assert.Equal("TestUuid", task5.GetDisplayName()) | ||
|
||
// Test case: When no fields have values | ||
task6 := app.Task{} | ||
assert.Equal("", task6.GetDisplayName()) | ||
} | ||
|
||
func TestCanRunOnCurrentPlatform(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
// Test case: When Platforms is nil | ||
task1 := &app.Task{} | ||
assert.True(task1.CanRunOnCurrentPlatform()) | ||
|
||
// Test case: When Platforms is empty | ||
task2 := &app.Task{Platforms: []string{}} | ||
assert.True(task2.CanRunOnCurrentPlatform()) | ||
|
||
// Test case: When Platforms contains the current platform (case insensitive) | ||
task3 := &app.Task{Platforms: []string{runtime.GOOS}} | ||
assert.True(task3.CanRunOnCurrentPlatform()) | ||
|
||
// Test case: When Platforms does not contain the current platform | ||
task4 := &app.Task{Platforms: []string{"someotherplatform"}} | ||
assert.False(task4.CanRunOnCurrentPlatform()) | ||
} | ||
|
||
// func TestCanRunConditionally(t *testing.T) { | ||
// assert := assert.New(t) | ||
|
||
// // Test case: When If field is empty | ||
// task1 := &app.Task{If: ""} | ||
// assert.True(task1.CanRunConditionally()) | ||
|
||
// // Test case: When JsEngine.Evaluate returns true | ||
// getJsEngine := func(mockEval func(script string) interface{}) interface{} { | ||
// engine := &MockJsEngine{ | ||
// MockEvaluate: mockEval, | ||
// } | ||
|
||
// return engine | ||
// } | ||
|
||
// jsengine2 := getJsEngine(func(script string) interface{} { | ||
// return true | ||
// }) | ||
|
||
// task2 := &app.Task{ | ||
// If: "{{ some condition }}", | ||
// JsEngine: jsengine2.(*scripting.JavaScriptEngine), | ||
// } | ||
// assert.True(task2.CanRunConditionally()) | ||
|
||
// // Test case: When JsEngine.Evaluate returns false | ||
// jsengine3 := getJsEngine(func(script string) interface{} { | ||
// return false | ||
// }) | ||
// task3 := &app.Task{ | ||
// If: "some condition", | ||
// JsEngine: jsengine3.(*scripting.JavaScriptEngine), | ||
// } | ||
// assert.False(task3.CanRunConditionally()) | ||
// } | ||
Comment on lines
+88
to
+123
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix type casting issue in commented test. The commented test has a type casting issue on line 110 that would prevent compilation. The If you plan to uncomment this test, fix the type issue: -// task2 := &app.Task{
-// If: "{{ some condition }}",
-// JsEngine: jsengine2.(*scripting.JavaScriptEngine),
-// }
+// task2 := &app.Task{
+// If: "{{ some condition }}",
+// JsEngine: jsengine2.(*MockJsEngine),
+// } However, note that this would still not work since
🤖 Prompt for AI Agents
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package app_test | ||
|
||
import ( | ||
"sync" | ||
"testing" | ||
|
||
"github.com/stackup-app/stackup/lib/app" | ||
"github.com/stackup-app/stackup/lib/gateway" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCreateWorkflow(t *testing.T) { | ||
gw := &gateway.Gateway{} // Mock or initialize as needed | ||
processMap := &sync.Map{} | ||
workflow := app.CreateWorkflow(gw, processMap) | ||
|
||
assert.NotNil(t, workflow) | ||
assert.NotNil(t, workflow.Settings) | ||
assert.NotNil(t, workflow.Preconditions) | ||
assert.NotNil(t, workflow.Tasks) | ||
assert.NotNil(t, workflow.Includes) | ||
assert.NotNil(t, workflow.Gateway) | ||
assert.NotNil(t, workflow.ProcessMap) | ||
assert.NotNil(t, workflow.Integrations) | ||
} | ||
|
||
func TestAsContract(t *testing.T) { | ||
workflow := &app.StackupWorkflow{} | ||
contract := workflow.AsContract() | ||
|
||
assert.NotNil(t, contract) | ||
} | ||
|
||
func TestFindTaskById(t *testing.T) { | ||
workflow := &app.StackupWorkflow{ | ||
Tasks: []*app.Task{ | ||
{Id: "test1"}, | ||
{Id: "test2"}, | ||
}, | ||
} | ||
|
||
taskAny, found := workflow.FindTaskById("test1") | ||
var task *app.Task = taskAny.(*app.Task) | ||
|
||
assert.True(t, found) | ||
assert.Equal(t, "test1", task.Id) | ||
|
||
_, notFound := workflow.FindTaskById("test3") | ||
assert.False(t, notFound) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quote project-level
threshold
to avoid YAML parsing errorsUnquoted
15%
may not be parsed correctly by YAML. Wrap it in quotes to ensure it’s interpreted as a string.Apply this diff:
📝 Committable suggestion
🤖 Prompt for AI Agents