-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for RuntimeEnvironment new functions
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
be2-scala/src/test/scala/ch/epfl/pop/config/RuntimeEnvironmentSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package ch.epfl.pop.config | ||
|
||
import ch.epfl.pop.config.RuntimeEnvironment.{readClientEndpoints, readServerPeers} | ||
import org.scalatest.funsuite.{AnyFunSuiteLike => FunSuite} | ||
import org.scalatest.matchers.should.Matchers.{convertToAnyShouldWrapper, equal} | ||
|
||
import java.io.{BufferedWriter, FileWriter} | ||
import scala.io.Source.fromFile | ||
|
||
class RuntimeEnvironmentSuite extends FunSuite { | ||
|
||
test("readClientEndpoints() should only return the addresses that match the regex from the schema") { | ||
val path = "src/main/scala/ch/epfl/pop/config/client-endpoints-list.conf" | ||
// Save old file content | ||
val source = fromFile(path) | ||
val oldContent = source.mkString | ||
source.close() | ||
|
||
// Values to add in the file | ||
val address1 = "ws://127.0.0.1:7000/client" | ||
val address2 = "ws://127.0.0.1:8000/client" | ||
val address3 = "ws://127.0.0.1:9000/client" | ||
val invalidAddress = "http://127.0.0.1/" | ||
|
||
// Writing the values | ||
var file = new BufferedWriter(new FileWriter(path)) | ||
|
||
file.append(address1) | ||
file.newLine() | ||
file.append(address2) | ||
file.newLine() | ||
file.append(invalidAddress) | ||
file.newLine() | ||
file.append(address3) | ||
file.close() | ||
|
||
// Verify it works as expected | ||
readClientEndpoints() should equal(List(address1, address2, address3)) | ||
|
||
// Restore old content | ||
file = new BufferedWriter(new FileWriter(path)) | ||
file.write(oldContent) | ||
file.close() | ||
} | ||
|
||
// If this test doesn't pass it may be because the default config were not restored in the previous test | ||
test("Read of default client endpoint and server peers config should be empty") { | ||
readClientEndpoints().isEmpty should equal(true) | ||
readServerPeers().isEmpty should equal(true) | ||
} | ||
|
||
} |