Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

feat: read clusters from database #56

Merged

Conversation

xcoulon
Copy link
Contributor

@xcoulon xcoulon commented Jan 4, 2019

also:

  • update to latest fabric8-common to remove an annoying error
    message after each test
  • run integration tests on a single processor to avoid concurrent
    writes in the database, which result in assertion errors

Fixes #54

Signed-off-by: Xavier Coulon xcoulon@redhat.com

also:
	- update to latest `fabric8-common` to remove an annoying error
    message after each test
  - run integration tests on a single processor to avoid concurrent
    writes in the database, which result in assertion errors

Fixes fabric8-services#54

Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
@codecov
Copy link

codecov bot commented Jan 4, 2019

Codecov Report

Merging #56 into master will decrease coverage by 0.03%.
The diff coverage is 92.72%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #56      +/-   ##
==========================================
- Coverage   78.57%   78.53%   -0.04%     
==========================================
  Files          15       15              
  Lines        1111     1123      +12     
==========================================
+ Hits          873      882       +9     
- Misses        190      192       +2     
- Partials       48       49       +1
Impacted Files Coverage Δ
cluster/repository/identity_cluster.go 83.92% <ø> (ø) ⬆️
controller/user.go 76.92% <100%> (ø) ⬆️
cluster/repository/cluster_repository.go 70.09% <100%> (+0.28%) ⬆️
cluster/service/cluster_service.go 80.58% <100%> (+0.77%) ⬆️
controller/clusters.go 92.89% <90%> (-2.14%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6a19264...fa40eab. Read the comment docs.

Copy link
Contributor

@alexeykazakov alexeykazakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. But please take a look at the comments below.

.make/test.mk Outdated
@@ -147,6 +147,7 @@ test-unit-with-coverage: prebuild-check clean-coverage-unit $(COV_PATH_UNIT)
test-unit: prebuild-check $(SOURCES)
$(call log-info,"Running test: $@")
$(eval TEST_PACKAGES:=$(shell go list ./... | grep -v $(ALL_PKGS_EXCLUDE_PATTERN)))
go clean -cache
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you want to clean cache? Adding -p 1 flag slows down tests. So, cache is actually quite useful when running tests locally. You can always clean cache manually between test runs if you want.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, let me remove that. I just wanted to make sure that there was no cache when running the integration tests to reproduce the "parallel run" failures, but I can surely remove that one now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in dc31c0f

@@ -236,3 +238,9 @@ func (m *GormClusterRepository) Query(funcs ...func(*gorm.DB) *gorm.DB) ([]Clust

return objs, nil
}

// List list ALL clusters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// List lists ALL clusters

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in dc31c0f


func (s *clusterTestSuite) TestList() {
// given
cluster1 := &repository.Cluster{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in dc31c0f

// then
require.NoError(s.T(), err)
require.Len(s.T(), clusters, 2)
test.AssertEqualClusters(s.T(), cluster1, &clusters[0])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not order clusters when query them in DB, so, theoretically they can be in a different order. Worth adding test.AssertClusters(t, expected, actual []Cluster) or test.AssertClusters(t, actual []Cluster, expected ...Cluster) since it can be useful in other tests too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, let me fix that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in dc31c0f

}

go func() {
fmt.Println("config watcher started")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove Println

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in d78a591

}

go func() {
fmt.Println("config watcher started")
defer func() {
fmt.Println("config watcher stopped")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove println

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in d78a591

@@ -217,13 +217,20 @@ func ValidateURL(urlStr *string) error {

// InitializeClusterWatcher initializes a file watcher for the cluster config file
// When the file is updated the configuration synchronously reload the cluster configuration
func (c clusterService) InitializeClusterWatcher() (func() error, error) {
func (c clusterService) InitializeClusterWatcher() (func() error, chan bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really still need that done channel in the tests after fixing the parallel test execution?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, it's not needed anymore, so I reverted that part.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in d78a591

require.NotNil(t, clusters)
require.NotNil(t, clusters.Data)
require.Len(t, clusters.Data, len(s.Configuration.GetClusters()))
for _, cluster := range clusters.Data {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add at least on cluster to the DB manually and make sure it's among the result. Not only the clusters loaded from Configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, let me add that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in dc31c0f

require.NotNil(t, clusters)
require.NotNil(t, clusters.Data)
require.Equal(t, len(s.Configuration.GetClusters()), len(clusters.Data))
for _, cluster := range clusters.Data {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in dc31c0f

test/cluster.go Outdated
Name: uuid.NewV4().String(),
SAToken: uuid.NewV4().String(),
SAUsername: uuid.NewV4().String(),
ClusterID: random,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guys, you keep "optimizing" this code by using the same string for fields which are supposed to be unique :) The whole point here that these fields have different value. Not the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get your point, I just wanted to have a same UUID for all fields so I could much easily locate the cluster ID in the logs. Let me revert that now that I don't need it anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in ae521c6

@xcoulon
Copy link
Contributor Author

xcoulon commented Jan 7, 2019

thanks for the review @alexeykazakov and let me address all your comments

Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
@xcoulon
Copy link
Contributor Author

xcoulon commented Jan 7, 2019

@alexeykazakov I addressed all your comments. Please let me know if you have further concerns ;)

Copy link
Contributor

@dipak-pawar dipak-pawar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great Job @xcoulon. LGTM

if err != nil {
return err
}
}
log.Warn(ctx, map[string]interface{}{}, "done creating/updating clusters from config file")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about creating/updating clusters from config file has been completed/done?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change the message if you prefer that wording

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in e99d1ef

Copy link
Contributor

@alexeykazakov alexeykazakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just the last comment regarding the trailing slashes.

// AssertEqualClusterData verifies that data for actual cluster match the expected one
func AssertEqualClusterData(t *testing.T, expected *repository.Cluster, actual *app.ClusterData) {
assert.Equal(t, expected.Name, actual.Name)
assert.Equal(t, httpsupport.AddTrailingSlashToURL(expected.URL), actual.APIURL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be safer to check URLs as is instead of adding trailing slashes to expected URLs?
We should be really careful with these trailing slashes. It's easy to miss it.

Copy link
Contributor Author

@xcoulon xcoulon Jan 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 238c902 with a Normalize function outside of the AssertEqualCluster funcs

also, include `SaTokenEncrypted` in response
also, refactor custom assertions to simplify
code in tests

Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
@xcoulon
Copy link
Contributor Author

xcoulon commented Jan 8, 2019

@dipak-pawar @alexeykazakov please let me know if you have further concerns about this PR ;)

test/cluster.go Outdated
type NormalizeCluster func(repository.Cluster) repository.Cluster

// AddTrailingSlashes a normalize function which converts all URL by adding a trailing
// slash if neede
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in fa40eab

}

// AssertEqualClusterDetails verifies that the `actual` and `expected` clusters are have the same values
// including sensitive details if `expectSensitiveInfo` is `true`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mentioned expectSensitiveInfo param in a few places but it looks like it's not defined/actually used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, that's the result of a copy/paste from an upcoming PR that actually introduces this arg, but it's not needed here, so I'll remove it from the comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in fa40eab

Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
@xcoulon xcoulon merged commit 7b582d0 into fabric8-services:master Jan 9, 2019
@xcoulon xcoulon deleted the Issue54_list_cluster_from_repository branch January 9, 2019 08:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants