Skip to content

Right approach to test system env variables #102

@l3r8yJ

Description

@l3r8yJ

@h1alexbel take a look, please

I have a class

public final class SkipAuthors implements Scalar<Collection<String>> {

    public SkipAuthors() {
        this(
            new ListOf<>(
                System.getenv().get("SKIP_AUTHORS").split(",")
            )
        );
    }

    @Override
    public Collection<String> value() {
        return Collections.unmodifiableCollection(this.authors);
    }
}

which is taking values of SKIP_AUTHORS sys env, what is the right way to test this? For now test looks like:

final class SkipAuthorsTest {

    @Test
    void worksAsImmutable() throws Exception {
        final Scalar<Collection<String>> authors = new SkipAuthors("ruby", "jeff");
        final Collection<String> expected = new ListOf<>("ruby", "jeff");
        MatcherAssert.assertThat(
            "%s should be equal to %s".formatted(authors.value(), expected),
            expected,
            Matchers.everyItem(
                Matchers.in(authors.value())
            )
        );
    }
}

btw, might be you know how array variables from action.yaml maps to system environment variables

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions