Skip to content

Commit 84ed1ae

Browse files
committed
no unsafe
1 parent 1096bf5 commit 84ed1ae

File tree

1 file changed

+48
-44
lines changed

1 file changed

+48
-44
lines changed

json-log-viewer/shared/src/test/scala/ru/d10xa/jsonlogviewer/YamlCommandExecutionTest.scala

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import ru.d10xa.jsonlogviewer.decline.FieldNamesConfig
1111
import ru.d10xa.jsonlogviewer.decline.TimestampConfig
1212
import ru.d10xa.jsonlogviewer.shell.Shell
1313

14+
/** Tests to verify the proper command execution behavior based on YAML
15+
* configuration. Ensures that commands from YAML are executed when present and
16+
* stdin is used when no commands are available.
17+
*/
1418
class YamlCommandExecutionTest extends CatsEffectSuite {
1519

1620
private val basicConfig = Config(
@@ -32,7 +36,6 @@ class YamlCommandExecutionTest extends CatsEffectSuite {
3236
)
3337

3438
test("should use commands from YAML when inlineInput is absent") {
35-
// Arrange: Test implementations with unique output
3639
val testStdinStream = new StdInLinesStream {
3740
override def stdinLinesStream: Stream[IO, String] =
3841
Stream.emit("FROM_STDIN")
@@ -46,7 +49,6 @@ class YamlCommandExecutionTest extends CatsEffectSuite {
4649
Stream.emit(s"FROM_COMMAND:${commands.mkString(",")}")
4750
}
4851

49-
// YAML configuration with command but without inlineInput
5052
val configYaml = ConfigYaml(
5153
fieldNames = None,
5254
feeds = Some(
@@ -68,27 +70,28 @@ class YamlCommandExecutionTest extends CatsEffectSuite {
6870
showEmptyFields = None
6971
)
7072

71-
val yamlRef = Ref.unsafe[IO, Option[ConfigYaml]](Some(configYaml))
72-
73-
val result = LogViewerStream
74-
.stream(
75-
basicConfig,
76-
yamlRef,
77-
testStdinStream,
78-
testShell
79-
)
80-
.compile
81-
.toList
82-
.unsafeRunSync()
83-
84-
assert(
85-
result.exists(_.contains("FROM_COMMAND")),
86-
"Should use output from commands in YAML"
87-
)
88-
assert(
89-
!result.exists(_.contains("FROM_STDIN")),
90-
"Should not use stdin"
91-
)
73+
for {
74+
yamlRef <- Ref.of[IO, Option[ConfigYaml]](Some(configYaml))
75+
output <- LogViewerStream
76+
.stream(
77+
basicConfig,
78+
yamlRef,
79+
testStdinStream,
80+
testShell
81+
)
82+
.compile
83+
.toList
84+
_ <- IO {
85+
assert(
86+
output.exists(_.contains("FROM_COMMAND")),
87+
"Should use output from commands in YAML"
88+
)
89+
assert(
90+
!output.exists(_.contains("FROM_STDIN")),
91+
"Should not use stdin"
92+
)
93+
}
94+
} yield ()
9295
}
9396

9497
test("should use stdin when no commands or inlineInput are present") {
@@ -126,26 +129,27 @@ class YamlCommandExecutionTest extends CatsEffectSuite {
126129
showEmptyFields = None
127130
)
128131

129-
val yamlRef = Ref.unsafe[IO, Option[ConfigYaml]](Some(configYaml))
130-
131-
val result = LogViewerStream
132-
.stream(
133-
basicConfig,
134-
yamlRef,
135-
testStdinStream,
136-
testShell
137-
)
138-
.compile
139-
.toList
140-
.unsafeRunSync()
141-
142-
assert(
143-
result.exists(_.contains("FROM_STDIN")),
144-
"Should use stdin"
145-
)
146-
assert(
147-
!result.exists(_.contains("FROM_COMMAND")),
148-
"Should not use command output when no commands are present"
149-
)
132+
for {
133+
yamlRef <- Ref.of[IO, Option[ConfigYaml]](Some(configYaml))
134+
output <- LogViewerStream
135+
.stream(
136+
basicConfig,
137+
yamlRef,
138+
testStdinStream,
139+
testShell
140+
)
141+
.compile
142+
.toList
143+
_ <- IO {
144+
assert(
145+
output.exists(_.contains("FROM_STDIN")),
146+
"Should use stdin"
147+
)
148+
assert(
149+
!output.exists(_.contains("FROM_COMMAND")),
150+
"Should not use command output when no commands are present"
151+
)
152+
}
153+
} yield ()
150154
}
151155
}

0 commit comments

Comments
 (0)