Skip to content
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

Run integration test with GCS mock #55

Merged
merged 27 commits into from
Dec 11, 2024
Merged

Run integration test with GCS mock #55

merged 27 commits into from
Dec 11, 2024

Conversation

mariiatuzovska
Copy link
Contributor

@mariiatuzovska mariiatuzovska commented Dec 9, 2024

This PR introduces integration tests to ensure the proper functioning of key components with fake-gcs-server as a dependency.
These tests provide a more comprehensive validation by simulating interactions with a Google Cloud Storage-like environment.

Key Changes:

  • Added integration tests that rely on fake-gcs-server.
  • Updated documentation with instructions on running the tests locally using Docker.
  • Modify CI job for integration tests.

@mariiatuzovska mariiatuzovska changed the title WIP: Run integration test with GCS mock Run integration test with GCS mock Dec 10, 2024
README.md Outdated
Use the following command to run the integration tests:

bash```
STORAGE_EMULATOR_HOST=http://0.0.0.0:4443 go test ./pkg/cmd/cli/... -run="TestCmd"
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically all our tests are more or less a form of it-test, so I'll remove this part in the command: 'run="TestCmd"'

Comment on lines 51 to 61
// test parameters for each test
cleanroomName string
expireTime time.Time
emailsSource []string
tmpDir string
salt string
publisherPairKey *pair.PrivateKey
advertiserInputFilePath string
advertiserKeyConfigFilePath string
publisherPAIRIDsFolderPath string
advertiserOutputFolderPath string
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these be part of a different struct? to me these do not belong to the "test-suite" struct

// STORAGE_EMULATOR_HOST is required to run this test
bucketURL := os.Getenv("STORAGE_EMULATOR_HOST")
if bucketURL == "" {
t.Skip("STORAGE_EMULATOR_HOST is required to run this test")
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of skipping, this test should fail IMO

Comment on lines 141 to 146
shaEncoder := sha256.New()
for i := range genEmailsSourceNumber {
shaEncoder.Write([]byte(fmt.Sprintf("%d@gmail.com", i)))
hem := shaEncoder.Sum(nil)
s.emailsSource[i] = fmt.Sprintf("%x", hem)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't you already have a helper function to generate emails?

Copy link
Contributor Author

@mariiatuzovska mariiatuzovska Dec 10, 2024

Choose a reason for hiding this comment

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

yes, I have one in pair package. I cannot import it from _test.go file.

}
}

func (s *cmdTestSuite) requireGenPublisherTripleEncryptedData() {
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 have this? publisher-triple-encrypted data is generated by the CLI, so you should not be creating it yourself. You probably need requireGenAdvertiserTripleEncryptedData (which is created by the publisher)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

naming mistake

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it actually writes into advertiser triple encrypted folder

s.requireGenPublisherTripleEncryptedData()
}

nextPuplisherState = v1.Cleanroom_Participant_SUCCEEDED
Copy link
Contributor

Choose a reason for hiding this comment

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

In the cleanroom service side, this will only happen if the CLI has pushed triple-encrypted-publisher data and called the advance-state the second time

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, it is called two times. I change variables "nextPuplisherState" and "nextAdvertiserState".


if cleanroom.Participants[0].State == v1.Cleanroom_Participant_DATA_TRANSFORMED {
// add publisher triple encrypted data on this step
s.requireGenPublisherTripleEncryptedData()
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not understanding this, why do we do it here? or the function name should requireGenAdvertiserTripleEncryptedData?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@amanjpro
Copy link
Contributor

Oh, you will also need to pass the two options:

--output=...
----save-publisher-encrypted-data-locally=...

So it does check the actual match, and uses the locally stored publisher data. THat will make the coverage data almost 100%

@mariiatuzovska
Copy link
Contributor Author

mariiatuzovska commented Dec 10, 2024

Oh, you will also need to pass the two options:

--output=... ----save-publisher-encrypted-data-locally=...

So it does check the actual match, and uses the locally stored publisher data. THat will make the coverage data almost 100%

It is already done and checked here: https://github.com/Optable/optable-pair-cli/pull/55/files#diff-68235dad6501edbd1da912df01435e618628c88dfdf962f4d4facb483fc8c093R325-R326

README.md Outdated
Use the following command to run the integration tests:

bash```
STORAGE_EMULATOR_HOST=http://0.0.0.0:4443 go test ./...
Copy link
Contributor

Choose a reason for hiding this comment

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

make test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@amanjpro suggested to add

Copy link
Contributor

Choose a reason for hiding this comment

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

I think what he says is in the README, we no longer this detail, because we already have the Make target, and I agree

We probably just need to tell you cannot run the tests under a windows machine

@@ -56,6 +57,8 @@ type (
Option func(*bucketOptions)
)

var HTTPClient = &http.Client{}
Copy link
Contributor

Choose a reason for hiding this comment

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

don't set global variable, pass it instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the other way is to pass it in the cli context, what do you suggest?

Copy link
Contributor

Choose a reason for hiding this comment

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

or as an optional value, and the constructor can check if it is nil or not, and sets it accordingly?


func (s *cmdTestSuite) requireGenAdvertiserTripleEncryptedData() {
s.T().Helper()
ctx := context.Background()
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

s.Require().NoError(err, "must close GCS writer")
}()
tripleEncryptedCsvWriter := csv.NewWriter(tripleEncryptedWriter)
defer tripleEncryptedCsvWriter.Flush()
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to defer this, and you call writer.Error() to check write errors.

Flush writes any buffered data to the underlying io.Writer. To check if an error occurred during Flush, call Writer.Error.


func (s *cmdTestSuite) requireLocalContentEqualToGCSContent(localFolder, gcsFolder string) {
s.T().Helper()
ctx := context.Background()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ctx := context.Background()

}()

w := csv.NewWriter(tmpInputFile)
defer w.Flush()
Copy link
Contributor

Choose a reason for hiding this comment

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

check w.Error()

@mariiatuzovska mariiatuzovska merged commit 45fd713 into main Dec 11, 2024
3 checks passed
@mariiatuzovska mariiatuzovska deleted the mock-gcs branch December 11, 2024 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants