Skip to content

Instantly share code, notes, and snippets.

@aufi
Created June 9, 2023 06:41
Show Gist options
  • Save aufi/48bcc126afee074c5bd48d13c0b7ae90 to your computer and use it in GitHub Desktop.
Save aufi/48bcc126afee074c5bd48d13c0b7ae90 to your computer and use it in GitHub Desktop.
func TestDependencyListAlternative1SharedDependenciesArray(t *testing.T) {
dependencies := []api.Dependency{}
// PREPARE TEST DATA (Must)
for _, sample := range Samples {
// Create applications.
assert.Must(t, Application.Create(&sample.ApplicationFrom))
assert.Must(t, Application.Create(&sample.ApplicationTo))
// Create dependencies.
dependency := api.Dependency{
From: api.Ref{
ID: sample.ApplicationFrom.ID,
},
To: api.Ref{
ID: sample.ApplicationTo.ID,
},
}
assert.Must(t, Dependency.Create(&dependency))
dependency.From.Name = sample.ApplicationFrom.Name // Marek, workaround until we implement Ref optional name aware Equal assertion
dependency.To.Name = sample.ApplicationTo.Name
dependencies = append(dependencies, dependency)
}
// THE ACTUAL TEST CODE - API list query and assertion (Should if needed)
// List dependencies.
got, err := Dependency.List()
if err != nil {
t.Errorf(err.Error())
}
if !assert.FlatEqual(got, dependencies) { // negative condition here needed
t.Errorf("Different response error. Got %v, expected %v", got, dependencies)
}
// CLEANUP TEST DATA - Delete Applications and Dependencies. (Must)
for _, dependency := range dependencies {
assert.Must(t, Application.Delete(dependency.From.ID))
assert.Must(t, Application.Delete(dependency.To.ID))
assert.Must(t, Dependency.Delete(dependency.ID))
}
}
go test -v -count=1 ./test/api/dependency/
time=2023-06-09T08:39:09+02:00 level=info msg=[binding] Hub RichClient created.
time=2023-06-09T08:39:09+02:00 level=info msg=[binding] |201| POST /auth/login
=== RUN TestDependencyCRUD
=== RUN TestDependencyCRUD/Dependency_from_Gateway_->_Inventory
time=2023-06-09T08:39:09+02:00 level=info msg=[binding] |201| POST /applications
time=2023-06-09T08:39:09+02:00 level=info msg=[binding] |201| POST /applications
time=2023-06-09T08:39:09+02:00 level=info msg=[binding] |201| POST /dependencies
time=2023-06-09T08:39:09+02:00 level=info msg=[binding] |200| GET /dependencies/1
time=2023-06-09T08:39:09+02:00 level=info msg=[binding] |204| DELETE /dependencies/1
time=2023-06-09T08:39:09+02:00 level=info msg=[binding] |404| GET /dependencies/1
time=2023-06-09T08:39:09+02:00 level=info msg=[binding] |204| DELETE /applications/1
time=2023-06-09T08:39:09+02:00 level=info msg=[binding] |204| DELETE /applications/2
--- PASS: TestDependencyCRUD (0.00s)
--- PASS: TestDependencyCRUD/Dependency_from_Gateway_->_Inventory (0.00s)
=== RUN TestDependencyListAlternative1SharedDependenciesArray
time=2023-06-09T08:39:09+02:00 level=info msg=[binding] |201| POST /applications
time=2023-06-09T08:39:09+02:00 level=info msg=[binding] |201| POST /applications
time=2023-06-09T08:39:09+02:00 level=info msg=[binding] |201| POST /dependencies
time=2023-06-09T08:39:09+02:00 level=info msg=[binding] |200| GET /dependencies
time=2023-06-09T08:39:09+02:00 level=info msg=[binding] |204| DELETE /applications/1
time=2023-06-09T08:39:09+02:00 level=info msg=[binding] |204| DELETE /applications/2
time=2023-06-09T08:39:09+02:00 level=info msg=[binding] |204| DELETE /dependencies/1
--- PASS: TestDependencyListAlternative1SharedDependenciesArray (0.00s)
PASS
ok github.com/konveyor/tackle2-hub/test/api/dependency 0.024s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment