Skip to content

Commit

Permalink
refactor #3
Browse files Browse the repository at this point in the history
  • Loading branch information
m00g3n committed Oct 17, 2019
1 parent 4184e16 commit 4e7430c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 42 deletions.
13 changes: 8 additions & 5 deletions tests/asset-store/testsuite/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func newAsset(dynamicCli dynamic.Interface, namespace string, bucketName string,
}
}

func (a *asset) CreateMany(assets []assetData, testId string, callbacks ...func(...interface{})) ([]string, error) {
var resourceVersions []string
func (a *asset) CreateMany(assets []assetData, testId string, callbacks ...func(...interface{})) (string, error) {
var initialResourceVersion string
for _, asset := range assets {
asset := &v1alpha2.Asset{
TypeMeta: metav1.TypeMeta{
Expand Down Expand Up @@ -67,14 +67,17 @@ func (a *asset) CreateMany(assets []assetData, testId string, callbacks ...func(
if err != nil {
return err
}
resourceVersions = append(resourceVersions, resourceVersion)
if initialResourceVersion != "" {
return nil
}
initialResourceVersion = resourceVersion
return nil
}, callbacks...)
if err != nil {
return nil, errors.Wrapf(err, "while creating Asset %s in namespace %s", asset.Name, a.Namespace)
return initialResourceVersion, errors.Wrapf(err, "while creating Asset %s in namespace %s", asset.Name, a.Namespace)
}
}
return resourceVersions, nil
return initialResourceVersion, nil
}

func (a *asset) WaitForStatusesReady(assets []assetData, resourceVersion string) error {
Expand Down
28 changes: 9 additions & 19 deletions tests/asset-store/testsuite/clusterasset.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (a *clusterAsset) CreateMany(assets []assetData, testId string, callbacks .
},
},
}
//FIXME Handle this
//FIXME Handle this | not
_, err := a.resCli.Create(asset, callbacks...)
if err != nil {
return errors.Wrapf(err, "while creating ClusterAsset %s", asset.Name)
Expand All @@ -67,26 +67,16 @@ func (a *clusterAsset) CreateMany(assets []assetData, testId string, callbacks .
return nil
}

func (a *clusterAsset) WaitForStatusesReady(assets []assetData) error {
//FIXME
err := waiter.WaitAtMost(func() (bool, error) {
for _, asset := range assets {
res, err := a.Get(asset.Name)
if err != nil {
return false, err
}

if res.Status.Phase != v1alpha2.AssetReady {
return false, nil
}
}

return true, nil
}, a.waitTimeout)
func (a *clusterAsset) WaitForStatusesReady(assets []assetData, initialResourceVersion string) error {
var assetNames []string
for _, asset := range assets {
assetNames = append(assetNames, asset.Name)
}
waitForStatusesReady := buildWaitForStatusesReady(a.resCli.ResCli, a.waitTimeout, assetNames...)
err := waitForStatusesReady(initialResourceVersion)
if err != nil {
return errors.Wrapf(err, "while waiting for ready ClusterAsset resources")
return errors.Wrapf(err, "while waiting for ready Asset resources")
}

return nil
}

Expand Down
28 changes: 10 additions & 18 deletions tests/asset-store/testsuite/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,17 @@ func (t *TestSuite) Run() {
err = t.clusterAsset.DeleteLeftovers(t.testId)
failOnError(t.g, err)

// FIXME break to 2 different methods due to resourceVersion
t.t.Log("Creating assets...")
var assetVersions []string
assetVersions, err = t.createAssets(uploadResult)
resourceVersion, err = t.createAssets(uploadResult)
failOnError(t.g, err)

t.t.Log("Waiting for assets to have ready phase...")
err = t.asset.WaitForStatusesReady(t.assetDetails, assetVersions[0])
err = t.asset.WaitForStatusesReady(t.assetDetails, resourceVersion)
failOnError(t.g, err)

t.t.Log("Waiting for cluster assets to have ready phase...")
err = t.clusterAsset.WaitForStatusesReady(t.assetDetails)
err = t.clusterAsset.WaitForStatusesReady(t.assetDetails, resourceVersion)
failOnError(t.g, err)

files, err := t.populateUploadedFiles()
Expand Down Expand Up @@ -172,7 +172,7 @@ func (t *TestSuite) Cleanup() {
err := t.clusterBucket.Delete()
failOnError(t.g, err)

err = t.deleteBuckets()
err = t.bucket.Delete()
failOnError(t.g, err)

err = t.namespace.Delete()
Expand All @@ -195,20 +195,20 @@ func (t *TestSuite) uploadTestFiles() (*upload.Response, error) {
return uploadResult, nil
}

func (t *TestSuite) createAssets(uploadResult *upload.Response) ([]string, error) {
func (t *TestSuite) createAssets(uploadResult *upload.Response) (string, error) {
t.assetDetails = convertToAssetResourceDetails(uploadResult, t.cfg.CommonAssetPrefix)

resourceVersions, err := t.asset.CreateMany(t.assetDetails, t.testId, t.t.Log)
assetVersion, err := t.asset.CreateMany(t.assetDetails, t.testId, t.t.Log)
if err != nil {
return nil, err
return assetVersion, err
}

err = t.clusterAsset.CreateMany(t.assetDetails, t.testId, t.t.Log)
if err != nil {
return nil, err
return assetVersion, err
}

return resourceVersions, nil
return assetVersion, nil
}

func (t *TestSuite) populateUploadedFiles() ([]uploadedFile, error) {
Expand Down Expand Up @@ -250,14 +250,6 @@ func (t *TestSuite) verifyDeletedFiles(files []uploadedFile) error {
return nil
}

func (t *TestSuite) deleteBuckets() error {
err := t.bucket.Delete()
if err != nil {
return err
}
return nil
}

func failOnError(g *gomega.GomegaWithT, err error) {
g.Expect(err).NotTo(gomega.HaveOccurred())
}
Expand Down

0 comments on commit 4e7430c

Please sign in to comment.