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

Right approach to test system env variables #102

Open
l3r8yJ opened this issue May 9, 2024 · 3 comments
Open

Right approach to test system env variables #102

l3r8yJ opened this issue May 9, 2024 · 3 comments

Comments

@l3r8yJ
Copy link
Contributor

l3r8yJ commented May 9, 2024

@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

@h1alexbel
Copy link
Contributor

@l3r8yJ it should be INPUT_SKIP_AUTHORS for skip_authors in action.yml

@l3r8yJ
Copy link
Contributor Author

l3r8yJ commented May 10, 2024

@h1alexbel yes, but how value will be presented? As far as I know, sys env contains just a string, but when we have something like

skip_authors:
  - l3r8yJ
  - h1alexbel

or

skip_authors: ["l3r8yJ", "h1alexbel"]

we will see something like INPUT_SKIP_AUTHORS=l3r8yJ,h1alexbel or what?

@h1alexbel
Copy link
Contributor

h1alexbel commented May 10, 2024

@l3r8yJ good question, I don't really test the first variant before, but for the second one, it should be like this:
INPUT_SKIP_AUTHORS='["l3r8yJ", "h1alexbel"]', so convert array into the string, skip_authors values should look like this:

skip_authors: '["l3r8yJ", "h1alexbel"]'

checkout this too: https://stackoverflow.com/a/54568163/19147117

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

No branches or pull requests

2 participants