Skip to content

Commit 82d8d66

Browse files
committed
👻 New binding tests. (#997)
Created new test/binding tests using cleaner approach. Uses: - gomega - t.Cleanup() - cmp.Eq() Eliminates samples. I'm not convinced the variation in samples was extensive enough to warrant the added complexity. Further, I doubt the samples are that usable by other projects. The approach here is to round-trip the most complete version of each resource. Adds a number of missing bindings. Adds a number of missing tests. Adds sorting to the test/cmp. Adds internal/k8s/seed (configMap). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Expanded binding APIs: analysis, reports, imports, archetype assessments, configmap access, file listing, task/taskgroup enhancements, task attachments, bulk app deletion, and stakeholder updates. * **Bug Fixes** * Manifest queries now eagerly load associations; application fact deletion scope tightened. * **Tests** * Large set of new integration and unit tests covering binding APIs and resources. * **Documentation** * Added binding and binding-test guidelines (CLAUDE.md). * **Refactor** * TaskPolicy schema simplified (preempt fields removed). <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Jeff Ortel <jortel@redhat.com>
1 parent 38ccd89 commit 82d8d66

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+10359
-124
lines changed

.github/workflows/main.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,25 @@ jobs:
4545
go-version: '1.21'
4646
- run: make test
4747

48+
test-binding:
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v4
52+
with:
53+
repository: konveyor/tackle2-seed
54+
- run: |
55+
mkdir -p /tmp/seed
56+
cp -r resources/* /tmp/seed
57+
- uses: actions/checkout@v4
58+
- uses: actions/setup-go@v3
59+
with:
60+
go-version: '1.21'
61+
- run: |
62+
make vet
63+
DISCONNECTED=1 make run &
64+
sleep 15 # probably a dirty solution
65+
HUB_BASE_URL=http://localhost:8080 make test-binding
66+
4867
test-api:
4968
needs:
5069
- fmt

.github/workflows/test-nightly.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,25 @@ jobs:
1414
go-version: '1.21'
1515
- run: make test
1616

17+
test-binding:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
with:
22+
repository: konveyor/tackle2-seed
23+
- run: |
24+
mkdir -p /tmp/seed
25+
cp -r resources/* /tmp/seed
26+
- uses: actions/checkout@v4
27+
- uses: actions/setup-go@v3
28+
with:
29+
go-version: '1.21'
30+
- run: |
31+
make vet
32+
DISCONNECTED=1 make run &
33+
sleep 15 # probably a dirty solution
34+
HUB_BASE_URL=http://localhost:8080 make test-binding
35+
1736
test-api:
1837
runs-on: ubuntu-latest
1938
steps:
@@ -26,4 +45,3 @@ jobs:
2645
DISCONNECTED=1 make run &
2746
sleep 15 # probably a dirty solution
2847
HUB_BASE_URL=http://localhost:8080 make test-api
29-
HUB_BASE_URL=http://localhost:8080 make test-api # Intentionaly run 2x to catch data left in Hub DB.

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ test-api:
135135
for pkg in $$(go list ./test/api/...); do \
136136
HUB_BASE_URL="$(HUB_BASE_URL)" go test -count=1 -v -failfast "$$pkg" || exit 1; \
137137
done
138+
test-binding:
139+
for pkg in $$(go list ./test/binding/...); do \
140+
HUB_BASE_URL="$(HUB_BASE_URL)" go test -count=1 -v -failfast "$$pkg" || exit 1; \
141+
done
138142

139143
# Run Hub test suite.
140144
test-all: test-unit test-api

docs/docs.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8549,12 +8549,6 @@ const docTemplate = `{
85498549
"isolated": {
85508550
"type": "boolean"
85518551
},
8552-
"preemptEnabled": {
8553-
"type": "boolean"
8554-
},
8555-
"preemptExempt": {
8556-
"type": "boolean"
8557-
}
85588552
}
85598553
},
85608554
"github_com_konveyor_tackle2-hub_api.TaskQueue": {

hack/cmd/addon/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
hub "github.com/konveyor/tackle2-hub/shared/addon"
2020
"github.com/konveyor/tackle2-hub/shared/api"
21+
bucketapi "github.com/konveyor/tackle2-hub/shared/binding/bucket"
2122
"github.com/konveyor/tackle2-hub/shared/nas"
2223
"k8s.io/apimachinery/pkg/util/rand"
2324
)
@@ -154,7 +155,7 @@ func listDir(d *Data, application *api.Application, paths []string) (err error)
154155
//
155156
// Upload list directory.
156157
addon.Activity("[BUCKET] uploading %s => bucket/%s.", output, BucketDir)
157-
bucket := addon.Application.Bucket(application.ID)
158+
bucket := addon.Application.Select(application.ID).Bucket
158159
err = bucket.Put(output, BucketDir)
159160
if err != nil {
160161
return
@@ -178,7 +179,7 @@ func listDir(d *Data, application *api.Application, paths []string) (err error)
178179
}
179180

180181
// playWithBucket
181-
func playWithBucket(bucket hub.BucketContent) (err error) {
182+
func playWithBucket(bucket bucketapi.Content) (err error) {
182183
tmpDir := tmpDir()
183184
defer func() {
184185
_ = nas.RmDir(tmpDir)

internal/api/application.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,8 +1061,7 @@ func (h ApplicationHandler) FactReplace(ctx *gin.Context, key FactKey) {
10611061
_ = ctx.Error(err)
10621062
return
10631063
}
1064-
1065-
// remove all the existing Facts for that source and app id.
1064+
// Delete all the existing facts with that source and application id.
10661065
db := h.DB(ctx)
10671066
db = db.Where("ApplicationID", id)
10681067
db = db.Where("Source", key.Source())
@@ -1071,16 +1070,14 @@ func (h ApplicationHandler) FactReplace(ctx *gin.Context, key FactKey) {
10711070
_ = ctx.Error(err)
10721071
return
10731072
}
1074-
1075-
// create new Facts
1073+
// Create new facts.
10761074
if len(facts) > 0 {
10771075
newFacts := []model.Fact{}
10781076
for k, v := range facts {
1079-
value, _ := json.Marshal(v)
10801077
newFacts = append(newFacts, model.Fact{
10811078
ApplicationID: id,
10821079
Key: FactKey(k).Name(),
1083-
Value: value,
1080+
Value: v,
10841081
Source: key.Source(),
10851082
})
10861083
}

internal/api/manifest.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/konveyor/tackle2-hub/internal/model"
1313
"github.com/konveyor/tackle2-hub/internal/secret"
1414
"github.com/konveyor/tackle2-hub/shared/api"
15+
"gorm.io/gorm/clause"
1516
)
1617

1718
const (
@@ -56,6 +57,7 @@ func (h ManifestHandler) Get(ctx *gin.Context) {
5657
id := h.pk(ctx)
5758
m := &model.Manifest{}
5859
db := h.DB(ctx)
60+
db = db.Preload(clause.Associations)
5961
err := db.First(m, id).Error
6062
if err != nil {
6163
_ = ctx.Error(err)
@@ -98,6 +100,7 @@ func (h ManifestHandler) List(ctx *gin.Context) {
98100
// Fetch.
99101
var list []model.Manifest
100102
db := h.DB(ctx)
103+
db = db.Preload(clause.Associations)
101104
db = filter.Where(db)
102105
err = db.Find(&list).Error
103106
if err != nil {

internal/api/resource/manifest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func (r *Manifest) With(m *model.Manifest) {
1313
baseWith(&r.Resource, &m.Model)
1414
r.Content = m.Content
1515
r.Secret = m.Secret
16-
r.Application = Ref{ID: m.ApplicationID, Name: ""}
16+
r.Application = Ref{ID: m.ApplicationID, Name: m.Application.Name}
1717
}
1818

1919
// Model builds a model.

0 commit comments

Comments
 (0)